Skip to content
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

Add check to avoid ArrayIndexOutOfBoundsExceptions from MapRouteLine#drawWayPoints #1951

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone.

### v0.39.0 - May 29, 2019

* Add check to avoid ArrayIndexOutOfBoundsExceptions from MapRouteLine#drawWayPoints [#1951](https://github.com/mapbox/mapbox-navigation-android/pull/1951)
* Fix way name truncating too soon [#1947](https://github.com/mapbox/mapbox-navigation-android/pull/1947)
* Fix instruction icon mismatch in between banner and notification [#1946](https://github.com/mapbox/mapbox-navigation-android/pull/1946)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void findClickedRoute(@NonNull LatLng point, HashMap<LineString, Directi
}

private void calculateClickDistances(HashMap<Double, DirectionsRoute> routeDistancesAwayFromClick,
Point clickPoint, HashMap<LineString, DirectionsRoute> routeLineStrings) {
Point clickPoint, HashMap<LineString, DirectionsRoute> routeLineStrings) {
for (LineString lineString : routeLineStrings.keySet()) {
Point pointOnLine = findPointOnLine(clickPoint, lineString);
if (pointOnLine == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ List<DirectionsRoute> retrieveDirectionsRoutes() {

boolean updatePrimaryRouteIndex(int primaryRouteIndex) {
boolean isNewIndex = this.primaryRouteIndex != primaryRouteIndex
&& primaryRouteIndex < directionsRoutes.size();
&& primaryRouteIndex < directionsRoutes.size() && primaryRouteIndex >= 0;
if (isNewIndex) {
this.primaryRouteIndex = primaryRouteIndex;
updateRoutesFor(primaryRouteIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import edu.emory.mathcs.backport.java.util.Collections;

import static com.mapbox.services.android.navigation.ui.v5.route.RouteConstants.ROUTE_LAYER_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
Expand Down Expand Up @@ -110,6 +113,44 @@ public void updatePrimaryIndex_routeLineSourceIsSet() throws IOException {
verify(routeLineSource, times(4)).setGeoJson(any(FeatureCollection.class));
}

@Test
public void updatePrimaryIndex_newPrimaryRouteIndexUpdated() throws IOException {
GeoJsonSource mockedRouteLineSource = mock(GeoJsonSource.class);
GeoJsonSource mockedWayPointSource = mock(GeoJsonSource.class);
List<Layer> anyRouteLayers = buildMockLayers();
List<DirectionsRoute> routes = new ArrayList<>();
routes.add(buildTestDirectionsRoute());
routes.add(buildTestDirectionsRoute());
routes.add(buildTestDirectionsRoute());
routes.add(buildTestDirectionsRoute());
MapRouteLine routeLine = new MapRouteLine(mockedRouteLineSource, mockedWayPointSource, anyRouteLayers);
routeLine.draw(routes);

boolean isNewIndex = routeLine.updatePrimaryRouteIndex(3);

assertTrue(isNewIndex);
assertEquals(3, routeLine.retrievePrimaryRouteIndex());
}

@Test
public void updatePrimaryIndex_newPrimaryRouteIndexIsNotUpdated() throws IOException {
GeoJsonSource mockedRouteLineSource = mock(GeoJsonSource.class);
GeoJsonSource mockedWayPointSource = mock(GeoJsonSource.class);
List<Layer> anyRouteLayers = buildMockLayers();
List<DirectionsRoute> routes = new ArrayList<>();
routes.add(buildTestDirectionsRoute());
routes.add(buildTestDirectionsRoute());
routes.add(buildTestDirectionsRoute());
routes.add(buildTestDirectionsRoute());
MapRouteLine routeLine = new MapRouteLine(mockedRouteLineSource, mockedWayPointSource, anyRouteLayers);
routeLine.draw(routes);

boolean isNewIndex = routeLine.updatePrimaryRouteIndex(-1);

assertFalse(isNewIndex);
assertEquals(0, routeLine.retrievePrimaryRouteIndex());
}

@Test
public void routeLineCap_defaultIsSet() {
Context context = mock(Context.class);
Expand Down