LocationRepositoryImpl implements LocationRepository { @Override public Location createLocation(Coordinates coordinates, String description) { LocationEntity locationEntity = repository.save( new LocationEntity(0, coordinates.latitude(), coordinates.longitude(), description)); Location location = toDomain(locationEntity); logger.info("Created location {}.", location.fullDescription()); return location; } @Autowired  LocationRepositoryImpl(LocationCrudRepository repository); @Override Location createLocation(Coordinates coordinates, String description); @Override List<Location> locations(); @Override Location removeLocation(long id); @Override void removeAll(); @Override Optional<Location> find(long locationId);  }
@Test void should_create_location_and_generate_id() { LocationEntity newEntity = locationEntity(testLocation); when(crudRepository.save(locationEntityCaptor.capture())).thenReturn(newEntity); Coordinates savedCoordinates = Coordinates.valueOf(0.00213, 32.777); String savedDescription = "new location"; Location newLocation = repository.createLocation(savedCoordinates, savedDescription); LocationEntity savedLocation = locationEntityCaptor.getValue(); assertThat(savedLocation.getLatitude()).isEqualTo(savedCoordinates.latitude()); assertThat(savedLocation.getLongitude()).isEqualTo(savedCoordinates.longitude()); assertThat(savedLocation.getDescription()).isEqualTo(savedDescription); assertThat(newLocation.id()).isEqualTo(newEntity.getId()); assertThat(newLocation.coordinates()) .isEqualTo(new Coordinates(newEntity.getLatitude(), newEntity.getLongitude())); assertThat(newLocation.description()).isEqualTo(newEntity.getDescription()); }