From bdd3e4370d3cb334a89b6ee6c28b20003e83e9ec Mon Sep 17 00:00:00 2001 From: Tobrun Date: Mon, 3 Dec 2018 14:14:59 +0200 Subject: [android] - update unit tests to be location component compatible --- .../location/LocationLayerControllerTest.java | 73 +++++++++------------- .../com/mapbox/mapboxsdk/maps/MapboxMapTest.java | 4 +- 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java index d301c5cbd2..1323afbda7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java @@ -5,12 +5,15 @@ import android.graphics.Bitmap; import android.support.annotation.NonNull; import com.google.gson.JsonElement; import com.mapbox.geojson.Feature; +import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import org.junit.Before; import org.junit.Test; import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON; @@ -38,9 +41,16 @@ import static org.mockito.Mockito.when; public class LocationLayerControllerTest { + private MapboxMap mapboxMap = mock(MapboxMap.class); + private Style style = mock(Style.class); + + @Before + public void before() { + when(mapboxMap.getStyle()).thenReturn(style); + } + @Test public void onInitialization_locationSourceIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); GeoJsonSource locationSource = mock(GeoJsonSource.class); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); @@ -49,12 +59,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addSource(locationSource); + verify(style).addSource(locationSource); } @Test public void onInitialization_shadowLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); Layer shadowLayer = mock(Layer.class); when(sourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer); @@ -65,12 +74,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addLayerBelow(shadowLayer, BACKGROUND_LAYER); + verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER); } @Test public void onInitialization_backgroundLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); Layer backgroundLayer = mock(Layer.class); when(sourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer); @@ -81,12 +89,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addLayerBelow(backgroundLayer, FOREGROUND_LAYER); + verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER); } @Test public void onInitialization_foregroundLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); Layer foregroundLayer = mock(Layer.class); when(sourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer); @@ -97,12 +104,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addLayerBelow(foregroundLayer, BEARING_LAYER); + verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER); } @Test public void onInitialization_bearingLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); Layer bearingLayer = mock(Layer.class); when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer); @@ -115,12 +121,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addLayerBelow(bearingLayer, layerBelow); + verify(style).addLayerBelow(bearingLayer, layerBelow); } @Test public void onInitialization_accuracyLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); Layer accuracyLayer = mock(Layer.class); when(sourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer); @@ -131,12 +136,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addLayerBelow(accuracyLayer, BACKGROUND_LAYER); + verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER); } @Test public void applyStyle_styleShadowWithValidElevation() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -148,12 +152,11 @@ public class LocationLayerControllerTest { // Style is applied on initialization new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addImage(SHADOW_ICON, bitmap); + verify(style).addImage(SHADOW_ICON, bitmap); } @Test public void applyStyle_ignoreStyleShadowWithInvalidElevation() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -164,12 +167,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap, times(0)).addImage(SHADOW_ICON, bitmap); + verify(style, times(0)).addImage(SHADOW_ICON, bitmap); } @Test public void applyStyle_styleForegroundFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LocationComponentOptions options = mock(LocationComponentOptions.class); @@ -183,12 +185,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addImage(FOREGROUND_ICON, bitmap); + verify(style).addImage(FOREGROUND_ICON, bitmap); } @Test public void applyStyle_styleForegroundStaleFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LocationComponentOptions options = mock(LocationComponentOptions.class); @@ -202,12 +203,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addImage(FOREGROUND_STALE_ICON, bitmap); + verify(style).addImage(FOREGROUND_STALE_ICON, bitmap); } @Test public void applyStyle_styleBackgroundFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LocationComponentOptions options = mock(LocationComponentOptions.class); @@ -221,12 +221,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addImage(BACKGROUND_ICON, bitmap); + verify(style).addImage(BACKGROUND_ICON, bitmap); } @Test public void applyStyle_styleBackgroundStaleFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LocationComponentOptions options = mock(LocationComponentOptions.class); @@ -240,12 +239,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addImage(BACKGROUND_STALE_ICON, bitmap); + verify(style).addImage(BACKGROUND_STALE_ICON, bitmap); } @Test public void applyStyle_styleBearingFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); LocationComponentOptions options = mock(LocationComponentOptions.class); @@ -259,12 +257,11 @@ public class LocationLayerControllerTest { new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - verify(mapboxMap).addImage(BEARING_ICON, bitmap); + verify(style).addImage(BEARING_ICON, bitmap); } @Test public void updateForegroundOffset_foregroundIconPropertyIsUpdated() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); GeoJsonSource locationSource = mock(GeoJsonSource.class); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); @@ -282,7 +279,6 @@ public class LocationLayerControllerTest { @Test public void updateForegroundOffset_shadowPropertyIsUpdated() { - MapboxMap mapboxMap = mock(MapboxMap.class); LayerSourceProvider sourceProvider = buildLayerProvider(); GeoJsonSource locationSource = mock(GeoJsonSource.class); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); @@ -301,8 +297,7 @@ public class LocationLayerControllerTest { @Test public void onNewLatLngValue_locationFeatureIsUpdated() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -321,8 +316,7 @@ public class LocationLayerControllerTest { @Test public void onNewGpsBearingValue_locationFeatureIsUpdated() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -342,8 +336,7 @@ public class LocationLayerControllerTest { @Test public void onNewGpsBearingValue_updateIgnoredWithInvalidRenderMode() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -363,8 +356,7 @@ public class LocationLayerControllerTest { @Test public void onNewCompassBearingValue_locationFeatureIsUpdated() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -384,8 +376,7 @@ public class LocationLayerControllerTest { @Test public void onNewCompassBearingValue_updateIgnoredWithInvalidRenderMode() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -405,8 +396,7 @@ public class LocationLayerControllerTest { @Test public void onNewAccuracyRadiusValue_locationFeatureIsUpdated() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); @@ -425,8 +415,7 @@ public class LocationLayerControllerTest { @Test public void onNewAccuracyRadiusValue_updateIgnoredWithInvalidRenderMode() { GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); + when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); LayerSourceProvider sourceProvider = buildLayerProvider(); when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java index 007a70dadc..9dd70971b2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -24,8 +24,8 @@ public class MapboxMapTest { mock(Projection.class), mock(MapboxMap.OnGesturesManagerInteractionListener.class), mock(AnnotationManager.class), - mock(CameraChangeDispatcher.class), - mock(MapChangeReceiver.class)); + mock(CameraChangeDispatcher.class) + ); } @Test(expected = IllegalArgumentException.class) -- cgit v1.2.1