ArrowLineLayer extends KujakuLayer { @Override public boolean removeLayerOnMap(@NonNull MapboxMap mapboxMap) { setRemoved(true); Style style = mapboxMap.getStyle(); if (style != null && style.isFullyLoaded()) { style.removeLayer(arrowHeadLayer); style.removeLayer(lineLayer); style.removeSource(arrowHeadSource); style.removeSource(lineLayerSource); visible = false; return true; } else { Log.e(TAG, "Could not remove the layers & source because the the style is null or not fully loaded"); return false; } } private  ArrowLineLayer(@NonNull Builder builder); LineLayer getLineLayer(); SymbolLayer getArrowHeadLayer(); @Override void addLayerToMap(@NonNull MapboxMap mapboxMap); @Override void enableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void disableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override @NonNull String[] getLayerIds(); @Override boolean removeLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void updateFeatures(@NonNull FeatureCollection featureCollection); static Point getCenter(@NonNull Geometry featureGeometry); @Override FeatureCollection getFeatureCollection(); static final String ARROW_HEAD_BEARING; static final int MIN_ARROW_ZOOM; static final int MAX_ARROW_ZOOM; static final float MIN_ZOOM_ARROW_HEAD_SCALE; static final float MAX_ZOOM_ARROW_HEAD_SCALE; }
@Test public void removeLayerOnMapShouldReturnFalseWhenStyleIsNotReady() throws InvalidArrowLineConfigException { ArrayList<Feature> featuresList = new ArrayList<>(); FeatureCollection featureCollection = FeatureCollection.fromFeatures(featuresList); ArrowLineLayer.FeatureConfig featureConfig = new ArrowLineLayer.FeatureConfig(featureCollection); ArrowLineLayer.SortConfig sortConfig = new ArrowLineLayer.SortConfig("", ArrowLineLayer.SortConfig.SortOrder.DESC, ArrowLineLayer.SortConfig.PropertyType.NUMBER); ArrowLineLayer.Builder builder = new ArrowLineLayer.Builder(context, featureConfig, sortConfig); ArrowLineLayer arrowLineLayer = builder.build(); MapboxMap mapboxMap = Mockito.mock(MapboxMap.class); Style style = Mockito.mock(Style.class); Mockito.doReturn(false) .when(style) .isFullyLoaded(); Mockito.doReturn(style) .when(mapboxMap) .getStyle(); assertFalse(arrowLineLayer.removeLayerOnMap(mapboxMap)); }
@Test public void removeLayerOnMapShouldReturnTrueWhenStyleIsReadyAndRemoveLayersAndSources() throws InvalidArrowLineConfigException { ArrayList<Feature> featuresList = new ArrayList<>(); FeatureCollection featureCollection = FeatureCollection.fromFeatures(featuresList); ArrowLineLayer.FeatureConfig featureConfig = new ArrowLineLayer.FeatureConfig(featureCollection); ArrowLineLayer.SortConfig sortConfig = new ArrowLineLayer.SortConfig("", ArrowLineLayer.SortConfig.SortOrder.DESC, ArrowLineLayer.SortConfig.PropertyType.NUMBER); ArrowLineLayer.Builder builder = new ArrowLineLayer.Builder(context, featureConfig, sortConfig); ArrowLineLayer arrowLineLayer = builder.build(); MapboxMap mapboxMap = Mockito.mock(MapboxMap.class); Style style = Mockito.mock(Style.class); SymbolLayer arrowHeadLayer = Mockito.mock(SymbolLayer.class); LineLayer lineLayer = Mockito.mock(LineLayer.class); GeoJsonSource arrowHeadSource = new GeoJsonSource("some-id"); GeoJsonSource lineLayerSource = new GeoJsonSource("some-id-2"); Mockito.doReturn(true) .when(style) .isFullyLoaded(); Mockito.doReturn(style) .when(mapboxMap) .getStyle(); ReflectionHelpers.setField(arrowLineLayer, "arrowHeadLayer", arrowHeadLayer); ReflectionHelpers.setField(arrowLineLayer, "lineLayer", lineLayer); ReflectionHelpers.setField(arrowLineLayer, "arrowHeadSource", arrowHeadSource); ReflectionHelpers.setField(arrowLineLayer, "lineLayerSource", lineLayerSource); assertTrue(arrowLineLayer.removeLayerOnMap(mapboxMap)); Mockito.verify(style, Mockito.times(1)) .removeLayer(ArgumentMatchers.eq(arrowHeadLayer)); Mockito.verify(style, Mockito.times(1)) .removeLayer(ArgumentMatchers.eq(lineLayer)); Mockito.verify(style, Mockito.times(1)) .removeSource(ArgumentMatchers.eq(arrowHeadSource)); Mockito.verify(style, Mockito.times(1)) .removeSource(ArgumentMatchers.eq(lineLayerSource)); }