@Test
public void testSaveDependentTask() {
createChildParentTasks();
// check that 1 has no parents and has 2,3 as children
Task retrieved = taskDAO.get(task1.getId());
assertEquals(0, retrieved.getParentTasks().size());
assertEquals(2, retrieved.getChildTasks().size());
for (Task child : retrieved.getChildTasks()) {
assertTrue(task2.getId() == child.getId() || task3.getId() == child.getId());
}
// assert that 1 is parent of 2 and 4 is it's child
retrieved = taskDAO.get(task2.getId());
assertEquals(1, retrieved.getParentTasks().size());
assertEquals(task1.getId(), retrieved.getParentTasks().iterator().next().getId());
assertEquals(1, retrieved.getChildTasks().size());
assertEquals(task4.getId(), retrieved.getChildTasks().iterator().next().getId());
// assert that 1 is parent of 3 and 4 is it's child
retrieved = taskDAO.get(task3.getId());
assertEquals(1, retrieved.getParentTasks().size());
assertEquals(task1.getId(), retrieved.getParentTasks().iterator().next().getId());
assertEquals(1, retrieved.getChildTasks().size());
assertEquals(task4.getId(), retrieved.getChildTasks().iterator().next().getId());
// assert that 4 has no children and that 2 and 3 are its parents
retrieved = taskDAO.get(task4.getId());
assertEquals(2, retrieved.getParentTasks().size());
for (Task parent : retrieved.getParentTasks()) {
assertTrue(task2.getId() == parent.getId() || task3.getId() == parent.getId());
}
assertEquals(0, retrieved.getChildTasks().size());
}