@Test public void throwRNFExceptionWhenEditUnknownVehicle() throws Exception { when(vehicleRepository.findFirstByGarageIdAndVehicleId("gId", "vId")).thenReturn(null); expectedException.expect(isA(ResourcesNotFoundException.class)); expectedException.expectMessage("Vehicle not found"); defaultVehicleService.editVehicle(new VehicleRequest(), "gId", "vId"); }
@Test public void editVehicleFromGarage() throws Exception { VehicleResponse vehicleResponse = new VehicleResponse(); when(vehicleRepository.findFirstByGarageIdAndVehicleId("gId", "vId")) .thenReturn(vehicleResponse); when(vehicleResponseMapper.map(any(VehicleRequest.class), anyString(), anyString())) .thenReturn(vehicleResponse); VehicleRequest vehicleRequest = new VehicleRequest(); defaultVehicleService.editVehicle(vehicleRequest, "gId", "vId"); verify(vehicleRepository, times(1)).findFirstByGarageIdAndVehicleId("gId", "vId"); verify(vehicleRepository, times(1)).save(Matchers.isA(VehicleResponse.class)); verify(vehicleResponseMapper, times(1)) .map(any(VehicleRequest.class), anyString(), anyString()); verifyNoMoreInteractions(vehicleRepository); }