summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt14
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java66
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt31
3 files changed, 82 insertions, 29 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
index 853760f6df..b0bea5aa0e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
@@ -9,6 +9,7 @@ import com.mapbox.android.core.location.LocationEngineRequest
import com.mapbox.mapboxsdk.R
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
+import io.mockk.mockk
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@@ -75,8 +76,7 @@ class LocationComponentTest {
@Test
fun activateWithRequestTest() {
- locationComponent.activateLocationComponent(context, locationEngine, locationEngineRequest, locationComponentOptions)
- verify(mapboxMap).getStyle(ArgumentMatchers.any(Style.OnStyleLoaded::class.java))
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
@@ -90,13 +90,13 @@ class LocationComponentTest {
.getDimension(R.dimen.mapbox_locationComponentTrackingMultiFingerMoveThreshold)
doReturn(0f).`when`(resources)
.getDimension(R.dimen.mapbox_locationComponentTrackingMultiFingerMoveThreshold)
- locationComponent.activateLocationComponent(context, true, locationEngineRequest)
+ locationComponent.activateLocationComponent(context, mockk(),true, locationEngineRequest)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
}
@Test
fun locationUpdatesWhenEnabledDisableTest() {
- locationComponent.activateLocationComponent(context, locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
verify(locationEngine, times(0)).removeLocationUpdates(currentListener)
verify(locationEngine, times(0)).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
@@ -114,7 +114,7 @@ class LocationComponentTest {
@Test
fun locationUpdatesWhenStartedStoppedTest() {
- locationComponent.activateLocationComponent(context, locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
@@ -127,7 +127,7 @@ class LocationComponentTest {
@Test
fun locationUpdatesWhenNewRequestTest() {
- locationComponent.activateLocationComponent(context, locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
@@ -139,7 +139,7 @@ class LocationComponentTest {
@Test
fun lastLocationUpdateOnStartTest() {
- locationComponent.activateLocationComponent(context, locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
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 475fb81684..68e31275f1 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
@@ -56,7 +56,8 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addSource(locationSource);
}
@@ -71,7 +72,8 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER);
}
@@ -86,7 +88,8 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER);
}
@@ -101,7 +104,8 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER);
}
@@ -118,7 +122,8 @@ public class LocationLayerControllerTest {
String layerBelow = "layer-below";
when(options.layerBelow()).thenReturn(layerBelow);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addLayerBelow(bearingLayer, layerBelow);
}
@@ -133,7 +138,8 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER);
}
@@ -149,7 +155,8 @@ public class LocationLayerControllerTest {
when(options.elevation()).thenReturn(2f);
// Style is applied on initialization
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addImage(SHADOW_ICON, bitmap);
}
@@ -164,7 +171,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
when(options.elevation()).thenReturn(0f);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style, times(0)).addImage(SHADOW_ICON, bitmap);
}
@@ -182,7 +190,8 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addImage(FOREGROUND_ICON, bitmap);
}
@@ -200,7 +209,8 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addImage(FOREGROUND_STALE_ICON, bitmap);
}
@@ -218,7 +228,8 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addImage(BACKGROUND_ICON, bitmap);
}
@@ -236,7 +247,8 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addImage(BACKGROUND_STALE_ICON, bitmap);
}
@@ -254,7 +266,8 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
+ new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
+ bitmapProvider, options);
verify(style).addImage(BEARING_ICON, bitmap);
}
@@ -268,7 +281,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.updateForegroundOffset(2d);
@@ -285,7 +299,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.updateForegroundOffset(2d);
@@ -302,7 +317,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.onNewLatLngValue(new LatLng());
@@ -320,7 +336,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.setRenderMode(RenderMode.GPS);
float gpsBearing = 2f;
@@ -340,7 +357,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.setRenderMode(RenderMode.COMPASS);
float gpsBearing = 2f;
@@ -360,7 +378,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.setRenderMode(RenderMode.COMPASS);
float compassBearing = 2f;
@@ -380,7 +399,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.setRenderMode(RenderMode.GPS);
float compassBearing = 2f;
@@ -400,7 +420,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
float accuracyRadiusValue = 2f;
@@ -419,7 +440,8 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
Feature locationFeature = mock(Feature.class);
LocationLayerController layer = new LocationLayerController(
- mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
+ mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
+ bitmapProvider, options
);
layer.setRenderMode(RenderMode.GPS);
float accuracyRadiusValue = 2f;
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
index 0c9abc82ba..4b2f3e287e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
@@ -9,6 +9,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
+import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -273,4 +274,34 @@ class StyleTest {
verify(exactly = 1) { nativeMapView.addSource(source) }
verify(exactly = 1) { callback.onStyleLoaded(any()) }
}
+
+ @Test
+ fun testGetNullStyle() {
+ Assert.assertNull(mapboxMap.style)
+ }
+
+ @Test
+ fun testGetNullWhileLoading() {
+ val transitionOptions = TransitionOptions(100, 200)
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions)
+ mapboxMap.setStyle(builder)
+ Assert.assertNull(mapboxMap.style)
+ mapboxMap.notifyStyleLoaded()
+ Assert.assertNotNull(mapboxMap.style)
+ }
+
+ @Test
+ fun testNotReinvokeSameListener() {
+ val callback = mockk<Style.OnStyleLoaded>()
+ every { callback.onStyleLoaded(any()) } answers {}
+ mapboxMap.getStyle(callback)
+ val source = mockk<GeoJsonSource>()
+ every { source.id } returns "1"
+ val builder = Style.Builder().fromJson("{}")
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleJson = "{}" }
+ mapboxMap.notifyStyleLoaded()
+ mapboxMap.setStyle(Style.MAPBOX_STREETS)
+ verify(exactly = 1) { callback.onStyleLoaded(any()) }
+ }
} \ No newline at end of file