### Question:
NavigationHelper { public static StepIntersection findCurrentIntersection(@NonNull List<StepIntersection> intersections, @NonNull List<Pair<StepIntersection, Double>> measuredIntersections, double stepDistanceTraveled) { for (Pair<StepIntersection, Double> measuredIntersection : measuredIntersections) { double intersectionDistance = measuredIntersection.second; int intersectionIndex = measuredIntersections.indexOf(measuredIntersection); int nextIntersectionIndex = intersectionIndex + ONE_INDEX; int measuredIntersectionSize = measuredIntersections.size(); boolean hasValidNextIntersection = nextIntersectionIndex < measuredIntersectionSize; if (hasValidNextIntersection) { double nextIntersectionDistance = measuredIntersections.get(nextIntersectionIndex).second; if (stepDistanceTraveled > intersectionDistance && stepDistanceTraveled < nextIntersectionDistance) { return measuredIntersection.first; } } else if (stepDistanceTraveled > measuredIntersection.second) { return measuredIntersection.first; } else { return measuredIntersections.get(FIRST_INTERSECTION).first; } } return intersections.get(FIRST_INTERSECTION); } private  NavigationHelper(); @NonNull static List<StepIntersection> createIntersectionsList(@NonNull LegStep currentStep, LegStep upcomingStep); @NonNull static List<Pair<StepIntersection, Double>> createDistancesToIntersections(List<Point> stepPoints,
                                                                             List<StepIntersection> intersections); static StepIntersection findCurrentIntersection(@NonNull List<StepIntersection> intersections,
                                                  @NonNull List<Pair<StepIntersection, Double>> measuredIntersections,
                                                  double stepDistanceTraveled); static StepIntersection findUpcomingIntersection(@NonNull List<StepIntersection> intersections,
                                                   @Nullable LegStep upcomingStep,
                                                   StepIntersection currentIntersection); @Nullable static CurrentLegAnnotation createCurrentAnnotation(CurrentLegAnnotation currentLegAnnotation,
                                                      RouteLeg leg, double legDistanceRemaining);  }### Answer:
@Test public void findCurrentIntersection_beginningOfStepReturnsFirstIntersection() throws Exception { RouteProgress routeProgress = buildMultiLegRouteProgress(); RouteLegProgress legProgress = routeProgress.currentLegProgress(); RouteStepProgress stepProgress = legProgress.currentStepProgress(); List<StepIntersection> intersections = stepProgress.intersections(); List<Pair<StepIntersection, Double>> intersectionDistances = stepProgress.intersectionDistancesAlongStep(); StepIntersection currentIntersection = NavigationHelper.findCurrentIntersection( intersections, intersectionDistances, 0 ); assertTrue(currentIntersection.equals(intersections.get(0))); }
@Test public void findCurrentIntersection_endOfStepReturnsLastIntersection() throws Exception { RouteProgress routeProgress = buildMultiLegRouteProgress(); RouteLegProgress legProgress = routeProgress.currentLegProgress(); RouteStepProgress stepProgress = legProgress.currentStepProgress(); List<StepIntersection> intersections = stepProgress.intersections(); List<Pair<StepIntersection, Double>> intersectionDistances = stepProgress.intersectionDistancesAlongStep(); StepIntersection currentIntersection = NavigationHelper.findCurrentIntersection( intersections, intersectionDistances, legProgress.currentStep().distance() ); assertTrue(currentIntersection.equals(intersections.get(intersections.size() - 1))); }
@Test public void findCurrentIntersection_middleOfStepReturnsCorrectIntersection() throws Exception { RouteProgress routeProgress = buildMultiLegRouteProgress(100, 0, 0, 2, 0); RouteLegProgress legProgress = routeProgress.currentLegProgress(); RouteStepProgress stepProgress = legProgress.currentStepProgress(); List<StepIntersection> intersections = stepProgress.intersections(); List<Pair<StepIntersection, Double>> intersectionDistances = stepProgress.intersectionDistancesAlongStep(); StepIntersection currentIntersection = NavigationHelper.findCurrentIntersection( intersections, intersectionDistances, 130 ); assertTrue(currentIntersection.equals(intersections.get(1))); }