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