コード例 #1
0
  @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");
  }
コード例 #2
0
  @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));
  }