ItEr21S04ArquitecturaServidorItEr20S04: Refactoring test so it expresses its intent in a clearer way.
This commit is contained in:
parent
2f5453923c
commit
a5d9366397
1 changed files with 37 additions and 13 deletions
|
|
@ -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<Criterion> somePredefinedCriterions;
|
||||
|
||||
public CriterionsBootstrapTest() {
|
||||
somePredefinedCriterions = getSomePredefinedCriterions();
|
||||
}
|
||||
|
||||
private List<Criterion> getSomePredefinedCriterions() {
|
||||
List<Criterion> result = new ArrayList<Criterion>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue