DemoService { @Async public void loadDemo(String name) { RoutingProblem routingProblem = routingProblems.byName(name); routingProblem.depot().ifPresent(depot -> addWithRetry(depot.coordinates(), depot.description())); routingProblem.visits().forEach(visit -> addWithRetry(visit.coordinates(), visit.description())); routingProblem.vehicles().forEach(vehicleService::createVehicle); } @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 loadDemo() { when(routingProblems.byName(problemName)).thenReturn(routingProblem); when(locationService.createLocation(any(Coordinates.class), anyString())).thenReturn(true); demoService.loadDemo(problemName); verify(locationService, times(routingProblem.visits().size() + 1)) .createLocation(any(Coordinates.class), anyString()); verify(vehicleService, times(routingProblem.vehicles().size())) .createVehicle(any(VehicleData.class)); }
@Test void retry_when_adding_location_fails() { when(routingProblems.byName(problemName)).thenReturn(routingProblem); when(locationService.createLocation(any(Coordinates.class), anyString())).thenReturn(false); assertThatExceptionOfType(RuntimeException.class) .isThrownBy(() -> demoService.loadDemo(problemName)) .withMessageContaining(depot.coordinates().toString()); verify(locationService, times(DemoService.MAX_TRIES)).createLocation(any(Coordinates.class), anyString()); }