### Question:
NavigationEventDispatcher { void onUserOffRoute(Location location) { for (OffRouteListener offRouteListener : offRouteListeners) { offRouteListener.userOffRoute(location); } if (metricEventListener != null) { metricEventListener.onOffRouteEvent(location); } } NavigationEventDispatcher();   NavigationEventDispatcher(RouteUtils routeUtils);   }### Answer:
@Test public void onArrivalDuringLastLeg_offRouteListenerIsRemoved() { String instruction = ""; Location location = mock(Location.class); BannerInstructionMilestone milestone = mock(BannerInstructionMilestone.class); RouteUtils routeUtils = mock(RouteUtils.class); when(routeUtils.isArrivalEvent(routeProgress, milestone)).thenReturn(true); when(routeUtils.isLastLeg(routeProgress)).thenReturn(true); NavigationEventDispatcher navigationEventDispatcher = buildEventDispatcherHasArrived(instruction, routeUtils, milestone); navigationEventDispatcher.onUserOffRoute(location); verify(offRouteListener, times(0)).userOffRoute(location); }
@Test public void onArrivalDuringLastLeg_metricEventListenerIsRemoved() { String instruction = ""; Location location = mock(Location.class); BannerInstructionMilestone milestone = mock(BannerInstructionMilestone.class); RouteUtils routeUtils = mock(RouteUtils.class); when(routeUtils.isArrivalEvent(routeProgress, milestone)).thenReturn(true); when(routeUtils.isLastLeg(routeProgress)).thenReturn(true); NavigationEventDispatcher dispatcher = buildEventDispatcherHasArrived(instruction, routeUtils, milestone); dispatcher.onUserOffRoute(location); verify(metricEventListener, times(0)).onOffRouteEvent(location); }