[android] fix LocationComponent unit test with Style.java object

This commit is contained in:
Łukasz Paczos
2018-12-05 18:40:55 +01:00
committed by Tobrun
parent 70e10ba133
commit 8e067868e7
2 changed files with 54 additions and 37 deletions

View File

@@ -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;
LocationComponent.this.options = options;
mapboxMap.getStyle(new InitializationCallback(context));
}
mapboxMap.addOnMapClickListener(onMapClickListener);
mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
class InitializationCallback implements Style.OnStyleLoaded {
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);
private final Context context;
locationAnimatorCoordinator = new LocationAnimatorCoordinator();
locationAnimatorCoordinator.addLayerListener(locationLayerController);
locationAnimatorCoordinator.addCameraListener(locationCameraController);
locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options
.trackingAnimationDurationMultiplier());
private InitializationCallback(Context context) {
this.context = context;
}
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();
@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) {

View File

@@ -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)