Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-2326

Fail fast if CS test given() is called with multiple entities with the same planning id and the same class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 8.4.0.Final
    • None
    • optaplanner-test
    • None

      This test succeeds:

          @Test
          void personConflict() {
              constraintVerifier.verifyThat(VaccinationScheduleConstraintProvider::personConflict)
                      .given(
                              new Injection(1, VACCINATION_CENTER_1, 0, MONDAY_0900, VaccineType.PFIZER, ANN),
                              new Injection(2, VACCINATION_CENTER_1, 0, MONDAY_1000, VaccineType.PFIZER, BETH),
                              new Injection(3, VACCINATION_CENTER_1, 0, MONDAY_1100, VaccineType.PFIZER, ANN)
                              )
                      .penalizesBy(1);
          }
      

      This test doesn't succeed:

          @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)
                              )
                      .penalizesBy(1);
          }
      

      But the error message has nothing to do with the actual cause:

      java.lang.AssertionError: Broken expectation.
              Constraint: org.acme.vaccinationscheduler.domain/Person conflict
        Expected penalty: 1 (class java.lang.Integer)
          Actual penalty: 0 (class java.lang.Long)
      
        Explanation of score (0hard/0medium/0soft):
          Constraint match totals:
              0: constraint (Person conflict) has 0 matches:
          Indictments:
      

      Notice that the real problem - the only difference - is that the @PlanningId is 3 times the same in the second code.

              lpetrovi@redhat.com Lukáš Petrovický (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: