@Test public void whenGetByIdWithNotExistingIdItShouldThrowEntityNotFoundExceptionWithDescriptiveMessage() { when(gateway.findById(TEST_ID)).thenReturn(null); try { TestEntity actual = service.getById(TEST_ID); failBecauseExceptionWasNotThrown(EntityNotFoundException.class); } catch (Exception e) { assertThat(e).isInstanceOf(EntityNotFoundException.class); assertThat(e) .hasMessageContaining(TestEntity.class.getSimpleName()) .hasMessageContaining("not found"); } }
public DE getById(String id) throws EntityNotFoundException { DE entity = gateway.findById(id); if (entity == null) { throw new EntityNotFoundException(domainEntityClass, id); } return entity; }
AbstractEntityService { public DE getById(String id) throws EntityNotFoundException { DE entity = gateway.findById(id); if (entity == null) { throw new EntityNotFoundException(domainEntityClass, id); } return entity; } }
AbstractEntityService { public DE getById(String id) throws EntityNotFoundException { DE entity = gateway.findById(id); if (entity == null) { throw new EntityNotFoundException(domainEntityClass, id); } return entity; } protected  AbstractEntityService(Class<DE> domainEntityClass, G gateway); }
AbstractEntityService { public DE getById(String id) throws EntityNotFoundException { DE entity = gateway.findById(id); if (entity == null) { throw new EntityNotFoundException(domainEntityClass, id); } return entity; } protected  AbstractEntityService(Class<DE> domainEntityClass, G gateway); DE add(AP addPayload); DE getById(String id); List<DE> getAll(); }
AbstractEntityService { public DE getById(String id) throws EntityNotFoundException { DE entity = gateway.findById(id); if (entity == null) { throw new EntityNotFoundException(domainEntityClass, id); } return entity; } protected  AbstractEntityService(Class<DE> domainEntityClass, G gateway); DE add(AP addPayload); DE getById(String id); List<DE> getAll();  }