ItEr34S12CUCreacionUnidadesPlanificacionItEr33S14: Adding support for unscheduling
This commit is contained in:
parent
6417fd9431
commit
f7f0ac6250
2 changed files with 96 additions and 0 deletions
|
|
@ -185,6 +185,30 @@ public class SchedulingState {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean canBeUnscheduled() {
|
||||
return getType() == Type.SCHEDULING_POINT;
|
||||
}
|
||||
|
||||
public void unschedule() {
|
||||
if (!canBeUnscheduled()) {
|
||||
throw new IllegalStateException("it can't be unscheduled");
|
||||
}
|
||||
setType(Type.NO_SCHEDULED);
|
||||
markDescendantsAsNoScheduled();
|
||||
}
|
||||
|
||||
private void markDescendantsAsNoScheduled() {
|
||||
for (SchedulingState each : children) {
|
||||
each.ancestorUnscheduled();
|
||||
each.markDescendantsAsNoScheduled();
|
||||
}
|
||||
}
|
||||
|
||||
private void ancestorUnscheduled() {
|
||||
Validate.isTrue(type == Type.SCHEDULED_SUBELEMENT);
|
||||
setType(Type.NO_SCHEDULED);
|
||||
}
|
||||
|
||||
private void setType(Type type) {
|
||||
if (this.type == type) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -242,6 +242,63 @@ public class SchedulingStateTest {
|
|||
assertThat(childB.getParent(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aNotScheduledElementCantBeUnScheduled(){
|
||||
assertFalse(root.canBeUnscheduled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCompletelyScheduledElementCanBeUnScheduled() {
|
||||
root.schedule();
|
||||
assertTrue(root.canBeUnscheduled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callingUnscheduleIfYouCantScheduleThrowsException() {
|
||||
for (SchedulingState each : all()) {
|
||||
try {
|
||||
each.unschedule();
|
||||
fail("unscheduling " + each + " must send exception");
|
||||
} catch (IllegalStateException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scheduledSubelementsCantBeUnScheduled() {
|
||||
root.schedule();
|
||||
assertThat(allRootDescendants(), each(not(canBeUnsheduled())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterUnschedulingAllDescendantsAreNoScheduled() {
|
||||
root.schedule();
|
||||
root.unschedule();
|
||||
assertThat(allRootDescendants(), each(hasType(Type.NO_SCHEDULED)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterUnSchedulingItsNotScheduled() {
|
||||
root.schedule();
|
||||
root.unschedule();
|
||||
assertThat(root, hasType(Type.NO_SCHEDULED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theChangeOfTypeIsNotified() {
|
||||
root.schedule();
|
||||
final boolean[] typeChanged = { false };
|
||||
childA.addTypeChangeListener(new ITypeChangedListener() {
|
||||
@Override
|
||||
public void typeChanged(Type newType) {
|
||||
typeChanged[0] = true;
|
||||
}
|
||||
});
|
||||
root.unschedule();
|
||||
assertTrue(typeChanged[0]);
|
||||
}
|
||||
|
||||
abstract static class SchedulingStateMatcher extends
|
||||
BaseMatcher<SchedulingState> {
|
||||
@Override
|
||||
|
|
@ -303,4 +360,19 @@ public class SchedulingStateTest {
|
|||
};
|
||||
}
|
||||
|
||||
private Matcher<SchedulingState> canBeUnsheduled() {
|
||||
return new SchedulingStateMatcher() {
|
||||
|
||||
@Override
|
||||
protected boolean matches(SchedulingState schedulingState) {
|
||||
return schedulingState.canBeUnscheduled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("cannot be scheduled");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue