RouteChangedEventPublisher { static RouteChangedEvent solutionToEvent(VehicleRoutingSolution solution, Object source) { List<ShallowRoute> routes = routes(solution); return new RouteChangedEvent( source, Distance.ofMillis(-solution.getScore().getSoftScore()), vehicleIds(solution), depotId(solution), visitIds(solution), routes); } @Autowired  RouteChangedEventPublisher(ApplicationEventPublisher eventPublisher);   }
@Test void fail_fast_if_vehicles_next_visit_doesnt_exist() { PlanningVehicle vehicle = testVehicle(1); vehicle.setNextVisit(testVisit(2)); VehicleRoutingSolution solution = solutionFromVisits( singletonList(vehicle), new PlanningDepot(testLocation(1)), singletonList(testVisit(3))); assertThatIllegalArgumentException() .isThrownBy(() -> RouteChangedEventPublisher.solutionToEvent(solution, this)) .withMessageContaining("Visit"); }
@Test void vehicle_without_a_depot_is_illegal_if_depot_exists() { PlanningDepot depot = new PlanningDepot(testLocation(1)); PlanningVehicle vehicle = testVehicle(1); VehicleRoutingSolution solution = solutionFromVisits(singletonList(vehicle), depot, emptyList()); vehicle.setDepot(null); assertThatIllegalArgumentException() .isThrownBy(() -> RouteChangedEventPublisher.solutionToEvent(solution, this)) .withMessageContaining("Vehicle"); }