コード例 #1
0
  @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");
  }
コード例 #2
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");
  }
コード例 #3
0
  @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");
  }
コード例 #4
0
  @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);
  }
コード例 #5
0
  @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");
  }
コード例 #6
0
  @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);
  }
コード例 #7
0
  @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);
  }
コード例 #8
0
  @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);
  }
コード例 #9
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));
  }
コード例 #10
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);
  }