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