### Question:
EntityFinder { public <T> T findOne(QuerydslPredicateExecutor<T> predicateExecutor, Predicate predicate, String notFoundMessage) { Optional<T> findResult = predicateExecutor.findOne(predicate); 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 findOneShouldReturnResultWhenIsPresent() throws Exception { Predicate predicate = mock(Predicate.class); ProcessInstanceEntity processInstanceEntity = mock(ProcessInstanceEntity.class); given(repository.findOne(predicate)).willReturn(Optional.of(processInstanceEntity)); ProcessInstanceEntity retrievedProcessInstanceEntity = entityFinder.findOne(repository, predicate, "error"); assertThat(retrievedProcessInstanceEntity).isEqualTo(processInstanceEntity); }
@Test public void findOneShouldThrowExceptionWhenNotPresent() throws Exception { Predicate predicate = mock(Predicate.class); given(repository.findOne(predicate)).willReturn(Optional.empty()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Error"); entityFinder.findOne(repository, predicate, "Error"); }