@Test void getDistance_should_throw_exception_when_no_route_exists() { whenRouteReturnResponse(); when(ghResponse.hasErrors()).thenReturn(true); when(ghResponse.getErrors()).thenReturn(Collections.singletonList(new RuntimeException())); GraphHopperRouter graphHopperRouter = new GraphHopperRouter(graphHopper); assertThatThrownBy(() -> graphHopperRouter.travelTimeMillis(from, to)) .isNotInstanceOf(NullPointerException.class) .isInstanceOf(RuntimeException.class) .hasMessageContaining("No route"); }
@Override public long travelTimeMillis(Coordinates from, Coordinates to) { GHRequest ghRequest = new GHRequest( from.latitude().doubleValue(), from.longitude().doubleValue(), to.latitude().doubleValue(), to.longitude().doubleValue()); GHResponse ghResponse = graphHopper.route(ghRequest); if (ghResponse.hasErrors()) { throw new DistanceCalculationException("No route from " + from + " to " + to, ghResponse.getErrors().get(0)); } return ghResponse.getBest().getTime(); }
GraphHopperRouter implements Router, DistanceCalculator, Region { @Override public long travelTimeMillis(Coordinates from, Coordinates to) { GHRequest ghRequest = new GHRequest( from.latitude().doubleValue(), from.longitude().doubleValue(), to.latitude().doubleValue(), to.longitude().doubleValue()); GHResponse ghResponse = graphHopper.route(ghRequest); if (ghResponse.hasErrors()) { throw new DistanceCalculationException("No route from " + from + " to " + to, ghResponse.getErrors().get(0)); } return ghResponse.getBest().getTime(); } }
GraphHopperRouter implements Router, DistanceCalculator, Region { @Override public long travelTimeMillis(Coordinates from, Coordinates to) { GHRequest ghRequest = new GHRequest( from.latitude().doubleValue(), from.longitude().doubleValue(), to.latitude().doubleValue(), to.longitude().doubleValue()); GHResponse ghResponse = graphHopper.route(ghRequest); if (ghResponse.hasErrors()) { throw new DistanceCalculationException("No route from " + from + " to " + to, ghResponse.getErrors().get(0)); } return ghResponse.getBest().getTime(); } @Autowired  GraphHopperRouter(GraphHopperOSM graphHopper); }
GraphHopperRouter implements Router, DistanceCalculator, Region { @Override public long travelTimeMillis(Coordinates from, Coordinates to) { GHRequest ghRequest = new GHRequest( from.latitude().doubleValue(), from.longitude().doubleValue(), to.latitude().doubleValue(), to.longitude().doubleValue()); GHResponse ghResponse = graphHopper.route(ghRequest); if (ghResponse.hasErrors()) { throw new DistanceCalculationException("No route from " + from + " to " + to, ghResponse.getErrors().get(0)); } return ghResponse.getBest().getTime(); } @Autowired  GraphHopperRouter(GraphHopperOSM graphHopper); @Override List<Coordinates> getPath(Coordinates from, Coordinates to); @Override long travelTimeMillis(Coordinates from, Coordinates to); @Override BoundingBox getBounds(); }
GraphHopperRouter implements Router, DistanceCalculator, Region { @Override public long travelTimeMillis(Coordinates from, Coordinates to) { GHRequest ghRequest = new GHRequest( from.latitude().doubleValue(), from.longitude().doubleValue(), to.latitude().doubleValue(), to.longitude().doubleValue()); GHResponse ghResponse = graphHopper.route(ghRequest); if (ghResponse.hasErrors()) { throw new DistanceCalculationException("No route from " + from + " to " + to, ghResponse.getErrors().get(0)); } return ghResponse.getBest().getTime(); } @Autowired  GraphHopperRouter(GraphHopperOSM graphHopper); @Override List<Coordinates> getPath(Coordinates from, Coordinates to); @Override long travelTimeMillis(Coordinates from, Coordinates to); @Override BoundingBox getBounds();  }