ICriterionType<Criterion> criterionType = createTypeThatMatches(false,
criterion, otherCriterion);
assertThat(worker.getCurrentSatisfactionsFor(criterion).size(),
equalTo(0));
assertFalse(criterion.isSatisfiedBy(worker));
Interval fromNow = Interval.from(new LocalDate());
assertTrue(worker.canAddSatisfaction(new CriterionWithItsType(
criterionType, criterion), fromNow));
worker.addSatisfaction(new CriterionWithItsType(criterionType,
criterion), fromNow);
assertTrue(criterion.isSatisfiedBy(worker));
assertThat(worker.getCurrentSatisfactionsFor(criterion).size(),
equalTo(1));
assertFalse(worker.canAddSatisfaction(new CriterionWithItsType(
criterionType, otherCriterion), fromNow));
try {
worker.addSatisfaction(new CriterionWithItsType(criterionType,
otherCriterion));
fail("must send exception since it already is activated for a criterion of the same type and the type doesn't allow repeated criterions per resource");
} catch (IllegalStateException e) {
// ok
}
assertThat(worker.query().from(criterionType).enforcedInAll(fromNow)
.result().size(), equalTo(1));
List<CriterionSatisfaction> finished = worker.finishEnforcedAt(
criterion, fromNow.getStart());
assertThat(finished.size(), equalTo(1));
assertTrue("all satisfactions are finished", worker.query().from(
criterionType).enforcedInAll(fromNow).result().isEmpty());
assertTrue(worker.canAddSatisfaction(new CriterionWithItsType(
criterionType, criterion), fromNow));