@Test void should_create_vehicle_and_generate_id_and_name() { VehicleEntity newEntity = vehicleEntity(testVehicle); when(crudRepository.save(vehicleEntityCaptor.capture())).thenReturn(newEntity); int savedCapacity = 1; Vehicle newVehicle = repository.createVehicle(savedCapacity); List<VehicleEntity> savedVehicles = vehicleEntityCaptor.getAllValues(); assertThat(savedVehicles).hasSize(2); assertThat(savedVehicles.get(0).getName()).isNull(); assertThat(savedVehicles.get(0).getCapacity()).isEqualTo(savedCapacity); assertThat(savedVehicles.get(1).getName()).isEqualTo("Vehicle " + newEntity.getId()); assertThat(savedVehicles.get(1).getCapacity()).isEqualTo(savedCapacity); 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);  }