summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt106
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt275
3 files changed, 382 insertions, 1 deletions
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 9dd70971b2..8b01b02c82 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
@@ -23,9 +23,9 @@ public class MapboxMapTest {
mock(UiSettings.class),
mock(Projection.class),
mock(MapboxMap.OnGesturesManagerInteractionListener.class),
- mock(AnnotationManager.class),
mock(CameraChangeDispatcher.class)
);
+ mapboxMap.injectAnnotationManager(mock(AnnotationManager.class));
}
@Test(expected = IllegalArgumentException.class)
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt
new file mode 100644
index 0000000000..cb42b0b33d
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt
@@ -0,0 +1,106 @@
+package com.mapbox.mapboxsdk.maps
+
+import android.graphics.Bitmap
+import com.mapbox.mapboxsdk.style.layers.SymbolLayer
+import com.mapbox.mapboxsdk.style.layers.TransitionOptions
+import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
+import io.mockk.mockk
+import org.junit.Assert.assertEquals
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+
+@RunWith(RobolectricTestRunner::class)
+class StyleBuilderTest {
+
+ @Test
+ fun testFromUrl() {
+ val expected = Style.MAPBOX_STREETS
+ val builder = Style.Builder()
+ builder.fromUrl(expected)
+ assertEquals(expected, builder.url)
+ }
+
+ @Test
+ fun testFromJson() {
+ val expected = "{}"
+ val builder = Style.Builder()
+ builder.fromJson(expected)
+ assertEquals(expected, builder.json)
+ }
+
+ @Test
+ fun testWithLayer() {
+ val layer = mockk<SymbolLayer>()
+ val builder = Style.Builder()
+ builder.withLayer(layer)
+ assertEquals(layer, builder.layers[0].layer)
+ }
+
+ @Test
+ fun testWithLayerAt() {
+ val expectedIndex = 5
+ val layer = mockk<SymbolLayer>()
+ val builder = Style.Builder()
+ builder.withLayerAt(layer, expectedIndex)
+ assertEquals(layer, builder.layers[0].layer)
+ assertEquals(expectedIndex, (builder.layers[0] as Style.Builder.LayerAtWrapper).index)
+ }
+
+ @Test
+ fun testWithLayerAbove() {
+ val expectedAbove = "above"
+ val layer = mockk<SymbolLayer>()
+ val builder = Style.Builder()
+ builder.withLayerAbove(layer, expectedAbove)
+ assertEquals(layer, builder.layers[0].layer)
+ assertEquals(expectedAbove, (builder.layers[0] as Style.Builder.LayerAboveWrapper).aboveLayer)
+ }
+
+ @Test
+ fun testWithLayerBelow() {
+ val expectedBelow = "above"
+ val layer = mockk<SymbolLayer>()
+ val builder = Style.Builder()
+ builder.withLayerBelow(layer, expectedBelow)
+ assertEquals(layer, builder.layers[0].layer)
+ assertEquals(expectedBelow, (builder.layers[0] as Style.Builder.LayerBelowWrapper).belowLayer)
+ }
+
+ @Test
+ fun testWithSource() {
+ val source = mockk<GeoJsonSource>()
+ val builder = Style.Builder()
+ builder.withSource(source)
+ assertEquals(source, builder.sources[0])
+ }
+
+ @Test
+ fun testWithImage() {
+ val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
+ val builder = Style.Builder()
+ builder.withImage("id", bitmap)
+ assertEquals(bitmap, builder.images[0].bitmap)
+ assertEquals("id", builder.images[0].id)
+ assertEquals(false, builder.images[0].sdf)
+ }
+
+ @Test
+ fun testWithImageSdf() {
+ val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
+ val builder = Style.Builder()
+ builder.withImage("id", bitmap, true)
+ assertEquals(bitmap, builder.images[0].bitmap)
+ assertEquals("id", builder.images[0].id)
+ assertEquals(true, builder.images[0].sdf)
+ }
+
+ @Test
+ fun testWithTransitionOptions() {
+ val transitionOptions = TransitionOptions(100, 200)
+ val builder = Style.Builder()
+ builder.withTransition(transitionOptions)
+ assertEquals(100, builder.transitionOptions.duration)
+ assertEquals(200, builder.transitionOptions.delay)
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000000..5af17985a4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
@@ -0,0 +1,275 @@
+package com.mapbox.mapboxsdk.maps
+
+import android.graphics.Bitmap
+import com.mapbox.mapboxsdk.constants.MapboxConstants
+import com.mapbox.mapboxsdk.style.layers.SymbolLayer
+import com.mapbox.mapboxsdk.style.layers.TransitionOptions
+import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.spyk
+import io.mockk.verify
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+
+@RunWith(RobolectricTestRunner::class)
+class StyleTest {
+
+ private lateinit var mapboxMap: MapboxMap
+
+ private lateinit var nativeMapView: NativeMapView
+
+ @Before
+ fun setup() {
+ nativeMapView = mockk()
+ mapboxMap = MapboxMap(nativeMapView, null, null, null, null, null)
+ every { nativeMapView.styleUrl = any() } answers {}
+ every { nativeMapView.styleJson = any() } answers {}
+ every { nativeMapView.addLayerBelow(any(), any()) } answers {}
+ every { nativeMapView.addLayerAbove(any(), any()) } answers {}
+ every { nativeMapView.addLayerAt(any(), any()) } answers {}
+ every { nativeMapView.addSource(any()) } answers {}
+ every { nativeMapView.addImage(any(), any(), any()) } answers {}
+ every { nativeMapView.transitionDuration = any() } answers {}
+ every { nativeMapView.transitionDelay = any() } answers {}
+ mapboxMap.injectLocationComponent(spyk())
+ }
+
+ @Test
+ fun testFromUrl() {
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ }
+
+ @Test
+ fun testFromJson() {
+ val builder = Style.Builder().fromJson("{}")
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleJson = "{}" }
+ }
+
+ @Test
+ fun testWithLayer() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().withLayer(layer)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
+ }
+
+ @Test
+ fun testWithLayerAbove() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().withLayerAbove(layer, "id")
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addLayerAbove(layer, "id") }
+ }
+
+ @Test
+ fun testWithLayerBelow() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().withLayerBelow(layer, "id")
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "id") }
+ }
+
+ @Test
+ fun testWithLayerAt() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().withLayerAt(layer, 1)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) }
+ }
+
+ @Test
+ fun testWithSource() {
+ val source = mockk<GeoJsonSource>()
+ every { source.id } returns "1"
+ val builder = Style.Builder().withSource(source)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addSource(source) }
+ }
+
+ @Test
+ fun testWithTransitionOptions() {
+ val transitionOptions = TransitionOptions(100, 200)
+ val builder = Style.Builder().withTransition(transitionOptions)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.transitionDuration = 100 }
+ verify(exactly = 1) { nativeMapView.transitionDelay = 200 }
+ }
+
+ @Test
+ fun testWithImage() {
+ val image = mockk<Bitmap>()
+ val builder = Style.Builder().withImage("id", image)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addImage("id", image, false) }
+ }
+
+ @Test
+ fun testWithImageSdf() {
+ val image = mockk<Bitmap>()
+ val builder = Style.Builder().withImage("id", image, true)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addImage("id", image, true) }
+ }
+
+ @Test
+ fun testWithFromLoadingSource() {
+ val source = mockk<GeoJsonSource>()
+ every { source.id } returns "1"
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addSource(source) }
+ }
+
+ @Test
+ fun testWithFromLoadingLayer() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayer(layer)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
+ }
+
+ @Test
+ fun testWithFromLoadingLayerAt() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerAt(layer, 1)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) }
+ }
+
+ @Test
+ fun testWithFromLoadingLayerBelow() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below")
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") }
+ }
+
+ @Test
+ fun testWithFromLoadingLayerAbove() {
+ val layer = mockk<SymbolLayer>()
+ every { layer.id } returns "1"
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below")
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") }
+ }
+
+ @Test
+ fun testWithFromLoadingTransitionOptions() {
+ val transitionOptions = TransitionOptions(100, 200)
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.transitionDuration = 100 }
+ verify(exactly = 1) { nativeMapView.transitionDelay = 200 }
+ }
+
+ @Test
+ fun testWithFromImage() {
+ val bitmap = mockk<Bitmap>()
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withImage("id", bitmap)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addImage("id", bitmap, false) }
+ }
+
+ @Test
+ fun testWithFromImageSdf() {
+ val bitmap = mockk<Bitmap>()
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withImage("id", bitmap, true)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addImage("id", bitmap, true) }
+ }
+
+ @Test
+ fun testFromCallback() {
+ val callback = mockk<Style.OnStyleLoaded>()
+ every { callback.onStyleLoaded(any()) } answers {}
+ val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
+ mapboxMap.setStyle(builder, callback)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { callback.onStyleLoaded(any()) }
+ }
+
+ @Test
+ fun testWithCallback() {
+ val callback = mockk<Style.OnStyleLoaded>()
+ every { callback.onStyleLoaded(any()) } answers {}
+ val source = mockk<GeoJsonSource>()
+ every { source.id } returns "1"
+ val builder = Style.Builder().withSource(source)
+ mapboxMap.setStyle(builder, callback)
+ verify(exactly = 1) { nativeMapView.addSource(source) }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { callback.onStyleLoaded(any()) }
+ }
+
+ @Test
+ fun testGetAsyncWith() {
+ 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().withSource(source)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.addSource(source) }
+ verify(exactly = 1) { callback.onStyleLoaded(any()) }
+ }
+
+ @Test
+ fun testGetAsyncFrom() {
+ 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()
+ verify(exactly = 1) { callback.onStyleLoaded(any()) }
+ }
+
+ @Test
+ fun testGetAsyncWithFrom() {
+ 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().fromUrl(Style.MAPBOX_STREETS).withSource(source)
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
+ mapboxMap.notifyStyleLoaded()
+ verify(exactly = 1) { nativeMapView.addSource(source) }
+ verify(exactly = 1) { callback.onStyleLoaded(any()) }
+ }
+} \ No newline at end of file