VehicleService { public void changeCapacity(long vehicleId, int capacity) { Vehicle vehicle = vehicleRepository.find(vehicleId).orElseThrow(() -> new IllegalArgumentException( "Can't remove Vehicle{id=" + vehicleId + "} because it doesn't exist")); Vehicle updatedVehicle = VehicleFactory.createVehicle(vehicle.id(), vehicle.name(), capacity); vehicleRepository.update(updatedVehicle); optimizer.changeCapacity(updatedVehicle); } @Autowired  VehicleService(RouteOptimizer optimizer, VehicleRepository vehicleRepository); void createVehicle(); void createVehicle(VehicleData vehicleData); void addVehicle(Vehicle vehicle); void removeVehicle(long vehicleId); synchronized void removeAnyVehicle(); void removeAll(); void changeCapacity(long vehicleId, int capacity);  }
@Test void changeCapacity() { final long vehicleId = 1; final int capacity = 123; final Vehicle originalVehicle = VehicleFactory.createVehicle(vehicleId, "1", capacity - 10); when(vehicleRepository.find(vehicleId)).thenReturn(Optional.of(originalVehicle)); vehicleService.changeCapacity(vehicleId, capacity); verify(vehicleRepository).update(vehicleArgumentCaptor.capture()); assertThat(vehicleArgumentCaptor.getValue().id()).isEqualTo(vehicleId); assertThat(vehicleArgumentCaptor.getValue().capacity()).isEqualTo(capacity); verify(optimizer).changeCapacity(vehicleArgumentCaptor.capture()); assertThat(vehicleArgumentCaptor.getValue().capacity()).isEqualTo(capacity); }