PortableVehicle { static PortableVehicle fromVehicle(Vehicle vehicle) { Objects.requireNonNull(vehicle, "vehicle must not be null"); return new PortableVehicle(vehicle.id(), vehicle.name(), vehicle.capacity()); } PortableVehicle(long id, String name, int capacity); long getId(); String getName(); int getCapacity(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test void fromVehicle() { long id = 321; String name = "Pink XY-123 B"; int capacity = 31; PortableVehicle portableVehicle = PortableVehicle.fromVehicle(VehicleFactory.createVehicle(id, name, capacity)); assertThat(portableVehicle.getId()).isEqualTo(id); assertThat(portableVehicle.getName()).isEqualTo(name); assertThat(portableVehicle.getCapacity()).isEqualTo(capacity); assertThatNullPointerException() .isThrownBy(() -> PortableVehicle.fromVehicle(null)) .withMessageContaining("vehicle"); }