test_class.declarator: scoreDirector
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ScoreDirector<VehicleRoutingSolution> scoreDirector;
test_class.type: ScoreDirector<VehicleRoutingSolution>
test_class.var_name: scoreDirector
test_class.file: optaweb-vehicle-routing-backend/src/test/java/org/optaweb/vehiclerouting/plugin/planner/change/RemoveVisitTest.java
test_class.identifier: RemoveVisitTest
test_case.body: @Test
      void remove_middle_visit() {
          VehicleRoutingSolution solution = SolutionFactory.emptySolution();
          when(scoreDirector.getWorkingSolution()).thenReturn(solution);
  
          PlanningVisit firstVisit = testVisit(1);
          PlanningVisit middleVisit = testVisit(2);
          PlanningVisit lastVisit = testVisit(3);
          solution.getVisitList().add(firstVisit);
          solution.getVisitList().add(lastVisit);
          solution.getVisitList().add(middleVisit);
  
          // V -> first -> removed -> last
          firstVisit.setPreviousStandstill(testVehicle(1));
          firstVisit.setNextVisit(middleVisit);
          middleVisit.setPreviousStandstill(firstVisit);
          middleVisit.setNextVisit(lastVisit);
          lastVisit.setPreviousStandstill(middleVisit);
  
          PlanningVisit removedVisit = testVisit(2);
          when(scoreDirector.lookUpWorkingObject(removedVisit)).thenReturn(middleVisit);
  
          // do change
          RemoveVisit removeVisit = new RemoveVisit(removedVisit);
          removeVisit.doChange(scoreDirector);
  
          verify(scoreDirector).beforeVariableChanged(lastVisit, "previousStandstill");
          verify(scoreDirector).afterVariableChanged(lastVisit, "previousStandstill");
          verify(scoreDirector).beforeEntityRemoved(middleVisit);
          verify(scoreDirector).afterEntityRemoved(middleVisit);
          assertThat(solution.getVisitList())
                  .hasSize(2)
                  .containsOnly(firstVisit, lastVisit);
  
          // V -> first -> removed -> last
          assertThat(lastVisit.getPreviousStandstill()).isEqualTo(firstVisit);
  
          verify(scoreDirector).triggerVariableListeners();
      }
test_case.class_method_signature: RemoveVisitTest.remove_middle_visit()
test_case.full_signature: @Test void remove_middle_visit()
test_case.identifier: remove_middle_visit
test_case.invocations: emptySolution thenReturn when getWorkingSolution testVisit testVisit testVisit add getVisitList add getVisitList add getVisitList setPreviousStandstill testVehicle setNextVisit setPreviousStandstill setNextVisit setPreviousStandstill testVisit thenReturn when lookUpWorkingObject doChange beforeVariableChanged verify afterVariableChanged verify beforeEntityRemoved verify afterEntityRemoved verify containsOnly hasSize assertThat getVisitList isEqualTo assertThat getPreviousStandstill triggerVariableListeners verify
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void remove_middle_visit()
focal_class.declarator: planningVisit
focal_class.modifier: private final
focal_class.original_string: private final PlanningVisit planningVisit;
focal_class.type: PlanningVisit
focal_class.var_name: planningVisit
focal_class.file: optaweb-vehicle-routing-backend/src/main/java/org/optaweb/vehiclerouting/plugin/planner/change/RemoveVisit.java
focal_class.identifier: RemoveVisit
focal_class.interfaces: implements ProblemFactChange<VehicleRoutingSolution>
focal_class.class_method_signature: RemoveVisit.RemoveVisit(PlanningVisit planningVisit)
focal_class.full_signature: public  RemoveVisit(PlanningVisit planningVisit)
focal_class.identifier: RemoveVisit
focal_class.modifiers: public
focal_class.parameters: (PlanningVisit planningVisit)
focal_class.signature:  RemoveVisit(PlanningVisit planningVisit)
focal_class.class_method_signature: RemoveVisit.doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_class.full_signature: @Override public void doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_class.identifier: doChange
focal_class.modifiers: @Override public
focal_class.parameters: (ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_class.return: void
focal_class.signature: void doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_method.body: @Override
      public void doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector) {
          VehicleRoutingSolution workingSolution = scoreDirector.getWorkingSolution();
  
          // Look up a working copy of the visit
          PlanningVisit workingVisit = scoreDirector.lookUpWorkingObject(planningVisit);
          if (workingVisit == null) {
              throw new IllegalStateException("Can't look up a working copy of " + planningVisit);
          }
  
          // Fix the next visit and set its previousStandstill to the removed visit's previousStandstill
          PlanningVisit nextVisit = workingVisit.getNextVisit();
          if (nextVisit != null) { // otherwise it's the last visit
              scoreDirector.beforeVariableChanged(nextVisit, "previousStandstill");
              nextVisit.setPreviousStandstill(workingVisit.getPreviousStandstill());
              scoreDirector.afterVariableChanged(nextVisit, "previousStandstill");
          }
  
          // No need to clone the visitList because it is a planning entity collection, so it is already planning-cloned.
          // To learn more about problem fact changes, see:
          // https://docs.jboss.org/optaplanner/release/latest/optaplanner-docs/html_single/#problemFactChangeExample
  
          // Remove the visit
          scoreDirector.beforeEntityRemoved(workingVisit);
          if (!workingSolution.getVisitList().remove(workingVisit)) {
              throw new IllegalStateException(
                      "Working solution's visitList "
                              + workingSolution.getVisitList()
                              + " doesn't contain the workingVisit ("
                              + workingVisit
                              + "). This is a bug!");
          }
          scoreDirector.afterEntityRemoved(workingVisit);
  
          scoreDirector.triggerVariableListeners();
      }
focal_method.class_method_signature: RemoveVisit.doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_method.full_signature: @Override public void doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_method.identifier: doChange
focal_method.invocations: getWorkingSolution lookUpWorkingObject getNextVisit beforeVariableChanged setPreviousStandstill getPreviousStandstill afterVariableChanged beforeEntityRemoved remove getVisitList getVisitList afterEntityRemoved triggerVariableListeners
focal_method.modifiers: @Override public
focal_method.parameters: (ScoreDirector<VehicleRoutingSolution> scoreDirector)
focal_method.return: void
focal_method.signature: void doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector)