ItEr44S10CUGravacionModelosUnidadesTraballoItEr43S12: Specifying some undefined behaviour on SchedulingState

This commit is contained in:
Óscar González Fernández 2010-01-21 01:28:35 +01:00
parent 5572a5b618
commit d62ef32102
2 changed files with 33 additions and 1 deletions

View file

@ -162,11 +162,21 @@ public class SchedulingState {
}
public void add(SchedulingState child) {
child.parent = this;
children.add(child);
child.changingParentTo(this);
setType(calculateTypeFromChildren());
}
private void changingParentTo(SchedulingState parent) {
this.parent = parent;
if (parent.getType().belongsToSchedulingPoint()) {
setTypeWithoutNotifyingParent(Type.SCHEDULED_SUBELEMENT);
for (SchedulingState each : getDescendants()) {
each.setTypeWithoutNotifyingParent(Type.SCHEDULED_SUBELEMENT);
}
}
}
public SchedulingState getParent() {
return parent;
}

View file

@ -314,6 +314,28 @@ public class SchedulingStateTest {
assertThat(root, hasType(Type.NO_SCHEDULED));
}
@Test
public void addingAChildToASchedulingPointMakesItAScheduledSubelementAndAllItsDescendants() {
childA.schedule();
SchedulingState newChild = new SchedulingState();
SchedulingState grandChild = new SchedulingState();
newChild.add(grandChild);
childA.add(newChild);
assertThat(newChild, hasType(Type.SCHEDULED_SUBELEMENT));
assertThat(grandChild, hasType(Type.SCHEDULED_SUBELEMENT));
}
@Test
public void addingAChildToAScheduledSubelementMakesItAScheduledSubelementAndAllItsDescendants() {
childA.schedule();
SchedulingState newChild = new SchedulingState();
SchedulingState grandChild = new SchedulingState();
newChild.add(grandChild);
grandChildA1.add(newChild);
assertThat(newChild, hasType(Type.SCHEDULED_SUBELEMENT));
assertThat(grandChild, hasType(Type.SCHEDULED_SUBELEMENT));
}
abstract static class SchedulingStateMatcher extends
BaseMatcher<SchedulingState> {
@Override