-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for null camera engine before returning from MapboxNavigation #866
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ | |
import com.mapbox.services.android.navigation.v5.BaseTest; | ||
import com.mapbox.services.android.navigation.v5.milestone.Milestone; | ||
import com.mapbox.services.android.navigation.v5.milestone.StepMilestone; | ||
import com.mapbox.services.android.navigation.v5.navigation.camera.SimpleCamera; | ||
import com.mapbox.services.android.navigation.v5.offroute.OffRoute; | ||
import com.mapbox.services.android.navigation.v5.offroute.OffRouteDetector; | ||
import com.mapbox.services.android.navigation.v5.snap.Snap; | ||
import com.mapbox.services.android.navigation.v5.snap.SnapToRoute; | ||
import com.mapbox.services.android.telemetry.location.LocationEngine; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.BANNER_INSTRUCTION_MILESTONE_ID; | ||
|
@@ -28,199 +28,257 @@ | |
|
||
public class MapboxNavigationTest extends BaseTest { | ||
|
||
private MapboxNavigation navigation; | ||
@Test | ||
public void sanityTest() { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
@Before | ||
public void before() throws Exception { | ||
navigation = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
assertNotNull(navigation); | ||
} | ||
|
||
@Test | ||
public void sanityTest() { | ||
assertNotNull("should not be null", navigation); | ||
public void sanityTestWithOptions() { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
assertNotNull("should not be null", navigationWithOptions); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertNotNull(navigationWithOptions); | ||
} | ||
|
||
@Test | ||
public void voiceMilestone_onInitializationDoesGetAdded() throws Exception { | ||
assertTrue(navigation.getMilestones().get(0).getIdentifier() == VOICE_INSTRUCTION_MILESTONE_ID); | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
int identifier = navigation.getMilestones().get(0).getIdentifier(); | ||
|
||
assertEquals(identifier, VOICE_INSTRUCTION_MILESTONE_ID); | ||
} | ||
|
||
@Test | ||
public void bannerMilestone_onInitializationDoesGetAdded() throws Exception { | ||
assertTrue(navigation.getMilestones().get(1).getIdentifier() == BANNER_INSTRUCTION_MILESTONE_ID); | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
int identifier = navigation.getMilestones().get(1).getIdentifier(); | ||
|
||
assertEquals(identifier, BANNER_INSTRUCTION_MILESTONE_ID); | ||
} | ||
|
||
|
||
@Test | ||
public void defaultMilestones_onInitializationDoNotGetAdded() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertEquals(0, navigationWithOptions.getMilestones().size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 #866 (comment) |
||
} | ||
|
||
@Test | ||
public void defaultEngines_didGetInitialized() throws Exception { | ||
assertNotNull(navigation.getSnapEngine()); | ||
public void defaultEngines_offRouteEngineDidGetInitialized() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
assertNotNull(navigation.getOffRouteEngine()); | ||
} | ||
|
||
@Test | ||
public void defaultEngines_snapEngineDidGetInitialized() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
assertNotNull(navigation.getSnapEngine()); | ||
} | ||
|
||
@Test | ||
public void offRouteEngine_doesNotGetInitializedWithFalseOption() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder() | ||
.enableOffRouteDetection(false) | ||
.build(); | ||
navigation = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
assertNull(navigation.getOffRouteEngine()); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertNull(navigationWithOptions.getOffRouteEngine()); | ||
} | ||
|
||
@Test | ||
public void snapToRouteEngine_doesNotGetInitializedWithFalseOption() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder() | ||
.snapToRoute(false) | ||
.build(); | ||
navigation = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
assertNull(navigation.getSnapEngine()); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertNull(navigationWithOptions.getSnapEngine()); | ||
} | ||
|
||
@Test | ||
public void fasterRouteEngine_doesNotGetInitializedWithFalseOption() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder() | ||
.enableFasterRouteDetection(false) | ||
.build(); | ||
navigation = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
assertNull(navigation.getFasterRouteEngine()); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertNull(navigationWithOptions.getFasterRouteEngine()); | ||
} | ||
|
||
@Test | ||
public void addMilestone_milestoneDidGetAdded() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
Milestone milestone = new StepMilestone.Builder().build(); | ||
|
||
navigation.addMilestone(milestone); | ||
|
||
assertTrue(navigation.getMilestones().contains(milestone)); | ||
} | ||
|
||
@Test | ||
public void addMilestone_milestoneOnlyGetsAddedOnce() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
navigationWithOptions.addMilestone(milestone); | ||
navigationWithOptions.addMilestone(milestone); | ||
|
||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void removeMilestone_milestoneDidGetRemoved() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should be in the |
||
navigationWithOptions.addMilestone(milestone); | ||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
navigationWithOptions.removeMilestone(milestone); | ||
|
||
assertEquals(0, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void removeMilestone_milestoneDoesNotExist() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should be in the |
||
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
navigationWithOptions.removeMilestone(milestone); | ||
|
||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void removeMilestone_nullRemovesAllMilestones() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could extract this block of code into a |
||
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
assertEquals(4, navigationWithOptions.getMilestones().size()); | ||
|
||
navigationWithOptions.removeMilestone(null); | ||
|
||
assertEquals(0, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void removeMilestone_correctMilestoneWithIdentifierGetsRemoved() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
Milestone milestone = new StepMilestone.Builder().setIdentifier(5678).build(); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
int removedMilestoneIdentifier = 5678; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO |
||
Milestone milestone = new StepMilestone.Builder().setIdentifier(removedMilestoneIdentifier).build(); | ||
navigationWithOptions.addMilestone(milestone); | ||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
navigationWithOptions.removeMilestone(5678); | ||
|
||
navigationWithOptions.removeMilestone(removedMilestoneIdentifier); | ||
|
||
assertEquals(0, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void removeMilestone_noMilestoneWithIdentifierFound() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could take advantage of the naming here to understand clearer what's going on. Like naming |
||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
navigationWithOptions.removeMilestone(5678); | ||
int removedMilestoneIdentifier = 5678; | ||
|
||
navigationWithOptions.removeMilestone(removedMilestoneIdentifier); | ||
|
||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void getLocationEngine_returnsCorrectLocationEngine() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
LocationEngine locationEngine = mock(LocationEngine.class); | ||
LocationEngine locationEngine2 = mock(LocationEngine.class); | ||
LocationEngine locationEngineInstanceNotUsed = mock(LocationEngine.class); | ||
|
||
navigation.setLocationEngine(locationEngine); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be in the |
||
assertNotSame(locationEngine2, navigation.getLocationEngine()); | ||
|
||
assertNotSame(locationEngineInstanceNotUsed, navigation.getLocationEngine()); | ||
assertEquals(locationEngine, navigation.getLocationEngine()); | ||
} | ||
|
||
@Test | ||
public void endNavigation_doesSendFalseToNavigationEvent() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
NavigationEventListener navigationEventListener = mock(NavigationEventListener.class); | ||
|
||
navigation.addNavigationEventListener(navigationEventListener); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here ☝️ |
||
navigation.startNavigation(mock(DirectionsRoute.class)); | ||
navigation.endNavigation(); | ||
|
||
verify(navigationEventListener, times(1)).onRunning(false); | ||
} | ||
|
||
@Test | ||
public void startNavigation_doesSendTrueToNavigationEvent() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
NavigationEventListener navigationEventListener = mock(NavigationEventListener.class); | ||
|
||
navigation.addNavigationEventListener(navigationEventListener); | ||
navigation.startNavigation(mock(DirectionsRoute.class)); | ||
|
||
verify(navigationEventListener, times(1)).onRunning(true); | ||
} | ||
|
||
@Test | ||
public void setSnapEngine_doesReplaceDefaultEngine() throws Exception { | ||
Snap snap = navigation.getSnapEngine(); | ||
assertTrue(snap instanceof SnapToRoute); | ||
snap = mock(Snap.class); | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
Snap snap = mock(Snap.class); | ||
navigation.setSnapEngine(snap); | ||
|
||
assertTrue(!(navigation.getSnapEngine() instanceof SnapToRoute)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using |
||
assertTrue(navigation.getSnapEngine() instanceof Snap); | ||
} | ||
|
||
@Test | ||
public void setOffRouteEngine_doesReplaceDefaultEngine() throws Exception { | ||
OffRoute offRoute = navigation.getOffRouteEngine(); | ||
assertTrue(offRoute instanceof OffRouteDetector); | ||
offRoute = mock(OffRoute.class); | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
OffRoute offRoute = mock(OffRoute.class); | ||
navigation.setOffRouteEngine(offRoute); | ||
|
||
assertTrue(!(navigation.getOffRouteEngine() instanceof OffRouteDetector)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here ☝️ |
||
assertTrue(navigation.getOffRouteEngine() instanceof OffRoute); | ||
} | ||
|
||
@Test | ||
public void getCameraEngine_returnsNonNullEngine() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
navigation.setOffRouteEngine(null); | ||
|
||
assertNotNull(navigation.getCameraEngine()); | ||
} | ||
|
||
@Test | ||
public void getCameraEngine_returnsSimpleCameraWhenNull() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
navigation.setOffRouteEngine(null); | ||
|
||
assertTrue(navigation.getCameraEngine() instanceof SimpleCamera); | ||
} | ||
|
||
private MapboxNavigation buildMapboxNavigation() { | ||
return new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
} | ||
|
||
private MapboxNavigation buildMapboxNavigationWithOptions(MapboxNavigationOptions options) { | ||
return new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the other way around, "expected" value 👉
VOICE_INSTRUCTION_MILESTONE_ID
which would be better represented using the literal value instead of using the constant (👀 Expect Literals), "actual" value 👉identifier
.The same thing happens in
bannerMilestone_onInitializationDoesGetAdded
test 👇