Remove deprecated location APIs (#11351)

This commit is contained in:
Łukasz Paczos
2018-03-02 11:01:10 +01:00
committed by GitHub
parent 87f88f37c4
commit 899211d816
49 changed files with 30 additions and 4679 deletions

View File

@@ -5,7 +5,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.android.core.location.LocationEngine;
import org.junit.Before;
import org.junit.Test;
@@ -25,13 +24,11 @@ public class MapboxTest {
private Context context;
private Context appContext;
private LocationEngine locationSource;
@Before
public void before() {
context = mock(Context.class);
appContext = mock(Context.class);
locationSource = mock(LocationEngine.class);
when(context.getApplicationContext()).thenReturn(appContext);
}
@@ -83,7 +80,7 @@ public class MapboxTest {
}
private void injectMapboxSingleton(String accessToken) {
Mapbox mapbox = new Mapbox(appContext, accessToken, locationSource);
Mapbox mapbox = new Mapbox(appContext, accessToken);
try {
Field field = Mapbox.class.getDeclaredField("INSTANCE");
field.setAccessible(true);

View File

@@ -118,13 +118,6 @@ public class MapboxMapOptionsTest {
assertNotEquals(2.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA);
}
@Test
public void testLocationEnabled() {
assertFalse(new MapboxMapOptions().getLocationEnabled());
assertTrue(new MapboxMapOptions().locationEnabled(true).getLocationEnabled());
assertFalse(new MapboxMapOptions().locationEnabled(false).getLocationEnabled());
}
@Test
public void testTiltGesturesEnabled() {
assertTrue(new MapboxMapOptions().getTiltGesturesEnabled());
@@ -175,18 +168,6 @@ public class MapboxMapOptionsTest {
assertNull(new MapboxMapOptions().getCamera());
}
@Test
public void testMyLocationForegroundTint() {
assertEquals(Color.BLUE, new MapboxMapOptions()
.myLocationForegroundTintColor(Color.BLUE).getMyLocationForegroundTintColor());
}
@Test
public void testMyLocationBackgroundTint() {
assertEquals(Color.BLUE, new MapboxMapOptions()
.myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor());
}
@Test
public void testPrefetchesTiles() {
// Default value

View File

@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import org.junit.After;
import org.junit.Before;
@@ -20,8 +19,6 @@ public class MapboxMapTest {
mapboxMap = new MapboxMap(mock(NativeMapView.class),
mock(Transform.class),
mock(UiSettings.class),
mock(TrackingSettings.class),
mock(MyLocationViewSettings.class),
mock(Projection.class),
mock(MapboxMap.OnGesturesManagerInteractionListener.class),
mock(AnnotationManager.class),

View File

@@ -1,99 +0,0 @@
package com.mapbox.mapboxsdk.maps;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.PointF;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class TrackingSettingsTest {
@InjectMocks
MyLocationView myLocationView = mock(MyLocationView.class);
@InjectMocks
UiSettings uiSettings = mock(UiSettings.class);
@InjectMocks
FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class);
@InjectMocks
TrackingSettings.CameraZoomInvalidator zoomInvalidator = mock(TrackingSettings.CameraZoomInvalidator.class);
private TrackingSettings trackingSettings;
@Before
public void beforeTest() {
trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointChangeListener, zoomInvalidator);
}
@Test
public void testSanity() {
assertNotNull("trackingsettings should not be null", trackingSettings);
}
@Test
public void testDismissTrackingModesOnGesture() {
trackingSettings.setDismissAllTrackingOnGesture(false);
assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isAllDismissTrackingOnGesture());
}
@Test
public void testValidateGesturesForTrackingModes() {
trackingSettings.setDismissAllTrackingOnGesture(false);
trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isAllDismissTrackingOnGesture());
}
@Test
public void testMyLocationEnabled() {
// setup mock context to provide accepted location permission
Context context = mock(Context.class);
when(myLocationView.getContext()).thenReturn(context);
when(context.checkPermission(eq(Manifest.permission.ACCESS_COARSE_LOCATION), anyInt(),
anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED);
assertFalse("Location should be disabled by default.", trackingSettings.isMyLocationEnabled());
trackingSettings.setMyLocationEnabled(true);
assertTrue("Location should be enabled", trackingSettings.isMyLocationEnabled());
}
@Test
public void testCameraZoomTo2forTracking() {
trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
verify(zoomInvalidator, atLeast(1)).zoomTo(2.0);
}
@Test
public void testFocalPointChangeForTracking() {
final float centerX = 32.3f;
final float centerY = 46.3f;
final PointF pointF = new PointF(centerX, centerY);
when(myLocationView.getCenter()).thenReturn(pointF);
trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
verify(focalPointChangeListener, atLeast(1)).onFocalPointChanged(pointF);
}
@Test
public void testFocalPointChangeForNonTracking() {
trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
verify(focalPointChangeListener, atLeast(1)).onFocalPointChanged(null);
}
}

View File

@@ -1,106 +0,0 @@
package com.mapbox.mapboxsdk.maps.widgets;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import com.mapbox.mapboxsdk.maps.FocalPointChangeListener;
import com.mapbox.mapboxsdk.maps.Projection;
import com.mapbox.mapboxsdk.maps.TrackingSettings;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import java.util.Arrays;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class MyLocationViewSettingsTest {
@InjectMocks
Projection projection = mock(Projection.class);
@InjectMocks
MyLocationView myLocationView = mock(MyLocationView.class);
@InjectMocks
TrackingSettings trackingSettings = mock(TrackingSettings.class);
@InjectMocks
FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class);
private MyLocationViewSettings locationViewSettings;
@Before
public void beforeTest() {
locationViewSettings = new MyLocationViewSettings(myLocationView, projection, focalPointChangeListener);
}
@Test
public void testSanity() {
assertNotNull("should not be null", locationViewSettings);
}
@Test
public void testForegroundDrawables() {
Drawable foregroundDrawable = mock(Drawable.class);
Drawable foregroundBearingDrawable = mock(Drawable.class);
Drawable.ConstantState constantState = mock(Drawable.ConstantState.class);
when(foregroundDrawable.getConstantState()).thenReturn(constantState);
when(constantState.newDrawable()).thenReturn(foregroundDrawable);
locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable);
assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable());
assertEquals("foreground bearing should match", foregroundBearingDrawable,
locationViewSettings.getForegroundBearingDrawable());
}
@Test
public void testBackgroundDrawable() {
Drawable backgroundDrawable = mock(Drawable.class);
int[] offset = new int[] {1, 2, 3, 4};
locationViewSettings.setBackgroundDrawable(backgroundDrawable, offset);
assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable());
assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset()));
}
@Test
public void testForegroundTint() {
int color = Color.RED;
locationViewSettings.setForegroundTintColor(Color.RED);
assertEquals("color should match", color, locationViewSettings.getForegroundTintColor());
}
@Test
public void testForegroundTransparentTint() {
int color = Color.TRANSPARENT;
locationViewSettings.setForegroundTintColor(Color.TRANSPARENT);
assertEquals("color should match", color, locationViewSettings.getForegroundTintColor());
}
@Test
public void testBackgroundTint() {
int color = Color.RED;
locationViewSettings.setBackgroundTintColor(Color.RED);
assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor());
}
@Test
public void testBackgroundTransparentTint() {
int color = Color.TRANSPARENT;
locationViewSettings.setBackgroundTintColor(Color.TRANSPARENT);
assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor());
}
@Test
public void testEnabled() {
assertFalse("initial state should be false", locationViewSettings.isEnabled());
locationViewSettings.setEnabled(true);
assertTrue("state should be true", locationViewSettings.isEnabled());
}
}