From 5a1b4243e559fc7d74a5a140fe723c770086992d Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 6 Dec 2018 17:21:33 +0200 Subject: [android] - add unit tests for Style.java API --- platform/android/MapboxGLAndroidSDK/build.gradle | 1 + .../mapboxsdk/location/LocationComponent.java | 6 + .../java/com/mapbox/mapboxsdk/maps/MapView.java | 14 +- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 22 +- .../main/java/com/mapbox/mapboxsdk/maps/Style.java | 55 +++-- .../com/mapbox/mapboxsdk/maps/MapboxMapTest.java | 2 +- .../com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt | 106 ++++++++ .../java/com/mapbox/mapboxsdk/maps/StyleTest.kt | 275 +++++++++++++++++++++ platform/android/gradle/dependencies.gradle | 2 + platform/android/scripts/exclude-activity-gen.json | 4 +- 10 files changed, 440 insertions(+), 47 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt create mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index ddb2949bbc..2c97965866 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -14,6 +14,7 @@ dependencies { implementation dependenciesList.okhttp3 testImplementation dependenciesList.junit testImplementation dependenciesList.mockito + testImplementation dependenciesList.mockk testImplementation dependenciesList.robolectric testImplementation dependenciesList.kotlinLib } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index b361de847b..37433076b0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -164,6 +164,12 @@ public final class LocationComponent { this.mapboxMap = mapboxMap; } + // used for creating a spy + LocationComponent() { + //noinspection ConstantConditions + mapboxMap = null; + } + @VisibleForTesting LocationComponent(@NonNull MapboxMap mapboxMap, @NonNull LocationEngineCallback currentlistener, diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 1883e539f3..558ea56a0d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -147,7 +147,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { GesturesManagerInteractionListener registerTouchListener = new GesturesManagerInteractionListener(); // callback for camera change events - final CameraChangeDispatcher cameraChangeDispatcher = new CameraChangeDispatcher(); + final CameraChangeDispatcher cameraDispatcher = new CameraChangeDispatcher(); // setup components for MapboxMap creation Projection proj = new Projection(nativeMapView); @@ -161,20 +161,20 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray); AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, iconManager, annotations, markers, polygons, polylines, shapeAnnotations); - Transform transform = new Transform(this, nativeMapView, cameraChangeDispatcher); + Transform transform = new Transform(this, nativeMapView, cameraDispatcher); // MapboxMap - mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, - annotationManager, cameraChangeDispatcher); + mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, cameraDispatcher); + mapboxMap.injectAnnotationManager(annotationManager); // user input mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, - annotationManager, cameraChangeDispatcher); + annotationManager, cameraDispatcher); mapKeyListener = new MapKeyListener(transform, uiSettings, mapGestureDetector); // compass - compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraChangeDispatcher)); - compassView.setOnClickListener(createCompassClickListener(cameraChangeDispatcher)); + compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraDispatcher)); + compassView.setOnClickListener(createCompassClickListener(cameraDispatcher)); // LocationComponent mapboxMap.injectLocationComponent(new LocationComponent(mapboxMap)); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index c20007481b..186ad447d6 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -58,31 +58,27 @@ public final class MapboxMap { private static final String TAG = "Mbgl-MapboxMap"; private final NativeMapView nativeMapView; - private final UiSettings uiSettings; private final Projection projection; private final Transform transform; - private final AnnotationManager annotationManager; private final CameraChangeDispatcher cameraChangeDispatcher; - private final OnGesturesManagerInteractionListener onGesturesManagerInteractionListener; + private final List styleLoadedCallbacks = new ArrayList<>(); private LocationComponent locationComponent; + private AnnotationManager annotationManager; + @Nullable private MapboxMap.OnFpsChangedListener onFpsChangedListener; - private final List styleLoadedCallbacks = new ArrayList<>(); - @Nullable private Style style; MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection, - OnGesturesManagerInteractionListener listener, AnnotationManager annotations, - CameraChangeDispatcher cameraChangeDispatcher) { + OnGesturesManagerInteractionListener listener, CameraChangeDispatcher cameraChangeDispatcher) { this.nativeMapView = map; this.uiSettings = ui; this.projection = projection; - this.annotationManager = annotations.bind(this); this.transform = transform; this.onGesturesManagerInteractionListener = listener; this.cameraChangeDispatcher = cameraChangeDispatcher; @@ -762,7 +758,7 @@ public final class MapboxMap { * will be triggered. *

* - * @param style The bundled style + * @param style The bundled style * @param callback The callback to be invoked when the style has loaded * @see Style */ @@ -793,7 +789,7 @@ public final class MapboxMap { * and {@link MapView.OnDidFailLoadingMapListener} callback will be triggered. *

* - * @param builder The style builder + * @param builder The style builder * @param callback The callback to be invoked when the style has loaded * @see Style */ @@ -820,7 +816,7 @@ public final class MapboxMap { } } - private void notifyStyleLoaded() { + void notifyStyleLoaded() { if (style != null) { style.onDidFinishLoadingStyle(); locationComponent.onFinishLoadingStyle(); @@ -1814,6 +1810,10 @@ public final class MapboxMap { this.locationComponent = locationComponent; } + void injectAnnotationManager(AnnotationManager annotationManager) { + this.annotationManager = annotationManager.bind(this); + } + /** * Returns the {@link LocationComponent} that can be used to display user's location on the map. *

diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java index 04153916eb..5e2439cba3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java @@ -603,6 +603,22 @@ public class Style { return styleJson; } + List getSources() { + return sources; + } + + List getLayers() { + return layers; + } + + List getImages() { + return images; + } + + TransitionOptions getTransitionOptions() { + return transitionOptions; + } + /** * Build the composed style. */ @@ -610,41 +626,28 @@ public class Style { return new Style(this, nativeMapView); } - private class ImageWrapper { - private Bitmap bitmap; - private String id; - private boolean sdf; + class ImageWrapper { + Bitmap bitmap; + String id; + boolean sdf; ImageWrapper(String id, Bitmap bitmap, boolean sdf) { this.id = id; this.bitmap = bitmap; this.sdf = sdf; } - - public Bitmap getBitmap() { - return bitmap; - } - - public String getId() { - return id; - } - - public boolean isSdf() { - return sdf; - } } - private class LayerWrapper { - private Layer layer; + class LayerWrapper { + Layer layer; LayerWrapper(Layer layer) { this.layer = layer; } } - private class LayerAboveWrapper extends LayerWrapper { - - private String aboveLayer; + class LayerAboveWrapper extends LayerWrapper { + String aboveLayer; LayerAboveWrapper(Layer layer, String aboveLayer) { super(layer); @@ -652,9 +655,8 @@ public class Style { } } - private class LayerBelowWrapper extends LayerWrapper { - - private String belowLayer; + class LayerBelowWrapper extends LayerWrapper { + String belowLayer; LayerBelowWrapper(Layer layer, String belowLayer) { super(layer); @@ -662,9 +664,8 @@ public class Style { } } - private class LayerAtWrapper extends LayerWrapper { - - private int index; + class LayerAtWrapper extends LayerWrapper { + int index; LayerAtWrapper(Layer layer, int index) { super(layer); 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() + val builder = Style.Builder() + builder.withLayer(layer) + assertEquals(layer, builder.layers[0].layer) + } + + @Test + fun testWithLayerAt() { + val expectedIndex = 5 + val layer = mockk() + 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() + 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() + 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() + 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() + 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() + 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() + 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() + 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() + 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() + val builder = Style.Builder().withImage("id", image) + mapboxMap.setStyle(builder) + verify(exactly = 1) { nativeMapView.addImage("id", image, false) } + } + + @Test + fun testWithImageSdf() { + val image = mockk() + 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() + 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() + 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() + 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() + 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() + 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() + 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() + 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() + 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() + every { callback.onStyleLoaded(any()) } answers {} + val source = mockk() + 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() + every { callback.onStyleLoaded(any()) } answers {} + mapboxMap.getStyle(callback) + val source = mockk() + 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() + every { callback.onStyleLoaded(any()) } answers {} + mapboxMap.getStyle(callback) + val source = mockk() + 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() + every { callback.onStyleLoaded(any()) } answers {} + mapboxMap.getStyle(callback) + val source = mockk() + 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 diff --git a/platform/android/gradle/dependencies.gradle b/platform/android/gradle/dependencies.gradle index f3ed79bfcd..8fd7952765 100644 --- a/platform/android/gradle/dependencies.gradle +++ b/platform/android/gradle/dependencies.gradle @@ -18,6 +18,7 @@ ext { leakCanary : '1.6.1', junit : '4.12', mockito : '2.18.3', + mockk : '1.8.13.kotlin13', robolectric : '3.8', timber : '4.7.1', okhttp : '3.11.0', @@ -38,6 +39,7 @@ ext { junit : "junit:junit:${versions.junit}", mockito : "org.mockito:mockito-core:${versions.mockito}", + mockk : "io.mockk:mockk:${versions.mockk}", robolectric : "org.robolectric:robolectric:${versions.robolectric}", testRunner : "com.android.support.test:runner:${versions.testRunner}", diff --git a/platform/android/scripts/exclude-activity-gen.json b/platform/android/scripts/exclude-activity-gen.json index 2e46770f68..425d652188 100644 --- a/platform/android/scripts/exclude-activity-gen.json +++ b/platform/android/scripts/exclude-activity-gen.json @@ -39,5 +39,7 @@ "SymbolLayerActivity", "LocationFragmentActivity", "MergeOfflineRegionsActivity", - "NestedViewPagerActivity" + "NestedViewPagerActivity", + "DebugModeActivity", + "TextureViewDebugModeActivity" ] -- cgit v1.2.1