summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-12-05 18:40:55 +0100
committerTobrun <tobrun@mapbox.com>2018-12-10 16:59:50 +0100
commit8e067868e70db4d2865dbce00d38b221794185d5 (patch)
tree70aeecc515acca69f8ead9119f9d50ed12039775
parent70e10ba1337398995ea1a11b69052f7b0db0f6aa (diff)
downloadqtlocation-mapboxgl-8e067868e70db4d2865dbce00d38b221794185d5.tar.gz
[android] fix LocationComponent unit test with Style.java object
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java90
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt9
2 files changed, 58 insertions, 41 deletions
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 c6ab96f320..b361de847b 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
@@ -183,6 +183,7 @@ public final class LocationComponent {
this.staleStateManager = staleStateManager;
this.compassEngine = compassEngine;
this.internalLocationEngineProvider = internalLocationEngineProvider;
+ isComponentInitialized = true;
}
/**
@@ -893,47 +894,56 @@ public final class LocationComponent {
}
private void initialize(@NonNull final Context context, @NonNull final LocationComponentOptions options) {
- mapboxMap.getStyle(new Style.OnStyleLoaded() {
- @Override
- public void onStyleLoaded(@NonNull Style style) {
- if (isComponentInitialized) {
- return;
- }
- isComponentInitialized = true;
- LocationComponent.this.options = options;
-
- mapboxMap.addOnMapClickListener(onMapClickListener);
- mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
-
- LayerSourceProvider sourceProvider = new LayerSourceProvider();
- LayerFeatureProvider featureProvider = new LayerFeatureProvider();
- LayerBitmapProvider bitmapProvider = new LayerBitmapProvider(context);
- locationLayerController = new LocationLayerController(mapboxMap, sourceProvider, featureProvider,
- bitmapProvider,
- options);
- locationCameraController = new LocationCameraController(
- context, mapboxMap, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener);
-
- locationAnimatorCoordinator = new LocationAnimatorCoordinator();
- locationAnimatorCoordinator.addLayerListener(locationLayerController);
- locationAnimatorCoordinator.addCameraListener(locationCameraController);
- locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options
- .trackingAnimationDurationMultiplier());
-
- WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- compassEngine = new LocationComponentCompassEngine(windowManager, sensorManager);
- compassEngine.addCompassListener(compassListener);
- staleStateManager = new StaleStateManager(onLocationStaleListener, options);
-
- updateMapWithOptions(options);
-
- setRenderMode(RenderMode.NORMAL);
- setCameraMode(CameraMode.NONE);
-
- onLocationLayerStart();
+ LocationComponent.this.options = options;
+ mapboxMap.getStyle(new InitializationCallback(context));
+ }
+
+ class InitializationCallback implements Style.OnStyleLoaded {
+
+ private final Context context;
+
+ private InitializationCallback(Context context) {
+ this.context = context;
+ }
+
+ @Override
+ public void onStyleLoaded(@NonNull Style style) {
+ if (isComponentInitialized) {
+ return;
}
- });
+ isComponentInitialized = true;
+
+ mapboxMap.addOnMapClickListener(onMapClickListener);
+ mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
+
+ LayerSourceProvider sourceProvider = new LayerSourceProvider();
+ LayerFeatureProvider featureProvider = new LayerFeatureProvider();
+ LayerBitmapProvider bitmapProvider = new LayerBitmapProvider(context);
+ locationLayerController = new LocationLayerController(mapboxMap, sourceProvider, featureProvider,
+ bitmapProvider,
+ options);
+ locationCameraController = new LocationCameraController(
+ context, mapboxMap, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener);
+
+ locationAnimatorCoordinator = new LocationAnimatorCoordinator();
+ locationAnimatorCoordinator.addLayerListener(locationLayerController);
+ locationAnimatorCoordinator.addCameraListener(locationCameraController);
+ locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options
+ .trackingAnimationDurationMultiplier());
+
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ compassEngine = new LocationComponentCompassEngine(windowManager, sensorManager);
+ compassEngine.addCompassListener(compassListener);
+ staleStateManager = new StaleStateManager(onLocationStaleListener, options);
+
+ updateMapWithOptions(options);
+
+ setRenderMode(RenderMode.NORMAL);
+ setCameraMode(CameraMode.NONE);
+
+ onLocationLayerStart();
+ }
}
private void initializeLocationEngine(@NonNull Context context) {
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 0c8684e061..853760f6df 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
@@ -8,11 +8,12 @@ import com.mapbox.android.core.location.LocationEngine
import com.mapbox.android.core.location.LocationEngineRequest
import com.mapbox.mapboxsdk.R
import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.Style
import org.junit.Assert
import org.junit.Before
-import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito.*
import org.mockito.MockitoAnnotations
@@ -61,16 +62,22 @@ class LocationComponentTest {
@Mock
private lateinit var locationEngineProvider: LocationComponent.InternalLocationEngineProvider
+ @Mock
+ private lateinit var style: Style
+
@Before
fun before() {
MockitoAnnotations.initMocks(this)
locationComponent = LocationComponent(mapboxMap, currentListener, lastListener, locationLayerController, locationCameraController, locationAnimatorCoordinator, staleStateManager, compassEngine, locationEngineProvider)
doReturn(locationEngine).`when`(locationEngineProvider).getBestLocationEngine(context, false)
+ doReturn(style).`when`(mapboxMap).style
}
@Test
fun activateWithRequestTest() {
locationComponent.activateLocationComponent(context, locationEngine, locationEngineRequest, locationComponentOptions)
+ verify(mapboxMap).getStyle(ArgumentMatchers.any(Style.OnStyleLoaded::class.java))
+
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
doReturn(mock(TypedArray::class.java)).`when`(context)