Skip to content

Commit

Permalink
Check for valid name property value in MapWayname (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder authored Jun 15, 2018
1 parent 4b35273 commit b48a348
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,10 @@ private List<Feature> findRoadLabelFeatures(PointF point) {
}

private void updateLayerWithRoadLabelFeatures(List<Feature> 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);
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void onRoadsReturnedFromQuery_visibilityIsSetToTrueAndLayoutIconAdded() {
SymbolLayer waynameLayer = mock(SymbolLayer.class);
List<Feature> 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);
Expand All @@ -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<Feature> 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);
Expand Down Expand Up @@ -107,6 +122,7 @@ public void onRoadsReturnedFromQuery_layoutProviderGeneratesBitmap() {
SymbolLayer waynameLayer = mock(SymbolLayer.class);
List<Feature> 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);
Expand Down

0 comments on commit b48a348

Please sign in to comment.