Skip to content

Commit

Permalink
Fix tests broken from updated fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Apr 17, 2018
1 parent d7c5c4b commit a730bcf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.api.directions.v5.models.LegStep;
import com.mapbox.api.directions.v5.models.RouteLeg;
import com.mapbox.services.android.navigation.v5.BaseTest;

import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;

import java.io.IOException;

public class RouteLegProgressTest extends BaseTest {

Expand Down Expand Up @@ -52,16 +53,21 @@ public void sanityTest() {

@Test
public void upComingStep_returnsNextStepInLeg() {
int stepIndex = 5;
List<LegStep> steps = route.legs().get(0).steps();
RouteProgress routeProgress = RouteProgress.builder()
.stepDistanceRemaining(route.legs().get(0).steps().get(0).distance())
.stepDistanceRemaining(steps.get(stepIndex).distance())
.legDistanceRemaining(route.legs().get(0).distance())
.distanceRemaining(route.distance())
.directionsRoute(route)
.stepIndex(5)
.stepIndex(stepIndex)
.legIndex(0)
.build();
assertTrue(routeProgress.currentLegProgress().upComingStep().geometry()
.startsWith("so{gfA~}xpgFzOyNnRoOdVqXzLmQbDiGhKqQ|Vie@`X{g@dkAw{B~NcXhPoWlRmXfSeW|U"));
LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();

int upComingStepIndex = steps.indexOf(upComingStep);

assertEquals(stepIndex + 1, upComingStepIndex);
}

@Test
Expand Down Expand Up @@ -236,15 +242,17 @@ public void getDistanceTraveled_equalsLegDistanceAtEndOfLeg() {

@Test
public void getDurationRemaining_equalsLegDurationAtBeginning() {
RouteLeg firstLeg = route.legs().get(0);
RouteProgress routeProgress = RouteProgress.builder()
.stepDistanceRemaining(route.legs().get(0).steps().get(0).distance())
.legDistanceRemaining(route.legs().get(0).distance())
.stepDistanceRemaining(firstLeg.steps().get(0).distance())
.legDistanceRemaining(firstLeg.distance())
.distanceRemaining(route.distance())
.directionsRoute(route)
.stepIndex(0)
.legIndex(0)
.build();
assertEquals(3535.2, routeProgress.currentLegProgress().durationRemaining(), BaseTest.DELTA);

assertEquals(firstLeg.duration(), routeProgress.currentLegProgress().durationRemaining(), BaseTest.DELTA);
}

@Test
Expand All @@ -262,16 +270,21 @@ public void getDurationRemaining_equalsZeroAtEndOfLeg() {

@Test
public void followOnStep_doesReturnTwoStepsAheadOfCurrent() throws Exception {
int stepIndex = 5;
List<LegStep> steps = route.legs().get(0).steps();
RouteProgress routeProgress = RouteProgress.builder()
.stepDistanceRemaining(route.legs().get(0).steps().get(0).distance())
.stepDistanceRemaining(steps.get(stepIndex).distance())
.legDistanceRemaining(route.legs().get(0).distance())
.distanceRemaining(route.distance())
.directionsRoute(route)
.stepIndex(5)
.stepIndex(stepIndex)
.legIndex(0)
.build();
assertTrue(routeProgress.currentLegProgress().followOnStep().geometry()
.startsWith("un`ffAz_dogFz`Aq^hF{B|GaB|HcAxKKlIp@lOzC|Dh@hKtAzFh@`FDvHy@bG{AjKaEfF"));
LegStep followOnStep = routeProgress.currentLegProgress().followOnStep();

int followOnIndex = steps.indexOf(followOnStep);

assertEquals(stepIndex + 2, followOnIndex);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.api.directions.v5.models.RouteLeg;
import com.mapbox.services.android.navigation.BuildConfig;
import com.mapbox.services.android.navigation.v5.BaseTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLocationManager;

import java.io.IOException;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import java.io.IOException;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, shadows = {ShadowLocationManager.class})
public class RouteProgressTest extends BaseTest {

// Fixtures
Expand Down Expand Up @@ -116,7 +109,9 @@ public void fractionTraveled_equalsOneAtEndOfRoute() {

@Test
public void durationRemaining_equalsRouteDurationAtBeginning() {
assertEquals(3535.2, beginningRouteProgress.durationRemaining(), BaseTest.DELTA);
double durationRemaining = route.duration();

assertEquals(durationRemaining, beginningRouteProgress.durationRemaining(), BaseTest.DELTA);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,11 @@ public void fractionTraveled_equalsOneAtEndOfStep() {

@Test
public void getDurationRemaining_equalsStepDurationAtBeginning() {
LegStep fourthStep = firstLeg.steps().get(5);
double stepDistanceRemaining = fourthStep.distance();
double stepDuration = fourthStep.duration();
RouteProgress routeProgress = RouteProgress.builder()
.stepDistanceRemaining(firstLeg.steps().get(5).distance())
.stepDistanceRemaining(stepDistanceRemaining)
.legDistanceRemaining(firstLeg.distance())
.distanceRemaining(route.distance())
.directionsRoute(route)
Expand All @@ -295,7 +298,9 @@ public void getDurationRemaining_equalsStepDurationAtBeginning() {
.build();

RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
assertEquals(41.5, routeStepProgress.durationRemaining(), BaseTest.DELTA);
double durationRemaining = routeStepProgress.durationRemaining();

assertEquals(stepDuration, durationRemaining, BaseTest.DELTA);
}

@Test
Expand Down Expand Up @@ -357,12 +362,10 @@ public void stepIntersections_includesAllStepIntersectionsAndNextManeuver() thro
.build();
RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();

int currentStepTotal = route.legs().get(0).steps().get(3).intersections().size();
Point maneuverLocation = route.legs().get(0).steps().get(4).maneuver().location();
int stepIntersections = route.legs().get(0).steps().get(3).intersections().size();
int intersectionSize = stepIntersections + 1;

assertEquals(currentStepTotal + 1, routeStepProgress.intersections().size());
assertEquals(routeStepProgress.intersections().get(16).location().latitude(), maneuverLocation.latitude());
assertEquals(routeStepProgress.intersections().get(16).location().longitude(), maneuverLocation.longitude());
assertEquals(intersectionSize, routeStepProgress.intersections().size());
}

@Test
Expand Down

0 comments on commit a730bcf

Please sign in to comment.