Search in sources :

Example 1 with RouteProgress

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);
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 2 with RouteProgress

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());
}
Also used : RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 3 with RouteProgress

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());
}
Also used : RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 4 with RouteProgress

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);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Point(com.mapbox.geojson.Point) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 5 with RouteProgress

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);
}
Also used : RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Point(com.mapbox.geojson.Point) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)44 Test (org.junit.Test)44 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)39 Point (com.mapbox.geojson.Point)30 Location (android.location.Location)19 LineString (com.mapbox.geojson.LineString)12 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)10 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)3 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)3 Context (android.content.Context)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 MetricsRouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)2 RouteStepProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress)2 DistanceUtils (com.mapbox.services.android.navigation.v5.utils.DistanceUtils)2 Date (java.util.Date)2 Ignore (org.junit.Ignore)2