@Test void should_return_distance_when_entity_is_found() { DistanceKey distanceKey = new DistanceKey(from.id(), to.id()); long distance = 10305; DistanceEntity distanceEntity = new DistanceEntity(distanceKey, distance); when(crudRepository.findById(distanceKey)).thenReturn(Optional.of(distanceEntity)); assertThat(repository.getDistance(from, to)).isEqualTo(distance); }
@Override public long getDistance(Location from, Location to) { Optional<DistanceEntity> optional = distanceRepository.findById(new DistanceKey(from.id(), to.id())); if (optional.isPresent()) { return optional.get().getDistance(); } return -1; }
DistanceRepositoryImpl implements DistanceRepository { @Override public long getDistance(Location from, Location to) { Optional<DistanceEntity> optional = distanceRepository.findById(new DistanceKey(from.id(), to.id())); if (optional.isPresent()) { return optional.get().getDistance(); } return -1; } }
DistanceRepositoryImpl implements DistanceRepository { @Override public long getDistance(Location from, Location to) { Optional<DistanceEntity> optional = distanceRepository.findById(new DistanceKey(from.id(), to.id())); if (optional.isPresent()) { return optional.get().getDistance(); } return -1; } @Autowired  DistanceRepositoryImpl(DistanceCrudRepository distanceRepository); }
DistanceRepositoryImpl implements DistanceRepository { @Override public long getDistance(Location from, Location to) { Optional<DistanceEntity> optional = distanceRepository.findById(new DistanceKey(from.id(), to.id())); if (optional.isPresent()) { return optional.get().getDistance(); } return -1; } @Autowired  DistanceRepositoryImpl(DistanceCrudRepository distanceRepository); @Override void saveDistance(Location from, Location to, long distance); @Override long getDistance(Location from, Location to); @Override void deleteDistances(Location location); @Override void deleteAll(); }
DistanceRepositoryImpl implements DistanceRepository { @Override public long getDistance(Location from, Location to) { Optional<DistanceEntity> optional = distanceRepository.findById(new DistanceKey(from.id(), to.id())); if (optional.isPresent()) { return optional.get().getDistance(); } return -1; } @Autowired  DistanceRepositoryImpl(DistanceCrudRepository distanceRepository); @Override void saveDistance(Location from, Location to, long distance); @Override long getDistance(Location from, Location to); @Override void deleteDistances(Location location); @Override void deleteAll();  }