diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins')
6 files changed, 0 insertions, 1248 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/CompassEngineTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/CompassEngineTest.java deleted file mode 100644 index c69d2fc5fb..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/CompassEngineTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.mapbox.mapboxsdk.plugins.locationlayer; - -import android.hardware.Sensor; -import android.hardware.SensorManager; -import android.view.WindowManager; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import static junit.framework.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class CompassEngineTest { - - private LocationLayerCompassEngine compassEngine; - - @Mock - private WindowManager windowManager; - - @Mock - private SensorManager sensorManager; - - @Before - public void setUp() throws Exception { - compassEngine = new LocationLayerCompassEngine(windowManager, sensorManager); - } - - @Test - public void lastKnownCompassBearingAccuracyDefault() { - assertEquals("Last accuracy should match", compassEngine.getLastAccuracySensorStatus(), 0); - } - - @Test - public void lastKnownCompassAccuracyStatusValue() { - Sensor sensor = mock(Sensor.class); - compassEngine.onAccuracyChanged(sensor, 2); - assertEquals("Last accuracy should match", compassEngine.getLastAccuracySensorStatus(), 2); - } - - @Test - public void whenGyroscopeIsNull_fallbackToGravity() { - SensorManager sensorManager = mock(SensorManager.class); - when(sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)).thenReturn(null); - new LocationLayerCompassEngine(windowManager, sensorManager); - - verify(sensorManager, times(1)).getDefaultSensor(Sensor.TYPE_ACCELEROMETER); - } - - @Test - public void whenGyroscopeIsNull_fallbackToMagneticField() { - SensorManager sensorManager = mock(SensorManager.class); - when(sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)).thenReturn(null); - new LocationLayerCompassEngine(windowManager, sensorManager); - - verify(sensorManager, times(1)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCameraTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCameraTest.java deleted file mode 100644 index c73216f5d6..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCameraTest.java +++ /dev/null @@ -1,337 +0,0 @@ -package com.mapbox.mapboxsdk.plugins.locationlayer; - -import android.graphics.PointF; - -import com.mapbox.android.gestures.MoveGestureDetector; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.camera.CameraUpdate; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Projection; -import com.mapbox.mapboxsdk.maps.UiSettings; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode; - -import org.junit.Test; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class LocationLayerCameraTest { - - @Test - public void setCameraMode_mapTransitionsAreCancelled() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - - camera.setCameraMode(CameraMode.TRACKING_GPS); - - verify(mapboxMap).cancelTransitions(); - } - - @Test - public void setCameraMode_gestureThresholdIsAdjusted() { - MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); - LocationLayerCamera camera = buildCamera(moveGestureDetector); - LocationLayerOptions options = mock(LocationLayerOptions.class); - float moveThreshold = 5f; - when(options.trackingInitialMoveThreshold()).thenReturn(moveThreshold); - camera.initializeOptions(options); - - camera.setCameraMode(CameraMode.TRACKING_GPS); - - verify(moveGestureDetector).setMoveThreshold(moveThreshold); - } - - @Test - public void setCameraMode_gestureThresholdIsResetWhenNotTracking() { - MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); - LocationLayerCamera camera = buildCamera(moveGestureDetector); - camera.initializeOptions(mock(LocationLayerOptions.class)); - - camera.setCameraMode(CameraMode.NONE); - - verify(moveGestureDetector).setMoveThreshold(0f); - } - - @Test - public void setCameraMode_notTrackingAdjustsFocalPoint() { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - - camera.setCameraMode(CameraMode.TRACKING_GPS); - camera.setCameraMode(CameraMode.NONE); - - verify(mapboxMap.getUiSettings()).setFocalPoint(null); - } - - @Test - public void setCameraMode_trackingChangeListenerCameraDismissedIsCalled() { - OnCameraTrackingChangedListener internalTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); - LocationLayerCamera camera = buildCamera(internalTrackingChangedListener); - camera.initializeOptions(mock(LocationLayerOptions.class)); - - camera.setCameraMode(CameraMode.TRACKING_GPS); - camera.setCameraMode(CameraMode.NONE); - - verify(internalTrackingChangedListener).onCameraTrackingDismissed(); - } - - @Test - public void setCameraMode_internalCameraTrackingChangeListenerIsCalled() { - OnCameraTrackingChangedListener internalTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); - LocationLayerCamera camera = buildCamera(internalTrackingChangedListener); - camera.initializeOptions(mock(LocationLayerOptions.class)); - int cameraMode = CameraMode.NONE; - - camera.setCameraMode(cameraMode); - - verify(internalTrackingChangedListener).onCameraTrackingChanged(cameraMode); - } - - @Test - public void onNewLatLngValue_cameraModeTrackingUpdatesLatLng() { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - when(mapboxMap.getProjection()).thenReturn(mock(Projection.class)); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING); - LatLng latLng = mock(LatLng.class); - - camera.onNewLatLngValue(latLng); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewLatLngValue_cameraModeTrackingGpsNorthUpdatesLatLng() { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - when(mapboxMap.getProjection()).thenReturn(mock(Projection.class)); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH); - LatLng latLng = mock(LatLng.class); - - camera.onNewLatLngValue(latLng); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewLatLngValue_cameraModeTrackingGpsUpdatesLatLng() { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - when(mapboxMap.getProjection()).thenReturn(mock(Projection.class)); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_GPS); - LatLng latLng = mock(LatLng.class); - - camera.onNewLatLngValue(latLng); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewLatLngValue_cameraModeTrackingCompassUpdatesLatLng() { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - when(mapboxMap.getProjection()).thenReturn(mock(Projection.class)); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_COMPASS); - LatLng latLng = mock(LatLng.class); - - camera.onNewLatLngValue(latLng); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewLatLngValue_cameraModeNoneIgnored() { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - when(mapboxMap.getProjection()).thenReturn(mock(Projection.class)); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.NONE); - LatLng latLng = mock(LatLng.class); - - camera.onNewLatLngValue(latLng); - - verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewLatLngValue_focalPointIsAdjusted() { - MapboxMap mapboxMap = mock(MapboxMap.class); - UiSettings uiSettings = mock(UiSettings.class); - when(mapboxMap.getUiSettings()).thenReturn(uiSettings); - Projection projection = mock(Projection.class); - PointF pointF = mock(PointF.class); - when(projection.toScreenLocation(any(LatLng.class))).thenReturn(pointF); - when(mapboxMap.getProjection()).thenReturn(projection); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING); - LatLng latLng = mock(LatLng.class); - - camera.onNewLatLngValue(latLng); - - verify(uiSettings).setFocalPoint(pointF); - } - - @Test - public void onNewGpsBearingValue_cameraModeTrackingGpsUpdatesBearing() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_GPS); - float gpsBearing = 5f; - - camera.onNewGpsBearingValue(gpsBearing); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewGpsBearingValue_cameraModeNoneGpsUpdatesBearing() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.NONE_GPS); - float gpsBearing = 5f; - - camera.onNewGpsBearingValue(gpsBearing); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewGpsBearingValue_cameraModeTrackingNorthUpdatesBearing() { - MapboxMap mapboxMap = mock(MapboxMap.class); - CameraPosition cameraPosition = new CameraPosition.Builder().bearing(7d).build(); - when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH); - float gpsBearing = 5f; - - camera.onNewGpsBearingValue(gpsBearing); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewGpsBearingValue_cameraModeTrackingNorthBearingZeroIgnored() { - MapboxMap mapboxMap = mock(MapboxMap.class); - CameraPosition cameraPosition = new CameraPosition.Builder().bearing(0d).build(); - when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH); - float gpsBearing = 5f; - - camera.onNewGpsBearingValue(gpsBearing); - - verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewGpsBearingValue_cameraModeNoneIgnored() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.NONE); - float gpsBearing = 5f; - - camera.onNewGpsBearingValue(gpsBearing); - - verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewCompassBearingValue_cameraModeTrackingCompassUpdatesBearing() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING_COMPASS); - float compassBearing = 5f; - - camera.onNewCompassBearingValue(compassBearing); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewCompassBearingValue_cameraModeNoneCompassUpdatesBearing() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.NONE_COMPASS); - float compassBearing = 5f; - - camera.onNewCompassBearingValue(compassBearing); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewCompassBearingValue_cameraModeNoneIgnored() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.NONE); - float compassBearing = 5f; - - camera.onNewCompassBearingValue(compassBearing); - - verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class)); - } - - @Test - public void onNewZoomValue_cameraIsUpdated() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LocationLayerCamera camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationLayerOptions.class)); - camera.setCameraMode(CameraMode.TRACKING); - float zoom = 5f; - - camera.onNewZoomValue(zoom); - - verify(mapboxMap).moveCamera(any(CameraUpdate.class)); - } - - private LocationLayerCamera buildCamera(OnCameraTrackingChangedListener onCameraTrackingChangedListener) { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); - OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); - return new LocationLayerCamera(mapboxMap, moveGestureDetector, - onCameraTrackingChangedListener, onCameraMoveInvalidateListener); - } - - private LocationLayerCamera buildCamera(MoveGestureDetector moveGestureDetector) { - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); - OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); - OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); - return new LocationLayerCamera(mapboxMap, moveGestureDetector, - onCameraTrackingChangedListener, onCameraMoveInvalidateListener); - } - - private LocationLayerCamera buildCamera(MapboxMap mapboxMap) { - MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); - OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); - OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); - return new LocationLayerCamera(mapboxMap, moveGestureDetector, - onCameraTrackingChangedListener, onCameraMoveInvalidateListener); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptionsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptionsTest.java deleted file mode 100644 index 5062a9b9cc..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptionsTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.mapbox.mapboxsdk.plugins.locationlayer; - -import android.content.Context; -import android.content.res.Resources; -import android.content.res.TypedArray; - -import com.mapbox.mapboxsdk.R; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class LocationLayerOptionsTest { - - @Mock - private Context context; - @Mock - private TypedArray array; - @Mock - private Resources resources; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - when(context.obtainStyledAttributes(R.style.mapbox_LocationLayer, R.styleable.mapbox_LocationLayer)) - .thenReturn(array); - when(array.getResourceId(R.styleable.mapbox_LocationLayer_mapbox_foregroundDrawable, -1)) - .thenReturn(R.drawable.mapbox_user_icon); - when(context.getResources()).thenReturn(resources); - } - - @Test - public void sanity() throws Exception { - LocationLayerOptions locationLayerOptions = LocationLayerOptions.builder(context) - .accuracyAlpha(0.5f) - .build(); - assertNotNull(locationLayerOptions); - } - - @Test - public void passingOutOfRangeAccuracyAlpha_throwsException() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Location layer accuracy alpha value must be between 0.0 and " - + "1.0."); - LocationLayerOptions.builder(context) - .accuracyAlpha(2f) - .build(); - } - - @Test - public void negativeElevation_causesExceptionToBeThrown() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid shadow size -500.0. Must be >= 0"); - LocationLayerOptions.builder(context) - .elevation(-500) - .build(); - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java deleted file mode 100644 index 2a08855ab7..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java +++ /dev/null @@ -1,466 +0,0 @@ -package com.mapbox.mapboxsdk.plugins.locationlayer; - -import android.graphics.Bitmap; - -import com.google.gson.JsonElement; -import com.mapbox.geojson.Feature; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; -import com.mapbox.mapboxsdk.style.layers.Layer; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; - -import org.junit.Test; - -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.BACKGROUND_ICON; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.BACKGROUND_LAYER; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.BACKGROUND_STALE_ICON; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.BEARING_ICON; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.BEARING_LAYER; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.FOREGROUND_ICON; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.FOREGROUND_LAYER; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.FOREGROUND_STALE_ICON; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.LOCATION_SOURCE; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.PROPERTY_ACCURACY_RADIUS; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.PROPERTY_COMPASS_BEARING; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.PROPERTY_FOREGROUND_ICON_OFFSET; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.PROPERTY_GPS_BEARING; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.PROPERTY_SHADOW_ICON_OFFSET; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.SHADOW_ICON; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.SHADOW_LAYER; -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; -import static org.mockito.Mockito.when; - -public class LocationLayerTest { - - @Test - public void onInitialization_locationSourceIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addSource(locationSource); - } - - @Test - public void onInitialization_shadowLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - Layer shadowLayer = mock(Layer.class); - when(sourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addLayerBelow(shadowLayer, BACKGROUND_LAYER); - } - - @Test - public void onInitialization_backgroundLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - Layer backgroundLayer = mock(Layer.class); - when(sourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addLayerBelow(backgroundLayer, FOREGROUND_LAYER); - } - - @Test - public void onInitialization_foregroundLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - Layer foregroundLayer = mock(Layer.class); - when(sourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addLayerBelow(foregroundLayer, BEARING_LAYER); - } - - @Test - public void onInitialization_bearingLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - Layer bearingLayer = mock(Layer.class); - when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - String layerBelow = "layer-below"; - when(options.layerBelow()).thenReturn(layerBelow); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addLayerBelow(bearingLayer, layerBelow); - } - - @Test - public void onInitialization_accuracyLayerIsAdded() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - Layer accuracyLayer = mock(Layer.class); - when(sourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addLayerBelow(accuracyLayer, BACKGROUND_LAYER); - } - - @Test - public void applyStyle_styleShadowWithValidElevation() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateShadowBitmap(any(LocationLayerOptions.class))).thenReturn(bitmap); - LocationLayerOptions options = mock(LocationLayerOptions.class); - when(options.elevation()).thenReturn(2f); - - // Style is applied on initialization - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addImage(SHADOW_ICON, bitmap); - } - - @Test - public void applyStyle_ignoreStyleShadowWithInvalidElevation() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateShadowBitmap(any(LocationLayerOptions.class))).thenReturn(bitmap); - LocationLayerOptions options = mock(LocationLayerOptions.class); - when(options.elevation()).thenReturn(0f); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap, times(0)).addImage(SHADOW_ICON, bitmap); - } - - @Test - public void applyStyle_styleForegroundFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LocationLayerOptions options = mock(LocationLayerOptions.class); - int drawableResId = 123; - int tintColor = 456; - when(options.foregroundDrawable()).thenReturn(drawableResId); - when(options.foregroundTintColor()).thenReturn(tintColor); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addImage(FOREGROUND_ICON, bitmap); - } - - @Test - public void applyStyle_styleForegroundStaleFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LocationLayerOptions options = mock(LocationLayerOptions.class); - int drawableResId = 123; - int tintColor = 456; - when(options.foregroundDrawableStale()).thenReturn(drawableResId); - when(options.foregroundStaleTintColor()).thenReturn(tintColor); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addImage(FOREGROUND_STALE_ICON, bitmap); - } - - @Test - public void applyStyle_styleBackgroundFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LocationLayerOptions options = mock(LocationLayerOptions.class); - int drawableResId = 123; - int tintColor = 456; - when(options.backgroundDrawable()).thenReturn(drawableResId); - when(options.backgroundTintColor()).thenReturn(tintColor); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addImage(BACKGROUND_ICON, bitmap); - } - - @Test - public void applyStyle_styleBackgroundStaleFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LocationLayerOptions options = mock(LocationLayerOptions.class); - int drawableResId = 123; - int tintColor = 456; - when(options.backgroundDrawableStale()).thenReturn(drawableResId); - when(options.backgroundStaleTintColor()).thenReturn(tintColor); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addImage(BACKGROUND_STALE_ICON, bitmap); - } - - @Test - public void applyStyle_styleBearingFromOptions() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class)); - LocationLayerOptions options = mock(LocationLayerOptions.class); - int drawableResId = 123; - int tintColor = 456; - when(options.bearingDrawable()).thenReturn(drawableResId); - when(options.bearingTintColor()).thenReturn(tintColor); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - Bitmap bitmap = mock(Bitmap.class); - when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap); - - new LocationLayer(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options); - - verify(mapboxMap).addImage(BEARING_ICON, bitmap); - } - - @Test - public void updateForegroundOffset_foregroundIconPropertyIsUpdated() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - - layer.updateForegroundOffset(2d); - - verify(locationFeature).addProperty(eq(PROPERTY_FOREGROUND_ICON_OFFSET), any(JsonElement.class)); - } - - @Test - public void updateForegroundOffset_shadowPropertyIsUpdated() { - MapboxMap mapboxMap = mock(MapboxMap.class); - LayerSourceProvider sourceProvider = buildLayerProvider(); - GeoJsonSource locationSource = mock(GeoJsonSource.class); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - - layer.updateForegroundOffset(2d); - - verify(locationFeature).addProperty(eq(PROPERTY_SHADOW_ICON_OFFSET), any(JsonElement.class)); - } - - @Test - public void onNewLatLngValue_locationFeatureIsUpdated() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - - layer.onNewLatLngValue(new LatLng()); - - // wanted twice (once for initialization) - verify(locationSource, times(2)).setGeoJson(locationFeature); - } - - @Test - public void onNewGpsBearingValue_locationFeatureIsUpdated() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - layer.setRenderMode(RenderMode.GPS); - float gpsBearing = 2f; - - layer.onNewGpsBearingValue(gpsBearing); - - verify(locationFeature).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing); - } - - @Test - public void onNewGpsBearingValue_updateIgnoredWithInvalidRenderMode() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - layer.setRenderMode(RenderMode.COMPASS); - float gpsBearing = 2f; - - layer.onNewGpsBearingValue(gpsBearing); - - verify(locationFeature, times(0)).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing); - } - - @Test - public void onNewCompassBearingValue_locationFeatureIsUpdated() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - layer.setRenderMode(RenderMode.COMPASS); - float compassBearing = 2f; - - layer.onNewCompassBearingValue(compassBearing); - - verify(locationFeature).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing); - } - - @Test - public void onNewCompassBearingValue_updateIgnoredWithInvalidRenderMode() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - layer.setRenderMode(RenderMode.GPS); - float compassBearing = 2f; - - layer.onNewCompassBearingValue(compassBearing); - - verify(locationFeature, times(0)).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing); - } - - @Test - public void onNewAccuracyRadiusValue_locationFeatureIsUpdated() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - float accuracyRadiusValue = 2f; - - layer.onNewAccuracyRadiusValue(accuracyRadiusValue); - - verify(locationFeature).addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue); - } - - @Test - public void onNewAccuracyRadiusValue_updateIgnoredWithInvalidRenderMode() { - GeoJsonSource locationSource = mock(GeoJsonSource.class); - MapboxMap mapboxMap = mock(MapboxMap.class); - when(mapboxMap.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource); - LayerSourceProvider sourceProvider = buildLayerProvider(); - when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource); - LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class); - LocationLayerOptions options = mock(LocationLayerOptions.class); - Feature locationFeature = mock(Feature.class); - LocationLayer layer = new LocationLayer( - mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options - ); - layer.setRenderMode(RenderMode.GPS); - float accuracyRadiusValue = 2f; - - layer.onNewAccuracyRadiusValue(accuracyRadiusValue); - - verify(locationFeature, times(0)).addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue); - } - - private LayerFeatureProvider buildFeatureProvider(LocationLayerOptions options) { - LayerFeatureProvider provider = mock(LayerFeatureProvider.class); - when(provider.generateLocationFeature(null, options)).thenReturn(mock(Feature.class)); - return provider; - } - - private LayerFeatureProvider buildFeatureProvider(Feature feature, LocationLayerOptions options) { - LayerFeatureProvider provider = mock(LayerFeatureProvider.class); - when(provider.generateLocationFeature(null, options)).thenReturn(feature); - return provider; - } - - private LayerSourceProvider buildLayerProvider() { - LayerSourceProvider layerSourceProvider = mock(LayerSourceProvider.class); - when(layerSourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(mock(Layer.class)); - when(layerSourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(mock(Layer.class)); - when(layerSourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(mock(Layer.class)); - when(layerSourceProvider.generateLayer(BEARING_LAYER)).thenReturn(mock(Layer.class)); - when(layerSourceProvider.generateAccuracyLayer()).thenReturn(mock(Layer.class)); - return layerSourceProvider; - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt deleted file mode 100644 index 2d7dc5b1a2..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt +++ /dev/null @@ -1,284 +0,0 @@ -package com.mapbox.mapboxsdk.plugins.locationlayer - -import android.location.Location -import com.mapbox.mapboxsdk.camera.CameraPosition -import com.mapbox.mapboxsdk.geometry.LatLng -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION -import com.mapbox.mapboxsdk.plugins.locationlayer.PluginAnimator.* -import junit.framework.Assert.assertEquals -import junit.framework.Assert.assertTrue -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mockito -import org.robolectric.RobolectricTestRunner - -@RunWith(RobolectricTestRunner::class) -class PluginAnimatorCoordinatorTest { - - private lateinit var pluginAnimatorCoordinator: PluginAnimatorCoordinator - private val cameraPosition: CameraPosition = CameraPosition.DEFAULT - - @Before - fun setUp() { - pluginAnimatorCoordinator = PluginAnimatorCoordinator() - } - - @Test - fun feedNewLocation_animatorsAreCreated() { - pluginAnimatorCoordinator.feedNewLocation(Location(""), cameraPosition, false) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_LATLNG] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_GPS_BEARING] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_LATLNG] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_GPS_BEARING] != null) - } - - @Test - fun feedNewLocation_animatorValue() { - val location = Location("") - location.latitude = 51.0 - location.longitude = 17.0 - location.bearing = 35f - pluginAnimatorCoordinator.feedNewLocation(location, cameraPosition, false) - - val cameraLatLngTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_LATLNG]?.target as LatLng - assertEquals(cameraLatLngTarget.latitude, cameraLatLngTarget.latitude) - - val layerLatLngTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_LATLNG]?.target as LatLng - assertEquals(layerLatLngTarget.latitude, layerLatLngTarget.latitude) - - val cameraBearingTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_GPS_BEARING]?.target as Float - assertEquals(location.bearing, cameraBearingTarget) - - val layerBearingTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_GPS_BEARING]?.target as Float - assertEquals(location.bearing, layerBearingTarget) - } - - @Test - fun feedNewLocation_isNorth_animatorsAreCreated() { - val location = Location("") - location.latitude = 51.0 - location.longitude = 17.0 - location.bearing = 35f - pluginAnimatorCoordinator.feedNewLocation(location, cameraPosition, false) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_LATLNG] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_GPS_BEARING] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_LATLNG] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_GPS_BEARING] != null) - } - - @Test - fun feedNewLocation_isNorth_animatorValue() { - val location = Location("") - location.latitude = 51.0 - location.longitude = 17.0 - location.bearing = 35f - pluginAnimatorCoordinator.feedNewLocation(location, cameraPosition, true) - - val cameraLatLngTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_LATLNG]?.target as LatLng - assertEquals(cameraLatLngTarget.latitude, cameraLatLngTarget.latitude) - - val layerLatLngTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_LATLNG]?.target as LatLng - assertEquals(layerLatLngTarget.latitude, layerLatLngTarget.latitude) - - val cameraBearingTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_GPS_BEARING]?.target as Float - assertEquals(0f, cameraBearingTarget) - - val layerBearingTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_GPS_BEARING]?.target as Float - assertEquals(location.bearing, layerBearingTarget) - } - - @Test - fun feedNewCompassBearing_animatorsAreCreated() { - pluginAnimatorCoordinator.feedNewCompassBearing(77f, cameraPosition) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_COMPASS_BEARING] != null) - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_COMPASS_BEARING] != null) - } - - @Test - fun feedNewCompassBearing_animatorValue() { - val bearing = 77f - pluginAnimatorCoordinator.feedNewCompassBearing(bearing, cameraPosition) - - val cameraBearingTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_COMPASS_BEARING]?.target as Float - assertEquals(bearing, cameraBearingTarget) - - val layerBearingTarget = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_COMPASS_BEARING]?.target as Float - assertEquals(bearing, layerBearingTarget) - } - - @Test - fun feedNewAccuracyRadius_animatorsCreated() { - pluginAnimatorCoordinator.feedNewAccuracyRadius(150f, false) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_ACCURACY] != null) - } - - @Test - fun feedNewAccuracyRadius_animatorValue() { - val accuracy = 150f - pluginAnimatorCoordinator.feedNewAccuracyRadius(accuracy, false) - - val layerAccuracy = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_ACCURACY]?.target as Float - assertEquals(layerAccuracy, accuracy) - - val animationDuration = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_ACCURACY]?.duration as Long - assertEquals(LocationLayerConstants.ACCURACY_RADIUS_ANIMATION_DURATION, animationDuration) - } - - @Test - fun feedNewAccuracyRadius_noAnimation_animatorsCreated() { - pluginAnimatorCoordinator.feedNewAccuracyRadius(150f, true) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_ACCURACY] != null) - } - - @Test - fun feedNewAccuracyRadius_noAnimation_animatorValue() { - val accuracy = 150f - pluginAnimatorCoordinator.feedNewAccuracyRadius(accuracy, true) - - val layerAccuracy = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_ACCURACY]?.target as Float - assertEquals(layerAccuracy, accuracy) - - val animationDuration = pluginAnimatorCoordinator.animatorMap[ANIMATOR_LAYER_ACCURACY]?.duration as Long - assertEquals(0L, animationDuration) - } - - @Test - fun feedNewZoomLevel_animatorsCreated() { - pluginAnimatorCoordinator.feedNewZoomLevel( - 15.0, - cameraPosition, - DEFAULT_TRACKING_ZOOM_ANIM_DURATION, - null - ) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_ZOOM] != null) - } - - @Test - fun feedNewZoomLevel_animatorValue() { - val zoom = 15.0f - pluginAnimatorCoordinator.feedNewZoomLevel( - zoom.toDouble(), - cameraPosition, - DEFAULT_TRACKING_ZOOM_ANIM_DURATION, - null - ) - - val animationDuration = pluginAnimatorCoordinator.animatorMap[ANIMATOR_ZOOM]?.duration as Long - assertEquals(DEFAULT_TRACKING_ZOOM_ANIM_DURATION, animationDuration) - - val target = pluginAnimatorCoordinator.animatorMap[ANIMATOR_ZOOM]?.target as Float - assertEquals(zoom, target) - } - - @Test - fun feedNewTiltLevel_animatorsCreated() { - pluginAnimatorCoordinator.feedNewTilt( - 30.0, - cameraPosition, - DEFAULT_TRACKING_TILT_ANIM_DURATION, - null - ) - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_TILT] != null) - } - - @Test - fun feedNewTiltLevel_animatorValue() { - val tilt = 30.0f - pluginAnimatorCoordinator.feedNewTilt( - tilt.toDouble(), - cameraPosition, - DEFAULT_TRACKING_TILT_ANIM_DURATION, - null - ) - - val animationDuration = pluginAnimatorCoordinator.animatorMap[ANIMATOR_TILT]?.duration as Long - assertEquals(DEFAULT_TRACKING_TILT_ANIM_DURATION, animationDuration) - - val target = pluginAnimatorCoordinator.animatorMap[ANIMATOR_TILT]?.target as Float - assertEquals(tilt, target) - } - - @Test - fun cancelAllAnimators() { - pluginAnimatorCoordinator.feedNewLocation(Location(""), cameraPosition, true) - pluginAnimatorCoordinator.cancelAllAnimations() - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_CAMERA_LATLNG] == null) - } - - @Test - fun cancelZoomAnimators() { - pluginAnimatorCoordinator.feedNewZoomLevel( - 15.0, - cameraPosition, - DEFAULT_TRACKING_ZOOM_ANIM_DURATION, - null - ) - pluginAnimatorCoordinator.cancelZoomAnimation() - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_ZOOM] == null) - } - - @Test - fun cancelTiltAnimation() { - pluginAnimatorCoordinator.feedNewTilt( - 30.0, - cameraPosition, - DEFAULT_TRACKING_TILT_ANIM_DURATION, - null - ) - - pluginAnimatorCoordinator.cancelTiltAnimation() - - assertTrue(pluginAnimatorCoordinator.animatorMap[ANIMATOR_TILT] == null) - } - - @Test - fun resetAllCameraAnimations_empty() { - pluginAnimatorCoordinator.resetAllCameraAnimations(cameraPosition, false) - assertTrue(pluginAnimatorCoordinator.animatorMap.isEmpty()) - } - - @Test - fun addLayerListener() { - val layerListener = Mockito.mock(OnLayerAnimationsValuesChangeListener::class.java) - pluginAnimatorCoordinator.addLayerListener(layerListener) - - assertTrue(pluginAnimatorCoordinator.layerListeners.contains(layerListener)) - } - - @Test - fun removeLayerListener() { - val layerListener = Mockito.mock(OnLayerAnimationsValuesChangeListener::class.java) - pluginAnimatorCoordinator.addLayerListener(layerListener) - pluginAnimatorCoordinator.removeLayerListener(layerListener) - - assertTrue(pluginAnimatorCoordinator.layerListeners.isEmpty()) - } - - @Test - fun addCameraListener() { - val cameraListener = Mockito.mock(OnCameraAnimationsValuesChangeListener::class.java) - pluginAnimatorCoordinator.addCameraListener(cameraListener) - - assertTrue(pluginAnimatorCoordinator.cameraListeners.contains(cameraListener)) - } - - @Test - fun removeCameraListener() { - val cameraListener = Mockito.mock(OnCameraAnimationsValuesChangeListener::class.java) - pluginAnimatorCoordinator.addCameraListener(cameraListener) - pluginAnimatorCoordinator.removeCameraListener(cameraListener) - - assertTrue(pluginAnimatorCoordinator.cameraListeners.isEmpty()) - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/UtilsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/UtilsTest.java deleted file mode 100644 index 9caad6c6a1..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/UtilsTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mapbox.mapboxsdk.plugins.locationlayer; - -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; - -public final class UtilsTest { - - - @Test - public void shortestRotation_doesReturnValueDistanceQuickestToZero() throws Exception { - float value = Utils.shortestRotation(0, 181); - assertEquals(360f, value); - value = Utils.shortestRotation(0, 179); - assertEquals(0f, value); - value = Utils.shortestRotation(0, 180); - assertEquals(0f, value); - } - - @Test - public void shortestRotation_doesReturnValueDistanceQuickestToFifty() throws Exception { - float value = Utils.shortestRotation(50, 231); - assertEquals(410f, value); - value = Utils.shortestRotation(50, 229); - assertEquals(50f, value); - value = Utils.shortestRotation(50, 180); - assertEquals(50f, value); - } -} |