PlanningLocationFactory { public static PlanningLocation testLocation(long id) { return testLocation(id, PlanningLocationFactory::failFast); } private  PlanningLocationFactory(); static PlanningLocation fromDomain(Location location); static PlanningLocation fromDomain(Location location, DistanceMap distanceMap); static PlanningLocation testLocation(long id); static PlanningLocation testLocation(long id, DistanceMap distanceMap);  }
@Test void test_locations_distance_map_should_work() { long distance = 11231; PlanningLocation planningLocation = PlanningLocationFactory.testLocation(0, location -> distance); assertThat(planningLocation.distanceTo(PlanningLocationFactory.testLocation(1))).isEqualTo(distance); }
@Test void test_location_without_distance_map_should_throw_exception() { PlanningLocation planningLocation = PlanningLocationFactory.testLocation(0); PlanningLocation otherLocation = PlanningLocationFactory.testLocation(1); assertThatIllegalStateException().isThrownBy(() -> planningLocation.distanceTo(otherLocation)); }