@Test
void should_create_vehicle_and_generate_id_and_name() {

    // arrange
    VehicleEntity newEntity = vehicleEntity(testVehicle);
    when(crudRepository.save(vehicleEntityCaptor.capture())).thenReturn(newEntity);
    int savedCapacity = 1;
    // act
    Vehicle newVehicle = repository.createVehicle(savedCapacity);
    // assert
    // -- the correct values were used to save the entity
    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);
    // -- created domain vehicle is equal to the entity returned by repository.save()
    // This may be confusing but that's the contract of Spring Repository API.
    // The entity instance that is being saved is meant to be discarded. The returned instance should be used
    // for further operations as the save() operation may update it (for example generate the ID).
    assertThat(newVehicle.id()).isEqualTo(newEntity.getId());
    assertThat(newVehicle.name()).isEqualTo(newEntity.getName());
    assertThat(newVehicle.capacity()).isEqualTo(newEntity.getCapacity());
}