From b48a348d1ef5e179fb4bbc4f5f74c370c2f17c6e Mon Sep 17 00:00:00 2001 From: Dan Nesfeder Date: Fri, 15 Jun 2018 13:12:16 -0400 Subject: [PATCH] Check for valid name property value in MapWayname (#1031) --- .../navigation/ui/v5/map/MapWayname.java | 25 +++++++++++++------ .../navigation/ui/v5/map/MapWaynameTest.java | 16 ++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/MapWayname.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/MapWayname.java index 2e4afe2dce0..40533c3690e 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/MapWayname.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/MapWayname.java @@ -70,14 +70,10 @@ private List findRoadLabelFeatures(PointF point) { } private void updateLayerWithRoadLabelFeatures(List roads, SymbolLayer waynameLayer) { - if (!roads.isEmpty()) { - String currentWayname = roads.get(FIRST_ROAD_FEATURE).getStringProperty(NAME_PROPERTY); - boolean newWayname = !wayname.contentEquals(currentWayname); - if (newWayname) { - wayname = currentWayname; - updateWaynameVisibility(true, waynameLayer); - updateWaynameLayer(wayname, waynameLayer); - } + boolean isValidFeatureList = !roads.isEmpty(); + if (isValidFeatureList) { + Feature roadFeature = roads.get(FIRST_ROAD_FEATURE); + updateWaynameLayerWithNameProperty(waynameLayer, roadFeature); } else { updateWaynameVisibility(false, waynameLayer); } @@ -109,6 +105,19 @@ private void adjustWaynameVisibility(boolean isVisible, Layer waynameLayer) { } } + private void updateWaynameLayerWithNameProperty(SymbolLayer waynameLayer, Feature roadFeature) { + boolean hasValidNameProperty = roadFeature.hasNonNullValueForProperty(NAME_PROPERTY); + if (hasValidNameProperty) { + String currentWayname = roadFeature.getStringProperty(NAME_PROPERTY); + boolean newWayname = !wayname.contentEquals(currentWayname); + if (newWayname) { + wayname = currentWayname; + updateWaynameVisibility(true, waynameLayer); + updateWaynameLayer(wayname, waynameLayer); + } + } + } + private void adjustMapPadding(boolean isVisible) { if (isVisible) { paddingAdjustor.updateTopPaddingWithWayname(); diff --git a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/map/MapWaynameTest.java b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/map/MapWaynameTest.java index ec3fa2d06eb..479137f6928 100644 --- a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/map/MapWaynameTest.java +++ b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/map/MapWaynameTest.java @@ -63,6 +63,7 @@ public void onRoadsReturnedFromQuery_visibilityIsSetToTrueAndLayoutIconAdded() { SymbolLayer waynameLayer = mock(SymbolLayer.class); List roads = new ArrayList<>(); Feature road = mock(Feature.class); + when(road.hasNonNullValueForProperty("name")).thenReturn(true); when(road.getStringProperty("name")).thenReturn(roadName); roads.add(road); MapWayname mapWayname = buildMapWayname(point, waynameLayer, roads); @@ -72,6 +73,20 @@ public void onRoadsReturnedFromQuery_visibilityIsSetToTrueAndLayoutIconAdded() { verify(waynameLayer, times(1)).setProperties(any(PropertyValue.class)); } + @Test + public void onFeatureWithoutNamePropertyReturned_updateIsIgnored() { + PointF point = mock(PointF.class); + SymbolLayer waynameLayer = mock(SymbolLayer.class); + List roads = new ArrayList<>(); + Feature road = mock(Feature.class); + roads.add(road); + MapWayname mapWayname = buildMapWayname(point, waynameLayer, roads); + + mapWayname.updateWaynameWithPoint(point, waynameLayer); + + verify(waynameLayer, times(0)).setProperties(any(PropertyValue.class)); + } + @Test public void onVisibiltySetToFalse_paddingIsAdjusted() { SymbolLayer waynameLayer = mock(SymbolLayer.class); @@ -107,6 +122,7 @@ public void onRoadsReturnedFromQuery_layoutProviderGeneratesBitmap() { SymbolLayer waynameLayer = mock(SymbolLayer.class); List roads = new ArrayList<>(); Feature road = mock(Feature.class); + when(road.hasNonNullValueForProperty("name")).thenReturn(true); when(road.getStringProperty("name")).thenReturn(roadName); roads.add(road); WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class);