### Question:
ToleranceUtils { public static double dynamicRerouteDistanceTolerance(Point snappedPoint, RouteProgress routeProgress) { List<StepIntersection> intersections = routeProgress.currentLegProgress().currentStepProgress().intersections(); List<Point> intersectionsPoints = new ArrayList<>(); for (StepIntersection intersection : intersections) { intersectionsPoints.add(intersection.location()); } Point closestIntersection = TurfClassification.nearestPoint(snappedPoint, intersectionsPoints); if (closestIntersection.equals(snappedPoint)) { return NavigationConstants.MINIMUM_DISTANCE_BEFORE_REROUTING; } double distanceToNextIntersection = TurfMeasurement.distance(snappedPoint, closestIntersection, TurfConstants.UNIT_METERS); if (distanceToNextIntersection <= NavigationConstants.MANEUVER_ZONE_RADIUS) { return NavigationConstants.MINIMUM_DISTANCE_BEFORE_REROUTING / 2; } return NavigationConstants.MINIMUM_DISTANCE_BEFORE_REROUTING; } private  ToleranceUtils(); static double dynamicRerouteDistanceTolerance(Point snappedPoint,
                                                       RouteProgress routeProgress);  }### Answer:
@Test public void dynamicRerouteDistanceTolerance_userFarAwayFromIntersection() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteProgress routeProgress = buildDefaultTestRouteProgress(); List<Point> stepPoints = PolylineUtils.decode(route.geometry(), PRECISION_6); Point midPoint = TurfMeasurement.midpoint(stepPoints.get(0), stepPoints.get(1)); double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(midPoint, routeProgress); assertEquals(25.0, tolerance, DELTA); }
@Test public void dynamicRerouteDistanceTolerance_userCloseToIntersection() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteProgress routeProgress = buildDefaultTestRouteProgress(); double distanceToIntersection = route.distance() - 39; LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS); double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress); assertEquals(50.0, tolerance, DELTA); }
@Test public void dynamicRerouteDistanceTolerance_userJustPastTheIntersection() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteProgress routeProgress = buildDefaultTestRouteProgress(); double distanceToIntersection = route.distance(); LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS); double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress); assertEquals(50.0, tolerance, DELTA); }