-
Enhancement
-
Resolution: Done
-
Minor
-
None
-
None
-
2021 Week 07-09 (from Feb 15)
-
3
-
Undefined
-
NEW
-
NEW
Given
Constraint personConflict(ConstraintFactory constraintFactory) { return constraintFactory .fromUniquePair(Injection.class, Joiners.equal(Injection::getPerson)) .penalize("Person conflict", HardMediumSoftLongScore.ofHard(100)); // There is no matchWeighter }
I need to do:
@Test
void personConflict() {
constraintVerifier.verifyThat(VaccinationScheduleConstraintProvider::personConflict)
.given(
...)
.penalizesBy(1); // The 1 is the match weight
}
But I'd rather do:
@Test
void personConflict() {
constraintVerifier.verifyThat(VaccinationScheduleConstraintProvider::personConflict)
.given(
...)
.penalizes(); // Automatically use matchWeight 1
}
Reqs:
- For an IntScore, use 1, for a LongScore, use 1L, for a BigDecimalScore, use BigDecimal.ONE.
- docs + go through the examples and quickstarts to replace penalizesBy(1) if and only if the actual constraint doesn't use a matchWeighter
Proposals:
A) Call it penalizes() - Not clear that it's once
B) Call it penalizesOnce(), so it clearer it only triggers once.
C) Call it penalizes(int times).
Problem of A (and partially B):
@Test void personConflict() { constraintVerifier.verifyThat(VaccinationScheduleConstraintProvider::personConflict) .given( new Injection(1, VACCINATION_CENTER_1, 0, MONDAY_0900, VaccineType.PFIZER, ANN), new Injection(1, VACCINATION_CENTER_1, 0, MONDAY_1000, VaccineType.PFIZER, BETH), new Injection(1, VACCINATION_CENTER_1, 0, MONDAY_1100, VaccineType.PFIZER, ANN) new Injection(1, VACCINATION_CENTER_1, 0, MONDAY_1200, VaccineType.PFIZER, BETH), ) .penalizesBy(2); }
The test code above needs to do penalizesBy(2), yet the constraint itself doesn't have a matchWeight.
Therefore C) starts making sense... In which case, how different is this from penalizesBy(2)?