@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()); }
@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); }
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); } }
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); }
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(); }
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();  }