@Test @Transactional public void afterSavingACriterionItExists() { givenACriterionWithAnExistentType(); criterionDAO.save(criterion); assertTrue(criterionDAO.exists(criterion.getId())); }
@Test @Transactional public void afterRemovingTheCriterionNoLongerExists() throws InstanceNotFoundException { givenACriterionWithAnExistentType(); criterionDAO.save(criterion); criterionDAO.remove(criterion.getId()); assertFalse(criterionDAO.exists(criterion.getId())); }
@Test(expected = DataIntegrityViolationException.class) @Transactional public void schemaEnsuresCannotExistTwoDifferentCriterionsWithSameNameAndType() throws ValidationException { Criterion c = givenASavedCriterionWithAnExistentType(); Criterion repeated = anotherCriterionWithSameNameAndType(c); criterionDAO.save(repeated); criterionDAO.flush(); }
@Test @Transactional public void listReturnsTheNewlyCreatedCriterions() { int previous = criterionDAO.list(Criterion.class).size(); givenASavedCriterionWithAnExistentType(); givenASavedCriterionWithAnExistentType(); List<Criterion> list = criterionDAO.list(Criterion.class); assertEquals(previous + 2, list.size()); }
@Test @Transactional public void findByTypeOnlyReturnsTheCriterionsMatchedByType() { givenASavedCriterionWithAnExistentType(); // saving another givenASavedCriterionWithAnExistentType(); ICriterionType<Criterion> type = createTypeThatMatches(criterion); Collection<Criterion> criterions = criterionDAO.findByType(type); assertEquals(1, criterions.size()); assertTrue(criterions.contains(criterion)); }
@Test public void thereIsNoOtherIfItsTheSame() { Criterion c = transactionService.runOnTransaction( new IOnTransaction<Criterion>() { @Override public Criterion execute() { return givenASavedCriterionWithAnExistentType(); } }); assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(c)); }
@Test public void ifItsDifferentThereIsOther() { Criterion c = transactionService.runOnTransaction( new IOnTransaction<Criterion>() { @Override public Criterion execute() { return givenASavedCriterionWithAnExistentType(); } }); Criterion copy = Criterion.create(c.getName(), c.getType()); assertTrue(criterionDAO.thereIsOtherWithSameNameAndType(copy)); }
private void reattachCriterion(Criterion criterion) { criterionDAO.reattachUnmodifiedEntity(criterion); criterion.getName(); reattachCriterionType(criterion.getType()); }
private void initializeCriterion(Criterion criterion) { criterionDAO.reattach(criterion); Hibernate.initialize(criterion.getType()); }
@Test(expected = InvalidDataAccessApiUsageException.class) @Transactional public void aCriterionRelatedToATransientTypeCannotBeSaved() { givenACriterionWithATransientCriterionType(); criterionDAO.save(criterion); }
@Test @Transactional public void noOtherIfTheCriterionDoesntExist() { Criterion criterion = givenUniquelyNamedCriterion(); assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(criterion)); }
private Criterion givenASavedCriterionWithAnExistentType() { Criterion c = givenACriterionWithAnExistentType(); criterionDAO.save(c); return c; }