### Question:
EntityFinder { public <T, ID> T findById(CrudRepository<T, ID> repository, ID id, String notFoundMessage) { Optional<T> findResult = repository.findById(id); return getEntity(findResult, notFoundMessage); }  T findById(CrudRepository<T, ID> repository,
                              ID id,
                              String notFoundMessage); T findOne(QuerydslPredicateExecutor<T> predicateExecutor,
                         Predicate predicate,
                         String notFoundMessage);  }### Answer:
@Test public void findByIdShouldReturnResultWhenIsPresent() throws Exception { String processInstanceId = "5"; ProcessInstanceEntity processInstanceEntity = mock(ProcessInstanceEntity.class); given(repository.findById(processInstanceId)).willReturn(Optional.of(processInstanceEntity)); ProcessInstanceEntity retrieveProcessInstanceEntity = entityFinder.findById(repository, processInstanceId, "error"); assertThat(retrieveProcessInstanceEntity).isEqualTo(processInstanceEntity); }
@Test public void findByIdShouldThrowExceptionWhenNotPresent() throws Exception { String processInstanceId = "5"; given(repository.findById(processInstanceId)).willReturn(Optional.empty()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Error"); entityFinder.findById(repository, processInstanceId, "Error"); }