[android] Remove com.google.android.gms.location (#379) (#801)

This commit is contained in:
Bart Louwers
2023-02-15 11:22:44 +01:00
committed by GitHub
parent 4a34caab75
commit 982ac6e7e3
19 changed files with 83 additions and 771 deletions

View File

@@ -1,11 +1,8 @@
package com.mapbox.mapboxsdk.location
import android.content.Context
import android.content.res.Resources
import android.content.res.TypedArray
import android.location.Location
import android.os.Looper
import com.mapbox.mapboxsdk.R
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.location.LocationComponentConstants.TRANSITION_ANIMATION_DURATION_MS
import com.mapbox.mapboxsdk.location.engine.LocationEngine
@@ -69,60 +66,45 @@ class LocationComponentTest {
@Mock
private lateinit var staleStateManager: StaleStateManager
@Mock
private lateinit var locationEngineProvider: LocationComponent.InternalLocationEngineProvider
@Mock
private lateinit var style: Style
private lateinit var developerAnimationListeners: List<MapboxMap.OnDeveloperAnimationListener>
private val defaultOptions: LocationComponentActivationOptions
get() = LocationComponentActivationOptions.builder(context, style).locationEngine(locationEngine).locationEngineRequest(locationEngineRequest).locationComponentOptions(locationComponentOptions).build()
@Before
fun before() {
MockitoAnnotations.initMocks(this)
developerAnimationListeners = mutableListOf()
locationComponent = LocationComponent(mapboxMap, transform, developerAnimationListeners, currentListener, lastListener, locationLayerController, locationCameraController, locationAnimatorCoordinator, staleStateManager, compassEngine, locationEngineProvider, false)
doReturn(locationEngine).`when`(locationEngineProvider).getBestLocationEngine(context, false)
locationComponent = LocationComponent(mapboxMap, transform, developerAnimationListeners, currentListener, lastListener, locationLayerController, locationCameraController, locationAnimatorCoordinator, staleStateManager, compassEngine, false)
doReturn(style).`when`(mapboxMap).style
}
@Test
fun activateWithRequestTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
doReturn(mock(TypedArray::class.java)).`when`(context)
.obtainStyledAttributes(R.style.maplibre_LocationComponent, R.styleable.maplibre_LocationComponent)
val resources = mock(Resources::class.java)
doReturn(resources).`when`(context).resources
doReturn(0f).`when`(resources)
.getDimension(R.dimen.maplibre_locationComponentTrackingMultiFingerMoveThreshold)
doReturn(0f).`when`(resources)
.getDimension(R.dimen.maplibre_locationComponentTrackingMultiFingerMoveThreshold)
locationComponent.activateLocationComponent(context, mock(Style::class.java), true, locationEngineRequest)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
`when`(style.isFullyLoaded).thenReturn(true)
}
@Test
fun activateWithDefaultLocationEngineRequestAndOptionsTestDefaultLocationEngine() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), true, locationEngineRequest, locationComponentOptions)
val options = LocationComponentActivationOptions.builder(context, style).locationEngine(locationEngine).locationEngineRequest(locationEngineRequest).locationComponentOptions(locationComponentOptions).build()
locationComponent.activateLocationComponent(options)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
Assert.assertNotNull(locationComponent.locationEngine)
}
@Test
fun activateWithDefaultLocationEngineRequestAndOptionsTestCustomLocationEngine() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), false, locationEngineRequest, locationComponentOptions)
val options = LocationComponentActivationOptions.builder(context, style).useDefaultLocationEngine(false).locationEngineRequest(locationEngineRequest).locationComponentOptions(locationComponentOptions).build()
locationComponent.activateLocationComponent(options)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
Assert.assertNull(locationComponent.locationEngine)
}
@Test
fun locationUpdatesWhenEnabledDisableTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
verify(locationEngine, times(0)).removeLocationUpdates(currentListener)
verify(locationEngine, times(0)).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
@@ -140,7 +122,8 @@ class LocationComponentTest {
@Test
fun locationUpdatesWhenStartedStoppedTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
@@ -153,7 +136,7 @@ class LocationComponentTest {
@Test
fun locationUpdatesWhenNewRequestTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
@@ -165,7 +148,7 @@ class LocationComponentTest {
@Test
fun lastLocationUpdateOnStartTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
@@ -174,7 +157,7 @@ class LocationComponentTest {
@Test
fun transitionCallbackFinishedTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -192,7 +175,7 @@ class LocationComponentTest {
@Test
fun transitionCallbackCanceledTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -210,7 +193,8 @@ class LocationComponentTest {
@Test
fun transitionCustomFinishedTest() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -228,7 +212,7 @@ class LocationComponentTest {
@Test
fun compass_listenWhenConsumedByNoneCamera() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -240,7 +224,7 @@ class LocationComponentTest {
@Test
fun compass_listenWhenConsumedByTrackingCamera() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -252,7 +236,7 @@ class LocationComponentTest {
@Test
fun compass_listenWhenConsumedByLayer() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -264,7 +248,7 @@ class LocationComponentTest {
@Test
fun compass_notListenWhenNotConsumed() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -283,7 +267,7 @@ class LocationComponentTest {
@Test
fun compass_removeListenerOnChange() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -297,7 +281,7 @@ class LocationComponentTest {
@Test
fun compass_removeListenerOnStop() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -310,7 +294,7 @@ class LocationComponentTest {
@Test
fun compass_reAddListenerOnStart() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -324,7 +308,7 @@ class LocationComponentTest {
@Test
fun compass_removeListenerOnStyleStartLoad() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -337,7 +321,7 @@ class LocationComponentTest {
@Test
fun compass_reAddListenerOnStyleLoadFinished() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -351,7 +335,7 @@ class LocationComponentTest {
@Test
fun compass_reAddListenerOnlyWhenEnabled() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -367,7 +351,7 @@ class LocationComponentTest {
@Test
fun compass_notAdListenerWhenDisabled() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -378,7 +362,7 @@ class LocationComponentTest {
@Test
fun compass_notAdListenerWhenStopped() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -389,7 +373,7 @@ class LocationComponentTest {
@Test
fun compass_notAddListenerWhenLayerNotReady() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.onStart()
locationComponent.isLocationComponentEnabled = true
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
@@ -406,7 +390,7 @@ class LocationComponentTest {
@Test
fun developerAnimationCalled() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
for (listener in developerAnimationListeners) {
listener.onDeveloperAnimationStarted()
@@ -416,7 +400,7 @@ class LocationComponentTest {
@Test
fun internal_cameraTrackingChangedListener_onCameraTrackingDismissed() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
val cameraChangeListener: OnCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener::class.java)
@@ -429,7 +413,7 @@ class LocationComponentTest {
@Test
fun internal_cameraTrackingChangedListener_onCameraTrackingChanged() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
val cameraValueListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
@@ -451,7 +435,7 @@ class LocationComponentTest {
@Test
fun internal_renderModeChangedListener_onRenderModeChanged() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
val cameraListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
@@ -476,7 +460,6 @@ class LocationComponentTest {
val projection: Projection = mock(Projection::class.java)
`when`(projection.getMetersPerPixelAtLatitude(location.latitude)).thenReturn(10.0)
`when`(mapboxMap.projection).thenReturn(projection)
`when`(style.isFullyLoaded).thenReturn(true)
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
locationComponent.activateLocationComponent(
@@ -500,7 +483,7 @@ class LocationComponentTest {
@Test
fun tiltWhileTracking_notReady() {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
val callback = mock(MapboxMap.CancelableCallback::class.java)
@@ -514,7 +497,7 @@ class LocationComponentTest {
fun tiltWhileTracking_notTracking() {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
`when`(locationCameraController.cameraMode).thenReturn(CameraMode.NONE)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
@@ -530,7 +513,7 @@ class LocationComponentTest {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
`when`(locationCameraController.cameraMode).thenReturn(CameraMode.TRACKING)
`when`(locationCameraController.isTransitioning).thenReturn(true)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
@@ -546,7 +529,7 @@ class LocationComponentTest {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
`when`(locationCameraController.cameraMode).thenReturn(CameraMode.TRACKING)
`when`(locationCameraController.isTransitioning).thenReturn(false)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
@@ -560,7 +543,7 @@ class LocationComponentTest {
@Test
fun zoomWhileTracking_notReady() {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
val callback = mock(MapboxMap.CancelableCallback::class.java)
@@ -574,7 +557,7 @@ class LocationComponentTest {
fun zoomWhileTracking_notTracking() {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
`when`(locationCameraController.cameraMode).thenReturn(CameraMode.NONE)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
@@ -590,7 +573,7 @@ class LocationComponentTest {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
`when`(locationCameraController.cameraMode).thenReturn(CameraMode.TRACKING)
`when`(locationCameraController.isTransitioning).thenReturn(true)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
@@ -606,7 +589,7 @@ class LocationComponentTest {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
`when`(locationCameraController.cameraMode).thenReturn(CameraMode.TRACKING)
`when`(locationCameraController.isTransitioning).thenReturn(false)
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.activateLocationComponent(defaultOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
@@ -624,7 +607,6 @@ class LocationComponentTest {
val projection: Projection = mock(Projection::class.java)
`when`(projection.getMetersPerPixelAtLatitude(location.latitude)).thenReturn(10.0)
`when`(mapboxMap.projection).thenReturn(projection)
`when`(style.isFullyLoaded).thenReturn(true)
locationComponent.activateLocationComponent(
LocationComponentActivationOptions.builder(context, style)
.locationComponentOptions(locationComponentOptions)
@@ -643,8 +625,7 @@ class LocationComponentTest {
fun newLocation_accuracy_indicatorLayerRadiusValue() {
val location = Location("test")
location.accuracy = 50f
`when`(style.isFullyLoaded).thenReturn(true)
locationComponent = LocationComponent(mapboxMap, transform, developerAnimationListeners, currentListener, lastListener, locationLayerController, locationCameraController, locationAnimatorCoordinator, staleStateManager, compassEngine, locationEngineProvider, true)
locationComponent = LocationComponent(mapboxMap, transform, developerAnimationListeners, currentListener, lastListener, locationLayerController, locationCameraController, locationAnimatorCoordinator, staleStateManager, compassEngine, true)
locationComponent.activateLocationComponent(
LocationComponentActivationOptions.builder(context, style)
.locationComponentOptions(locationComponentOptions)

View File

@@ -1,129 +0,0 @@
package com.mapbox.mapboxsdk.location.engine;
import android.location.Location;
import android.os.Looper;
import androidx.annotation.NonNull;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class GoogleLocationEngineImplAdditionalTest {
private static final long INTERVAL = 1000L;
private LocationEngineProxy engine;
private Location location;
private List<Location> locationList = new ArrayList<>();
private FusedLocationProviderClient fusedLocationProviderClient;
private Task<Void> mockTask;
private Task<Location> mockLocationTask;
@Before
public void setUp() {
location = mock(Location.class);
when(location.getLatitude()).thenReturn(1.0);
when(location.getLongitude()).thenReturn(2.0);
locationList.clear();
locationList.add(location);
fusedLocationProviderClient = mock(FusedLocationProviderClient.class);
mockTask = mock(Task.class);
mockLocationTask = mock(Task.class);
when(fusedLocationProviderClient.getLastLocation()).thenReturn(mockLocationTask);
when(fusedLocationProviderClient
.requestLocationUpdates(any(LocationRequest.class), any(LocationCallback.class), any(Looper.class)))
.thenAnswer(new Answer<Task<Void>>() {
@Override
public Task<Void> answer(InvocationOnMock invocation) {
LocationCallback listener = (LocationCallback) invocation.getArguments()[1];
listener.onLocationResult(LocationResult.create(locationList));
return mockTask;
}
});
engine = new LocationEngineProxy<>(new GoogleLocationEngineImpl(fusedLocationProviderClient));
}
@Test
public void checkGetLastLocation() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
when(mockLocationTask.addOnSuccessListener(any(OnSuccessListener.class)))
.thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
OnSuccessListener listener = (OnSuccessListener) invocation.getArguments()[0];
listener.onSuccess(location);
return mock(Task.class);
}
});
engine.getLastLocation(new LocationEngineCallback<LocationEngineResult>() {
@Override
public void onSuccess(LocationEngineResult result) {
List<Location> list = result.getLocations();
assertEquals(1, list.size());
assertEquals(1.0, list.get(0).getLatitude(), 0);
assertEquals(2.0, list.get(0).getLongitude(), 0);
latch.countDown();
}
@Override
public void onFailure(@NonNull Exception exception) {
}
});
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
@Test
public void checkRequestAndRemoveLocationUpdates() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
LocationEngineCallback<LocationEngineResult> engineCallback = new LocationEngineCallback<LocationEngineResult>() {
@Override
public void onSuccess(LocationEngineResult result) {
List<Location> list = result.getLocations();
assertEquals(1, list.size());
assertEquals(1.0, list.get(0).getLatitude(), 0);
assertEquals(2.0, list.get(0).getLongitude(), 0);
latch.countDown();
}
@Override
public void onFailure(@NonNull Exception exception) {
}
};
engine.requestLocationUpdates(getRequest(INTERVAL, LocationEngineRequest.PRIORITY_HIGH_ACCURACY),
engineCallback, mock(Looper.class));
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertNotNull(engine.removeListener(engineCallback));
}
private static LocationEngineRequest getRequest(long interval, int priority) {
return new LocationEngineRequest.Builder(interval).setPriority(priority).build();
}
}

View File

@@ -1,66 +0,0 @@
package com.mapbox.mapboxsdk.location.engine;
import android.app.PendingIntent;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public class GoogleLocationEngineImplTest {
@Mock
private FusedLocationProviderClient fusedLocationProviderClientMock;
private LocationEngine engine;
private GoogleLocationEngineImpl googleLocationEngineImpl;
@Before
public void setUp() {
googleLocationEngineImpl = new GoogleLocationEngineImpl(fusedLocationProviderClientMock);
engine = new LocationEngineProxy<>(googleLocationEngineImpl);
}
@Test
public void removeLocationUpdatesForInvalidListener() {
LocationEngineCallback<LocationEngineResult> callback = mock(LocationEngineCallback.class);
engine.removeLocationUpdates(callback);
verify(fusedLocationProviderClientMock, never()).removeLocationUpdates(any(LocationCallback.class));
}
@Test
public void removeLocationUpdatesForPendingIntent() {
PendingIntent pendingIntent = mock(PendingIntent.class);
engine.removeLocationUpdates(pendingIntent);
verify(fusedLocationProviderClientMock, times(1))
.removeLocationUpdates(any(PendingIntent.class));
}
@Test(expected = NullPointerException.class)
public void getLastLocationNullCallback() {
engine.getLastLocation(null);
}
@Test(expected = NullPointerException.class)
public void requestLocationUpdatesNullCallback() {
engine.requestLocationUpdates(null, null, null);
}
@After
public void tearDown() {
reset(fusedLocationProviderClientMock);
engine = null;
}
}

View File

@@ -1,14 +0,0 @@
package com.mapbox.mapboxsdk.location.engine;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class LocationEngineProviderTest {
@Test(expected = NullPointerException.class)
public void passNullContext() {
LocationEngineProvider.getBestLocationEngine(null, false);
}
}