use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationEventDispatcherTest method setNavigationMetricListener_didNotGetTriggeredUntilArrival.
@Test
public void setNavigationMetricListener_didNotGetTriggeredUntilArrival() throws Exception {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
navigationEventDispatcher.addMetricEventListeners(eventListeners);
navigationEventDispatcher.addMetricArrivalListener(arrivalListener);
// Progress that hasn't arrived
RouteProgress routeProgressDidNotArrive = RouteProgress.builder().stepDistanceRemaining(100).legDistanceRemaining(100).distanceRemaining(100).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
navigationEventDispatcher.onProgressChange(location, routeProgressDidNotArrive);
verify(eventListeners, times(1)).onRouteProgressUpdate(routeProgressDidNotArrive);
verify(arrivalListener, times(0)).onArrival(location, routeProgressDidNotArrive);
// Progress that has arrived
RouteProgress routeProgressDidArrive = RouteProgress.builder().stepDistanceRemaining(30).legDistanceRemaining(30).distanceRemaining(30).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
navigationEventDispatcher.onProgressChange(location, routeProgressDidArrive);
verify(eventListeners, times(1)).onRouteProgressUpdate(routeProgressDidArrive);
verify(arrivalListener, times(1)).onArrival(location, routeProgressDidArrive);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationHelperTest method increaseIndex_increasesLegIndex.
@Test
public void increaseIndex_increasesLegIndex() throws Exception {
RouteProgress routeProgress = routeProgressBuilder.legIndex(0).stepIndex(21).build();
NavigationIndices previousIndices = NavigationIndices.create(0, 21);
NavigationIndices newIndices = NavigationHelper.increaseIndex(routeProgress, previousIndices);
assertEquals(1, newIndices.legIndex());
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationHelperTest method increaseIndex_stepIndexResetsOnLegIndexIncrease.
@Test
public void increaseIndex_stepIndexResetsOnLegIndexIncrease() throws Exception {
RouteProgress routeProgress = routeProgressBuilder.legIndex(0).stepIndex(21).build();
NavigationIndices previousIndices = NavigationIndices.create(0, 21);
NavigationIndices newIndices = NavigationHelper.increaseIndex(routeProgress, previousIndices);
assertEquals(0, newIndices.stepIndex());
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationRouteProcessorTest method withinManeuverRadiusAndBearingMatches_stepIndexIsIncreased.
@Test
public void withinManeuverRadiusAndBearingMatches_stepIndexIsIncreased() throws Exception {
RouteProgress firstProgress = routeProcessor.buildNewRouteProgress(navigation, mock(Location.class));
int firstProgressIndex = firstProgress.currentLegProgress().stepIndex();
List<Point> coordinates = createCoordinatesFromCurrentStep(firstProgress);
Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 2);
Location rawLocation = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
when(rawLocation.getBearing()).thenReturn(145f);
RouteProgress secondProgress = routeProcessor.buildNewRouteProgress(navigation, rawLocation);
int secondProgressIndex = secondProgress.currentLegProgress().stepIndex();
assertTrue(firstProgressIndex != secondProgressIndex);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationRouteProcessorTest method onInvalidNextLeg_indexIsNotIncreased.
@Test
public void onInvalidNextLeg_indexIsNotIncreased() throws Exception {
routeProcessor.buildNewRouteProgress(navigation, mock(Location.class));
int legSize = navigation.getRoute().legs().size();
for (int i = 0; i < legSize; i++) {
routeProcessor.onShouldIncreaseIndex();
routeProcessor.checkIncreaseIndex(navigation);
}
RouteProgress progress = routeProcessor.buildNewRouteProgress(navigation, mock(Location.class));
assertTrue(progress.legIndex() == legSize - 1);
}
Aggregations