@Test void remove_created_vehicle_by_id() { VehicleEntity vehicleEntity = vehicleEntity(testVehicle); final long id = testVehicle.id(); when(crudRepository.findById(id)).thenReturn(Optional.of(vehicleEntity)); Vehicle removed = repository.removeVehicle(id); assertThat(removed).isEqualTo(testVehicle); verify(crudRepository).deleteById(id); }
@Override public Vehicle removeVehicle(long id) { Optional<VehicleEntity> optionalVehicleEntity = repository.findById(id); VehicleEntity vehicleEntity = optionalVehicleEntity.orElseThrow( () -> new IllegalArgumentException("Vehicle{id=" + id + "} doesn't exist")); repository.deleteById(id); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Deleted vehicle {}.", vehicle); return vehicle; }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle removeVehicle(long id) { Optional<VehicleEntity> optionalVehicleEntity = repository.findById(id); VehicleEntity vehicleEntity = optionalVehicleEntity.orElseThrow( () -> new IllegalArgumentException("Vehicle{id=" + id + "} doesn't exist")); repository.deleteById(id); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Deleted vehicle {}.", vehicle); return vehicle; } }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle removeVehicle(long id) { Optional<VehicleEntity> optionalVehicleEntity = repository.findById(id); VehicleEntity vehicleEntity = optionalVehicleEntity.orElseThrow( () -> new IllegalArgumentException("Vehicle{id=" + id + "} doesn't exist")); repository.deleteById(id); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Deleted vehicle {}.", vehicle); return vehicle; } VehicleRepositoryImpl(VehicleCrudRepository repository); }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle removeVehicle(long id) { Optional<VehicleEntity> optionalVehicleEntity = repository.findById(id); VehicleEntity vehicleEntity = optionalVehicleEntity.orElseThrow( () -> new IllegalArgumentException("Vehicle{id=" + id + "} doesn't exist")); repository.deleteById(id); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Deleted vehicle {}.", vehicle); return vehicle; } VehicleRepositoryImpl(VehicleCrudRepository repository); @Override Vehicle createVehicle(int capacity); @Override Vehicle createVehicle(VehicleData vehicleData); @Override List<Vehicle> vehicles(); @Override Vehicle removeVehicle(long id); @Override void removeAll(); @Override Optional<Vehicle> find(long vehicleId); @Override void update(Vehicle vehicle); }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle removeVehicle(long id) { Optional<VehicleEntity> optionalVehicleEntity = repository.findById(id); VehicleEntity vehicleEntity = optionalVehicleEntity.orElseThrow( () -> new IllegalArgumentException("Vehicle{id=" + id + "} doesn't exist")); repository.deleteById(id); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Deleted vehicle {}.", vehicle); return vehicle; } VehicleRepositoryImpl(VehicleCrudRepository repository); @Override Vehicle createVehicle(int capacity); @Override Vehicle createVehicle(VehicleData vehicleData); @Override List<Vehicle> vehicles(); @Override Vehicle removeVehicle(long id); @Override void removeAll(); @Override Optional<Vehicle> find(long vehicleId); @Override void update(Vehicle vehicle);  }