@Test public void deleteVehicleWithUnknownVehicleId_throwsRNFException() throws Exception { when(vehicleRepository.findFirstByGarageIdAndVehicleId("gId", "vId")).thenReturn(null); expectedException.expect(Is.isA(ResourcesNotFoundException.class)); expectedException.expectMessage("Vehicle not found"); defaultVehicleService.deleteVehicle("gId", "vId"); }
@Test public void throwRNFExceptionWhenAddNewVehicleWithUnknownGarage() throws Exception { when(garageRepository.findOne(anyString())).thenReturn(null); expectedException.expect(isA(ResourcesNotFoundException.class)); expectedException.expectMessage("Garage not found"); defaultVehicleService.addVehicle(any(VehicleRequest.class), "garage-id"); }
@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 throwRNFExceptionWhenRetrieveVehicleWithUnknownVehicleId() { when(vehicleRepository.findFirstByGarageIdAndVehicleId("garage-id", "vehicle-id")) .thenReturn(null); expectedException.expect(isA(ResourcesNotFoundException.class)); expectedException.expectMessage("Vehicle not found"); defaultVehicleService.findVehicle("garage-id", null); }
@Test public void throwRNFExceptionWhenRetrieveMultipleVehiclesWithUnknownVehiclesInGarage() throws Exception { when(vehicleRepository.findAllByGarageId("gId")).thenReturn(null); expectedException.expect(Is.isA(ResourcesNotFoundException.class)); expectedException.expectMessage("Vehicle not found"); defaultVehicleService.findAllVehicles("gId"); }
@Test public void retrieveMultipleVehiclesFromGarage() throws Exception { List<VehicleResponse> vehicleResponseList = new ArrayList(); when(vehicleRepository.findAllByGarageId("gId")).thenReturn(vehicleResponseList); defaultVehicleService.findAllVehicles("gId"); verify(vehicleRepository, times(1)).findAllByGarageId("gId"); verifyNoMoreInteractions(vehicleRepository); }
@Test public void findVehicleInGarageReturnsVehicle() { when(vehicleRepository.findFirstByGarageIdAndVehicleId("garage-id", "vehicle-id")) .thenReturn(new VehicleResponse()); defaultVehicleService.findVehicle("garage-id", "vehicle-id"); verify(vehicleRepository, times(1)).findFirstByGarageIdAndVehicleId(anyString(), anyString()); verify(vehicleRepository, times(1)).findFirstByGarageIdAndVehicleId("garage-id", "vehicle-id"); verifyNoMoreInteractions(vehicleRepository); }
@Test public void deleteVehicle() throws Exception { VehicleResponse vehicleResponse = new VehicleResponse(); when(vehicleRepository.findFirstByGarageIdAndVehicleId("gId", "vId")) .thenReturn(vehicleResponse); defaultVehicleService.deleteVehicle("gId", "vId"); verify(vehicleRepository, times(1)).findFirstByGarageIdAndVehicleId("gId", "vId"); verify(vehicleRepository, times(1)).delete("vId"); verifyNoMoreInteractions(vehicleRepository); }
@Test public void createVehicleAndPersistToDatabase() { when(garageRepository.findOne("garage-id")).thenReturn(new GarageEntity()); VehicleResponse vehicleResponse = new VehicleResponse(); when(vehicleResponseMapper.map(any(VehicleRequest.class), anyString(), anyString())) .thenReturn(vehicleResponse); when(vehicleRepository.save(vehicleResponse)).thenReturn(vehicleResponse); defaultVehicleService.addVehicle(any(VehicleRequest.class), "garage-id"); verify(garageRepository, times(1)).findOne(anyString()); verify(vehicleRepository, times(1)).save(any(VehicleResponse.class)); }
@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); }