DemoService { public String exportDataSet() { List<Location> visits = new ArrayList<>(locationRepository.locations()); Location depot = visits.isEmpty() ? null : visits.remove(0); List<Vehicle> vehicles = vehicleRepository.vehicles(); return dataSetMarshaller.marshal(new RoutingProblem( "Custom Vehicle Routing instance", vehicles, depot, visits)); } @Autowired  DemoService(
            RoutingProblemList routingProblems,
            LocationService locationService,
            LocationRepository locationRepository,
            VehicleService vehicleService,
            VehicleRepository vehicleRepository,
            DataSetMarshaller dataSetMarshaller); Collection<RoutingProblem> demos(); @Async void loadDemo(String name); String exportDataSet();  }
@Test void export_should_marshal_routing_plans_with_locations_and_vehicles_from_repository() { Location depot = new Location(0, Coordinates.valueOf(1.0, 2.0), "Depot"); Location visit1 = new Location(1, Coordinates.valueOf(11.0, 22.0), "Visit 1"); Location visit2 = new Location(2, Coordinates.valueOf(22.0, 33.0), "Visit 2"); Vehicle vehicle1 = VehicleFactory.createVehicle(11, "Vehicle 1", 100); Vehicle vehicle2 = VehicleFactory.createVehicle(12, "Vehicle 2", 200); when(locationRepository.locations()).thenReturn(Arrays.asList(depot, visit1, visit2)); when(vehicleRepository.vehicles()).thenReturn(Arrays.asList(vehicle1, vehicle2)); demoService.exportDataSet(); RoutingProblem routingProblem = verifyAndCaptureMarshalledProblem(); assertThat(routingProblem.name()).isNotNull(); assertThat(routingProblem.depot()).contains(depot); assertThat(routingProblem.visits()).containsExactly(visit1, visit2); assertThat(routingProblem.vehicles()).containsExactly(vehicle1, vehicle2); }
@Test void export_should_marshal_empty_routing_plan_when_repositories_empty() { when(locationRepository.locations()).thenReturn(Collections.emptyList()); when(vehicleRepository.vehicles()).thenReturn(Collections.emptyList()); demoService.exportDataSet(); RoutingProblem routingProblem = verifyAndCaptureMarshalledProblem(); assertThat(routingProblem.name()).isNotNull(); assertThat(routingProblem.depot()).isEmpty(); assertThat(routingProblem.visits()).isEmpty(); assertThat(routingProblem.vehicles()).isEmpty(); }