@Test void create_vehicle_from_given_data() { VehicleEntity newEntity = vehicleEntity(testVehicle); when(crudRepository.save(vehicleEntityCaptor.capture())).thenReturn(newEntity); VehicleData vehicleData = VehicleFactory.vehicleData("x", 1); Vehicle newVehicle = repository.createVehicle(vehicleData); VehicleEntity savedVehicle = vehicleEntityCaptor.getValue(); assertThat(savedVehicle.getName()).isEqualTo(vehicleData.name()); assertThat(savedVehicle.getCapacity()).isEqualTo(vehicleData.capacity()); assertThat(newVehicle.id()).isEqualTo(newEntity.getId()); assertThat(newVehicle.name()).isEqualTo(newEntity.getName()); assertThat(newVehicle.capacity()).isEqualTo(newEntity.getCapacity()); }
@Override public Vehicle createVehicle(int capacity) { long id = repository.save(new VehicleEntity(0, null, capacity)).getId(); VehicleEntity vehicleEntity = repository.save(new VehicleEntity(id, "Vehicle " + id, capacity)); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Created vehicle {}.", vehicle); return vehicle; }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle createVehicle(int capacity) { long id = repository.save(new VehicleEntity(0, null, capacity)).getId(); VehicleEntity vehicleEntity = repository.save(new VehicleEntity(id, "Vehicle " + id, capacity)); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Created vehicle {}.", vehicle); return vehicle; } }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle createVehicle(int capacity) { long id = repository.save(new VehicleEntity(0, null, capacity)).getId(); VehicleEntity vehicleEntity = repository.save(new VehicleEntity(id, "Vehicle " + id, capacity)); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Created vehicle {}.", vehicle); return vehicle; } VehicleRepositoryImpl(VehicleCrudRepository repository); }
VehicleRepositoryImpl implements VehicleRepository { @Override public Vehicle createVehicle(int capacity) { long id = repository.save(new VehicleEntity(0, null, capacity)).getId(); VehicleEntity vehicleEntity = repository.save(new VehicleEntity(id, "Vehicle " + id, capacity)); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Created 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 createVehicle(int capacity) { long id = repository.save(new VehicleEntity(0, null, capacity)).getId(); VehicleEntity vehicleEntity = repository.save(new VehicleEntity(id, "Vehicle " + id, capacity)); Vehicle vehicle = toDomain(vehicleEntity); logger.info("Created 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);  }