diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt | 150 |
1 files changed, 79 insertions, 71 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt index a0873e97ff..2d68612c70 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt @@ -15,31 +15,33 @@ import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) class MapboxMapTest { - private lateinit var mapboxMap: MapboxMap - - private lateinit var nativeMapView: NativeMapView - - private lateinit var transform: Transform - - @Before - fun setup() { - val cameraChangeDispatcher = spyk<CameraChangeDispatcher>() - nativeMapView = mockk(relaxed = true) - transform = mockk(relaxed = true) - mapboxMap = MapboxMap(nativeMapView, transform, mockk(relaxed = true), null, null, cameraChangeDispatcher) - every { nativeMapView.isDestroyed } returns false - every { nativeMapView.nativePtr } returns 5 - mapboxMap.injectLocationComponent(spyk()) - mapboxMap.setStyle(Style.MAPBOX_STREETS) - mapboxMap.onFinishLoadingStyle() - } - - @Test - fun testTransitionOptions() { - val expected = TransitionOptions(100, 200) - mapboxMap.style?.transition = expected - verify { nativeMapView.transitionOptions = expected } - } + private lateinit var mapboxMap: MapboxMap + + private lateinit var nativeMapView: NativeMapView + + private lateinit var transform: Transform + + private lateinit var cameraChangeDispatcher: CameraChangeDispatcher + + @Before + fun setup() { + cameraChangeDispatcher = spyk() + nativeMapView = mockk(relaxed = true) + transform = mockk(relaxed = true) + mapboxMap = MapboxMap(nativeMapView, transform, mockk(relaxed = true), null, null, cameraChangeDispatcher) + every { nativeMapView.isDestroyed } returns false + every { nativeMapView.nativePtr } returns 5 + mapboxMap.injectLocationComponent(spyk()) + mapboxMap.setStyle(Style.MAPBOX_STREETS) + mapboxMap.onFinishLoadingStyle() + } + + @Test + fun testTransitionOptions() { + val expected = TransitionOptions(100, 200) + mapboxMap.style?.transition = expected + verify { nativeMapView.transitionOptions = expected } + } @Test fun testMoveCamera() { @@ -51,52 +53,52 @@ class MapboxMapTest { verify { transform.moveCamera(mapboxMap, update, callback) } } - @Test - fun testMinZoom() { - mapboxMap.setMinZoomPreference(10.0) - verify { transform.minZoom = 10.0 } - } - - @Test - fun testMaxZoom() { - mapboxMap.setMaxZoomPreference(10.0) - verify { transform.maxZoom = 10.0 } - } - - @Test - fun testFpsListener() { - val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>() - mapboxMap.onFpsChangedListener = fpsChangedListener - assertEquals("Listener should match", fpsChangedListener, mapboxMap.onFpsChangedListener) - } - - @Test - fun testTilePrefetch() { - mapboxMap.prefetchesTiles = true - verify { nativeMapView.prefetchTiles = true } - } - - @Test - fun testCameraForLatLngBounds() { - val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build() - mapboxMap.setLatLngBoundsForCameraTarget(bounds) - verify { nativeMapView.setLatLngBounds(bounds) } - } - - @Test(expected = IllegalArgumentException::class) - fun testAnimateCameraChecksDurationPositive() { - mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null) - } - - @Test(expected = IllegalArgumentException::class) - fun testEaseCameraChecksDurationPositive() { - mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null) - } - - @Test - fun testGetNativeMapPtr() { - assertEquals(5, mapboxMap.nativeMapPtr) - } + @Test + fun testMinZoom() { + mapboxMap.setMinZoomPreference(10.0) + verify { transform.minZoom = 10.0 } + } + + @Test + fun testMaxZoom() { + mapboxMap.setMaxZoomPreference(10.0) + verify { transform.maxZoom = 10.0 } + } + + @Test + fun testFpsListener() { + val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>() + mapboxMap.onFpsChangedListener = fpsChangedListener + assertEquals("Listener should match", fpsChangedListener, mapboxMap.onFpsChangedListener) + } + + @Test + fun testTilePrefetch() { + mapboxMap.prefetchesTiles = true + verify { nativeMapView.prefetchTiles = true } + } + + @Test + fun testCameraForLatLngBounds() { + val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build() + mapboxMap.setLatLngBoundsForCameraTarget(bounds) + verify { nativeMapView.setLatLngBounds(bounds) } + } + + @Test(expected = IllegalArgumentException::class) + fun testAnimateCameraChecksDurationPositive() { + mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null) + } + + @Test(expected = IllegalArgumentException::class) + fun testEaseCameraChecksDurationPositive() { + mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null) + } + + @Test + fun testGetNativeMapPtr() { + assertEquals(5, mapboxMap.nativeMapPtr) + } @Test fun testNativeMapIsNotCalledOnStateSave() { @@ -104,4 +106,10 @@ class MapboxMapTest { mapboxMap.onSaveInstanceState(mockk(relaxed = true)) verify { nativeMapView wasNot Called } } + + @Test + fun testCameraChangeDispatcherCleared() { + mapboxMap.onDestroy() + verify { cameraChangeDispatcher.onDestroy() } + } }
\ No newline at end of file |