EventDao extends BaseHibernateEntityDao<EventHibernateEntity> { @Override public void create(EventHibernateEntity event) { persist(event); } @Inject  EventDao(SessionFactory sessionFactory); @Override EventHibernateEntity findById(String id); @Override List<EventHibernateEntity> findAll(); @Override void create(EventHibernateEntity event);  }
@Test public void whenCreateItShouldCreateEvent() { EventHibernateEntity newEvent = buildUnsavedEvent(); daoTestRule.inTransaction(() -> { dao.create(newEvent); }); assertThat(newEvent.getId()) .isNotEmpty(); }
@Test public void whenCreateWithoutHandicapGroupSetItShouldThrow() { EventHibernateEntity entity = buildUnsavedEvent(); entity.setHandicapGroupSet(null); try { daoTestRule.inTransaction(() -> dao.create(entity)); failBecauseExceptionWasNotThrown(ConstraintViolationException.class); } catch (ConstraintViolationException e) { assertThat(e.getMessage()) .containsIgnoringCase("handicapGroupSet") .containsIgnoringCase("null"); } }
@Test public void whenCreateWithoutCompetitionGroupSetItShouldThrow() { EventHibernateEntity entity = buildUnsavedEvent(); entity.setCompetitionGroupSet(null); try { daoTestRule.inTransaction(() -> dao.create(entity)); failBecauseExceptionWasNotThrown(ConstraintViolationException.class); } catch (ConstraintViolationException e) { assertThat(e.getMessage()) .containsIgnoringCase("competitionGroupSet") .containsIgnoringCase("null"); } }