@Test
void should_call_router_and_persist_distances_when_repo_is_empty() {

    Location l1 = location(100, -1);
    Location l2 = location(111, 20);
    long dist12 = 12;
    long dist21 = 21;
    when(distanceRepository.getDistance(any(), any())).thenReturn(-1L);
    when(distanceCalculator.travelTimeMillis(l1.coordinates(), l2.coordinates())).thenReturn(dist12);
    when(distanceCalculator.travelTimeMillis(l2.coordinates(), l1.coordinates())).thenReturn(dist21);
    // no calculation for the first location
    distanceMatrix.addLocation(l1);
    verifyNoInteractions(distanceCalculator);
    verifyNoInteractions(distanceRepository);
    distanceMatrix.addLocation(l2);
    // getting distances from the repository (unsuccessful)
    verify(distanceRepository).getDistance(l2, l1);
    verify(distanceRepository).getDistance(l1, l2);
    // distances are calculated and persisted
    verify(distanceRepository).saveDistance(l2, l1, dist21);
    verify(distanceRepository).saveDistance(l1, l2, dist12);
}