diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/bootstrap/CriterionsBootstrapTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/bootstrap/CriterionsBootstrapTest.java index fbe31decd..403e3b3c1 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/bootstrap/CriterionsBootstrapTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/bootstrap/CriterionsBootstrapTest.java @@ -4,6 +4,9 @@ import static org.junit.Assert.assertTrue; import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE; import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE; +import java.util.ArrayList; +import java.util.List; + import org.junit.Test; import org.junit.runner.RunWith; import org.navalplanner.business.resources.bootstrap.ICriterionsBootstrap; @@ -27,22 +30,43 @@ public class CriterionsBootstrapTest { @Autowired private ICriterionDAO criterionDAO; + private List somePredefinedCriterions; + + public CriterionsBootstrapTest() { + somePredefinedCriterions = getSomePredefinedCriterions(); + } + + private List getSomePredefinedCriterions() { + List result = new ArrayList(); + for (WorkingRelationship workingRelationship : WorkingRelationship.values()) { + result.add(workingRelationship.criterion()); + } + return result; + } + @Test public void testBootstrap() throws Exception { - Criterion criterion = WorkingRelationship.FIRED.criterion(); - if (criterionDAO.existsByNameAndType(criterion)) { - criterionDAO.removeByNameAndType(criterion); - } - criterion = WorkingRelationship.HIRED.criterion(); - if (criterionDAO.existsByNameAndType(criterion)) { - criterionDAO.removeByNameAndType(criterion); - } - + givenNoSomePredefinedCriterionExists(); criterionsBootstrap.loadRequiredData(); - criterion = WorkingRelationship.FIRED.criterion(); - assertTrue(criterionDAO.existsByNameAndType(criterion)); - criterion = WorkingRelationship.HIRED.criterion(); - assertTrue(criterionDAO.existsByNameAndType(criterion)); + thenAllSomePredefinedCriterionsExist(); + } + + private void givenNoSomePredefinedCriterionExists() { + for (Criterion criterion : somePredefinedCriterions) { + remove(criterion); + } + } + + private void thenAllSomePredefinedCriterionsExist() { + for (Criterion criterion : somePredefinedCriterions) { + assertTrue(criterionDAO.existsByNameAndType(criterion)); + } + } + + private void remove(Criterion criterion) { + if (criterionDAO.existsByNameAndType(criterion)) { + criterionDAO.removeByNameAndType(criterion); + } } }