summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/CompassEngineTest.java25
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt161
2 files changed, 186 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/CompassEngineTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/CompassEngineTest.java
index bc64379263..bebd828118 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/CompassEngineTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/CompassEngineTest.java
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.location;
import android.hardware.Sensor;
+import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.WindowManager;
@@ -10,7 +11,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import static com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.SENSOR_DELAY_MICROS;
import static junit.framework.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -27,8 +31,15 @@ public class CompassEngineTest {
@Mock
private SensorManager sensorManager;
+ @Mock
+ private Sensor compassSensor;
+
+ @Mock
+ private CompassListener compassListener;
+
@Before
public void setUp() throws Exception {
+ when(sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)).thenReturn(compassSensor);
compassEngine = new LocationComponentCompassEngine(windowManager, sensorManager);
}
@@ -61,4 +72,18 @@ public class CompassEngineTest {
verify(sensorManager, times(1)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
}
+
+ @Test
+ public void listener_registerOnAdd() {
+ compassEngine.addCompassListener(compassListener);
+ verify(sensorManager)
+ .registerListener(any(SensorEventListener.class), eq(compassSensor), eq(SENSOR_DELAY_MICROS));
+ }
+
+ @Test
+ public void listener_unregisterOnRemove() {
+ compassEngine.addCompassListener(compassListener);
+ compassEngine.removeCompassListener(compassListener);
+ verify(sensorManager).unregisterListener(any(SensorEventListener.class), eq(compassSensor));
+ }
}
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 2fa340fbb8..cf513068ac 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.camera.CameraPosition
import com.mapbox.mapboxsdk.location.modes.CameraMode
+import com.mapbox.mapboxsdk.location.modes.RenderMode
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import io.mockk.mockk
@@ -183,4 +184,164 @@ class LocationComponentTest {
verify(listener).onLocationCameraTransitionCanceled(CameraMode.TRACKING)
verify(locationAnimatorCoordinator).resetAllCameraAnimations(CameraPosition.DEFAULT, false)
}
+
+ @Test
+ fun compass_listenWhenConsumedByNoneCamera() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationCameraController.isConsumingCompass).thenReturn(true)
+ locationComponent.cameraMode = CameraMode.NONE_COMPASS
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_listenWhenConsumedByTrackingCamera() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationCameraController.isConsumingCompass).thenReturn(true)
+ locationComponent.cameraMode = CameraMode.TRACKING_COMPASS
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_listenWhenConsumedByLayer() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_notListenWhenNotConsumed() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(false)
+ `when`(locationCameraController.isConsumingCompass).thenReturn(false)
+ locationComponent.renderMode = RenderMode.GPS
+ locationComponent.renderMode = RenderMode.NORMAL
+ locationComponent.cameraMode = CameraMode.TRACKING
+ locationComponent.cameraMode = CameraMode.NONE
+ locationComponent.cameraMode = CameraMode.NONE_GPS
+ locationComponent.cameraMode = CameraMode.TRACKING_GPS
+ locationComponent.cameraMode = CameraMode.TRACKING_GPS_NORTH
+ verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_removeListenerOnChange() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ `when`(locationLayerController.isConsumingCompass).thenReturn(false)
+ locationComponent.renderMode = RenderMode.NORMAL
+ verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_removeListenerOnStop() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStop()
+ verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_reAddListenerOnStart() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStop()
+ locationComponent.onStart()
+ verify(compassEngine, times(2)).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_removeListenerOnStyleStartLoad() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStartLoadingMap()
+ verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_reAddListenerOnStyleLoadFinished() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStartLoadingMap()
+ locationComponent.onFinishLoadingStyle()
+ verify(compassEngine, times(2)).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_reAddListenerOnlyWhenEnabled() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.isLocationComponentEnabled = false
+ locationComponent.onStartLoadingMap()
+ locationComponent.onFinishLoadingStyle()
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_notAdListenerWhenDisabled() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_notAdListenerWhenStopped() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
+ }
} \ No newline at end of file