ItEr35S07ValidacionEProbasFuncionaisItEr34S08: Recovering previously deleted test method can be saved twice along with fix due to checkConstraintUniqueCriterionTypeName

This commit is contained in:
Óscar González Fernández 2009-11-17 21:23:08 +01:00
parent 4a06cb14cc
commit d0d3130e1d
2 changed files with 15 additions and 4 deletions

View file

@ -71,7 +71,8 @@ public class CriterionTypeDAO extends GenericDAOHibernate<CriterionType, Long>
@Override
public boolean existsByName(CriterionType criterionType) {
try {
return findUniqueByName(criterionType) != null;
CriterionType t = findUniqueByName(criterionType);
return t != null && t != criterionType;
} catch (InstanceNotFoundException e) {
return false;
}

View file

@ -79,12 +79,21 @@ public class CriterionTypeDAOTest {
assertTrue(criterionTypeDAO.exists(criterionType.getId()));
}
@Test(expected=ValidationException.class)
@Test
public void testCriterionTypeCanBeSavedTwice() throws ValidationException {
CriterionType criterionType = createValidCriterionType();
criterionTypeDAO.save(criterionType);
criterionTypeDAO.save(criterionType);
assertTrue(criterionTypeDAO.exists(criterionType.getId())
|| criterionTypeDAO.existsByName(criterionType));
}
@Test(expected = ValidationException.class)
public void testCannotSaveTwoDifferentCriterionTypesWithTheSameName()
throws ValidationException {
CriterionType criterionType = createValidCriterionType("bla","");
CriterionType criterionType = createValidCriterionType("bla", "");
criterionTypeDAO.save(criterionType);
criterionType = createValidCriterionType("bla","");
criterionType = createValidCriterionType("bla", "");
criterionTypeDAO.save(criterionType);
}
@ -145,4 +154,5 @@ public class CriterionTypeDAOTest {
assertTrue(numberOfCriterionsOfTypeResourceAndWorker >= numberOfCriterionsOfTypeResource);
}
}