@Test
public void onlyIfPredicateIsTrueWhenTaskIsEnabledAndAllPredicatesAreTrue() {
final AtomicBoolean condition1 = new AtomicBoolean(true);
final AtomicBoolean condition2 = new AtomicBoolean(true);
AbstractTask task = getTask();
task.onlyIf(new Spec<Task>() {
public boolean isSatisfiedBy(Task element) {
return condition1.get();
}
});
task.onlyIf(new Spec<Task>() {
public boolean isSatisfiedBy(Task element) {
return condition2.get();
}
});
assertTrue(task.getOnlyIf().isSatisfiedBy(task));
task.setEnabled(false);
assertFalse(task.getOnlyIf().isSatisfiedBy(task));
task.setEnabled(true);
condition1.set(false);
assertFalse(task.getOnlyIf().isSatisfiedBy(task));
condition1.set(true);
condition2.set(false);
assertFalse(task.getOnlyIf().isSatisfiedBy(task));
condition2.set(true);
assertTrue(task.getOnlyIf().isSatisfiedBy(task));
}