SolverManager implements SolverEventListener<VehicleRoutingSolution> { @Override public void bestSolutionChanged(BestSolutionChangedEvent<VehicleRoutingSolution> bestSolutionChangedEvent) { if (!bestSolutionChangedEvent.isEveryProblemFactChangeProcessed()) { logger.info("Ignoring a new best solution that has some problem facts missing"); return; } routeChangedEventPublisher.publishSolution(bestSolutionChangedEvent.getNewBestSolution()); } @Autowired  SolverManager(
            Solver<VehicleRoutingSolution> solver,
            AsyncListenableTaskExecutor executor,
            RouteChangedEventPublisher routeChangedEventPublisher,
            ApplicationEventPublisher eventPublisher); @Override void bestSolutionChanged(BestSolutionChangedEvent<VehicleRoutingSolution> bestSolutionChangedEvent);  }
@Test void ignore_new_best_solutions_when_unprocessed_fact_changes() { when(bestSolutionChangedEvent.isEveryProblemFactChangeProcessed()).thenReturn(false); solverManager.bestSolutionChanged(bestSolutionChangedEvent); verify(bestSolutionChangedEvent, never()).getNewBestSolution(); verify(routeChangedEventPublisher, never()).publishSolution(any()); }
@Test void publish_new_best_solution_if_all_fact_changes_processed() { VehicleRoutingSolution solution = SolutionFactory.emptySolution(); when(bestSolutionChangedEvent.isEveryProblemFactChangeProcessed()).thenReturn(true); when(bestSolutionChangedEvent.getNewBestSolution()).thenReturn(solution); solverManager.bestSolutionChanged(bestSolutionChangedEvent); verify(routeChangedEventPublisher).publishSolution(solutionArgumentCaptor.capture()); VehicleRoutingSolution event = solutionArgumentCaptor.getValue(); assertThat(event).isSameAs(solution); }