[build] - initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.KEY_PREFERENCE_SKU_TOKEN;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class AccountsManagerTest {
|
||||
@Test
|
||||
public void testIsExpired() {
|
||||
long now = AccountsManager.getNow();
|
||||
|
||||
long defaultValue = 0L;
|
||||
long tooOld = now - DateUtils.HOUR_IN_MILLIS - 1;
|
||||
long futureValue = now + 1;
|
||||
long immediatePast = now - 1;
|
||||
|
||||
assertTrue(AccountsManager.isExpired(now, defaultValue));
|
||||
assertTrue(AccountsManager.isExpired(now, tooOld));
|
||||
|
||||
assertFalse(AccountsManager.isExpired(now, futureValue));
|
||||
assertFalse(AccountsManager.isExpired(now, immediatePast));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksSkuTokenExternalManagement() {
|
||||
SharedPreferences mockedSharedPreferences = mock(SharedPreferences.class);
|
||||
when(mockedSharedPreferences.getString(KEY_PREFERENCE_SKU_TOKEN, "")).thenReturn("external-sku-token");
|
||||
boolean isNotManaged = false;
|
||||
AccountsManager theAccountsManager = new AccountsManager(mockedSharedPreferences, isNotManaged);
|
||||
|
||||
String skuToken = theAccountsManager.getSkuToken();
|
||||
|
||||
assertEquals("external-sku-token", skuToken);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksSkuTokenInternalManagement() {
|
||||
SharedPreferences mockedSharedPreferences = mock(SharedPreferences.class, RETURNS_DEEP_STUBS);
|
||||
when(mockedSharedPreferences.getString("com.mapbox.mapboxsdk.accounts.userid", ""))
|
||||
.thenReturn("any-user-id");
|
||||
boolean isManaged = true;
|
||||
AccountsManager theAccountsManager = new AccountsManager(mockedSharedPreferences, isManaged);
|
||||
|
||||
String skuToken = theAccountsManager.getSkuToken();
|
||||
|
||||
assertFalse(skuToken.isEmpty());
|
||||
assertTrue(skuToken.startsWith("100"));
|
||||
assertTrue(skuToken.endsWith("any-user-id"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MapboxInjector {
|
||||
|
||||
private static final String FIELD_INSTANCE = "INSTANCE";
|
||||
private static final String FIELD_ACCOUNTS = "accounts";
|
||||
|
||||
public static void inject(@NonNull Context context, @NonNull String accessToken) {
|
||||
inject(context, accessToken, null);
|
||||
}
|
||||
|
||||
public static void inject(@NonNull Context context, @NonNull String accessToken, @Nullable String skuToken) {
|
||||
Mapbox mapbox = new Mapbox(context, accessToken);
|
||||
try {
|
||||
Field instance = Mapbox.class.getDeclaredField(FIELD_INSTANCE);
|
||||
instance.setAccessible(true);
|
||||
instance.set(mapbox, mapbox);
|
||||
|
||||
Field accounts = Mapbox.class.getDeclaredField(FIELD_ACCOUNTS);
|
||||
accounts.setAccessible(true);
|
||||
|
||||
AccountsManager manager = mock(AccountsManager.class);
|
||||
when(manager.getSkuToken()).thenReturn(skuToken);
|
||||
accounts.set(mapbox, manager);
|
||||
} catch (Exception exception) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
try {
|
||||
Field field = Mapbox.class.getDeclaredField(FIELD_INSTANCE);
|
||||
field.setAccessible(true);
|
||||
field.set(field, null);
|
||||
} catch (Exception exception) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertSame;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MapboxTest {
|
||||
|
||||
private Context context;
|
||||
private Context appContext;
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
context = mock(Context.class);
|
||||
appContext = mock(Context.class);
|
||||
when(context.getApplicationContext()).thenReturn(appContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccessToken() {
|
||||
final String accessToken = "pk.0000000001";
|
||||
MapboxInjector.inject(context, accessToken);
|
||||
assertSame(accessToken, Mapbox.getAccessToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationContext() {
|
||||
MapboxInjector.inject(context, "pk.0000000001");
|
||||
assertNotNull(Mapbox.getApplicationContext());
|
||||
assertNotEquals(context, appContext);
|
||||
assertEquals(appContext, appContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPkTokenValid() {
|
||||
assertTrue(Mapbox.isAccessTokenValid("pk.0000000001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkTokenValid() {
|
||||
assertTrue(Mapbox.isAccessTokenValid("sk.0000000001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyToken() {
|
||||
assertFalse(Mapbox.isAccessTokenValid(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullToken() {
|
||||
assertFalse(Mapbox.isAccessTokenValid(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlaBlaToken() {
|
||||
assertFalse(Mapbox.isAccessTokenValid("blabla"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoInstance() {
|
||||
DisplayMetrics displayMetrics = mock(DisplayMetrics.class);
|
||||
Resources resources = mock(Resources.class);
|
||||
when(resources.getDisplayMetrics()).thenReturn(displayMetrics);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
TypedArray typedArray = mock(TypedArray.class);
|
||||
when(context.obtainStyledAttributes(nullable(AttributeSet.class), any(int[].class), anyInt(), anyInt()))
|
||||
.thenReturn(typedArray);
|
||||
|
||||
expectedException.expect(MapboxConfigurationException.class);
|
||||
expectedException.expectMessage(
|
||||
"\nUsing MapView requires calling Mapbox.getInstance(Context context, String accessToken) before "
|
||||
+ "inflating or creating the view. The access token parameter is required when using a Mapbox service."
|
||||
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
|
||||
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens."
|
||||
);
|
||||
new MapView(context);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
MapboxInjector.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class AnnotationTest {
|
||||
|
||||
@InjectMocks
|
||||
private MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
private Annotation annotation;
|
||||
@NonNull
|
||||
private Annotation compare = new Annotation() {
|
||||
@Override
|
||||
public long getId() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
annotation = new Annotation() {
|
||||
// empty child
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("markerOptions should not be null", annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
annotation.setId(1);
|
||||
annotation.setMapboxMap(mapboxMap);
|
||||
annotation.remove();
|
||||
verify(mapboxMap, times(1)).removeAnnotation(annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveUnboundMapboxMap() {
|
||||
annotation.setId(1);
|
||||
annotation.remove();
|
||||
verify(mapboxMap, times(0)).removeAnnotation(annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareToEqual() {
|
||||
annotation.setId(1);
|
||||
assertEquals("conparable equal", 0, annotation.compareTo(compare));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareToHigher() {
|
||||
annotation.setId(3);
|
||||
assertEquals("conparable higher", -1, annotation.compareTo(compare));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTolower() {
|
||||
annotation.setId(0);
|
||||
assertEquals("conparable lower", 1, annotation.compareTo(compare));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Annotation holder = null;
|
||||
assertFalse(annotation.equals(holder));
|
||||
holder = annotation;
|
||||
assertTrue(annotation.equals(holder));
|
||||
assertFalse(annotation.equals(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
int id = 1;
|
||||
annotation.setId(id);
|
||||
assertSame("hashcode should match", annotation.hashCode(), id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotSame;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IconTest {
|
||||
|
||||
@Mock
|
||||
Bitmap bitmap;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(bitmap.getConfig()).thenReturn(Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testId() {
|
||||
String id = "test";
|
||||
Icon icon = IconFactory.recreate(id, Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8));
|
||||
assertEquals("id should match", id, icon.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitmap() {
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
assertEquals("bitmap should match", bitmap, icon.getBitmap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Icon icon1 = IconFactory.recreate("test", bitmap);
|
||||
Icon icon2 = IconFactory.recreate("test", bitmap);
|
||||
assertEquals("icons should not match", icon1, icon2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsObject() {
|
||||
Icon icon = IconFactory.recreate("test", Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8));
|
||||
assertNotSame("icon should not match", new Object(), icon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
long expectedHashcode = 31 * bitmap.hashCode() + "test".hashCode();
|
||||
assertEquals("hashcode should match", expectedHashcode, icon.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.PointF;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Projection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class InfoWindowTest {
|
||||
|
||||
@InjectMocks
|
||||
MapView mMapView = mock(MapView.class);
|
||||
|
||||
@InjectMocks
|
||||
MapboxMap mMapboxMap = mock(MapboxMap.class);
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
assertNotNull("infoWindow should exist", infoWindow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
Marker marker = markerOptions.position(new LatLng()).getMarker();
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap).setBoundMarker(marker);
|
||||
assertEquals("marker should match", marker, infoWindow.getBoundMarker());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClose() {
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
infoWindow.close();
|
||||
assertEquals("infowindow should not be visible", false, infoWindow.isVisible());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOpen() {
|
||||
LatLng latLng = new LatLng(0, 0);
|
||||
Projection projection = mock(Projection.class);
|
||||
when(mMapboxMap.getProjection()).thenReturn(projection);
|
||||
when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
|
||||
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
infoWindow.open(mMapView, new MarkerOptions().position(new LatLng()).getMarker(), latLng, 0, 0);
|
||||
assertEquals("infowindow should not be visible", true, infoWindow.isVisible());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenClose() {
|
||||
LatLng latLng = new LatLng(0, 0);
|
||||
Projection projection = mock(Projection.class);
|
||||
when(mMapboxMap.getProjection()).thenReturn(projection);
|
||||
when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
|
||||
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
infoWindow.open(mMapView, new MarkerOptions().position(new LatLng()).getMarker(), latLng, 0, 0);
|
||||
infoWindow.close();
|
||||
assertEquals("infowindow should not be visible", false, infoWindow.isVisible());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
LatLng latLng = new LatLng(0, 0);
|
||||
Projection projection = mock(Projection.class);
|
||||
when(mMapboxMap.getProjection()).thenReturn(projection);
|
||||
when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
|
||||
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
infoWindow.open(mMapView, new MarkerOptions().position(latLng).getMarker(), latLng, 0, 0);
|
||||
infoWindow.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class MarkerTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
assertNotNull("markerOptions should not be null", markerOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
assertNotNull("marker should not be null", markerOptions.getMarker());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMarkerPositionException.class)
|
||||
public void testInvalidMarker() {
|
||||
new MarkerOptions().getMarker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPosition() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getPosition(), new LatLng(10, 12));
|
||||
assertEquals(markerOptions.getPosition(), new LatLng(10, 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitle() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().title("Mapbox").position(new LatLng());
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getTitle(), "Mapbox");
|
||||
assertEquals(markerOptions.getTitle(), "Mapbox");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSnippet() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().snippet("Mapbox").position(new LatLng());
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getSnippet(), "Mapbox");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
Marker marker = new MarkerOptions().title("title").snippet("snippet").position(new LatLng(10, 12)).getMarker();
|
||||
assertEquals(marker.getSnippet(), "snippet");
|
||||
|
||||
assertEquals(marker.getPosition(), new LatLng(10, 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIcon() {
|
||||
Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).icon(icon);
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals("Icon should match", icon, marker.getIcon());
|
||||
assertEquals("Icon should match", icon, markerOptions.getIcon());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
Marker marker = new MarkerOptions().position(new LatLng()).getMarker();
|
||||
assertEquals("hash code should match", marker.hashCode(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeBuilder() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
|
||||
assertEquals("hash code should match", markerOptions.hashCode(), 579999617);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Marker markerOne = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
|
||||
Marker markerTwo = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
|
||||
assertEquals(markerOne, markerTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentLocation() {
|
||||
MarkerOptions marker = new MarkerOptions().position(new LatLng(0, 0));
|
||||
MarkerOptions other = new MarkerOptions().position(new LatLng(1, 0));
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentSnippet() {
|
||||
MarkerOptions marker = new MarkerOptions().snippet("s");
|
||||
MarkerOptions other = new MarkerOptions();
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentIcon() {
|
||||
MarkerOptions marker = new MarkerOptions().icon(mock(Icon.class));
|
||||
MarkerOptions other = new MarkerOptions();
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentTitle() {
|
||||
MarkerOptions marker = new MarkerOptions().title("t");
|
||||
MarkerOptions other = new MarkerOptions();
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsItself() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0));
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals("Marker should match", marker, marker);
|
||||
assertEquals("MarkerOptions should match", markerOptions, markerOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEquals() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0));
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertNotEquals("MarkerOptions should match", markerOptions, new Object());
|
||||
assertNotEquals("Marker should match", marker, new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityBuilder() {
|
||||
MarkerOptions markerOne = new MarkerOptions().position(new LatLng(0, 0));
|
||||
MarkerOptions markerTwo = new MarkerOptions().position(new LatLng(0, 0));
|
||||
assertEquals(markerOne, markerTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Marker marker = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
|
||||
assertEquals(marker.toString(), "Marker [position[" + "LatLng [latitude=0.0, longitude=0.0, altitude=0.0]" + "]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).title("t").snippet("s");
|
||||
Parcelable parcelable = MockParcel.obtain(markerOptions);
|
||||
assertEquals("Parcel should match original object", parcelable, markerOptions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class PolygonTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
PolygonOptions polygonOptions = new PolygonOptions();
|
||||
assertNotNull("polygonOptions should not be null", polygonOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolygon() {
|
||||
Polygon polygon = new PolygonOptions().getPolygon();
|
||||
assertNotNull("polyline should not be null", polygon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlpha() {
|
||||
Polygon polygon = new PolygonOptions().alpha(0.5f).getPolygon();
|
||||
assertEquals(0.5f, polygon.getAlpha(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrokeColor() {
|
||||
Polygon polygon = new PolygonOptions().strokeColor(1).getPolygon();
|
||||
assertEquals(1, polygon.getStrokeColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColor() {
|
||||
Polygon polygon = new PolygonOptions().fillColor(1).getPolygon();
|
||||
assertEquals(1, polygon.getFillColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLng() {
|
||||
Polygon polygon = new PolygonOptions().add(new LatLng(0, 0)).getPolygon();
|
||||
assertNotNull("points should not be null", polygon.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polygon.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAllLatLng() {
|
||||
List<LatLng> coordinates = new ArrayList<>();
|
||||
coordinates.add(new LatLng(0, 0));
|
||||
Polygon polygon = new PolygonOptions().addAll(coordinates).getPolygon();
|
||||
assertNotNull(polygon.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polygon.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
polylineOptions.width(1.0f);
|
||||
polylineOptions.color(2);
|
||||
polylineOptions.add(new LatLng(0, 0));
|
||||
|
||||
Polyline polyline = polylineOptions.getPolyline();
|
||||
assertEquals(1.0f, polyline.getWidth(), 0);
|
||||
assertEquals(2, polyline.getColor());
|
||||
assertNotNull("Points should not be null", polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class PolylineTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
assertNotNull("polylineOptions should not be null", polylineOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolyline() {
|
||||
Polyline polyline = new PolylineOptions().getPolyline();
|
||||
assertNotNull("polyline should not be null", polyline);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlpha() {
|
||||
Polyline polyline = new PolylineOptions().alpha(0.2f).getPolyline();
|
||||
assertEquals(0.2f, polyline.getAlpha(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWidth() {
|
||||
Polyline polyline = new PolylineOptions().width(1).getPolyline();
|
||||
assertEquals(1.0f, polyline.getWidth(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColor() {
|
||||
Polyline polyline = new PolylineOptions().color(1).getPolyline();
|
||||
assertEquals(1, polyline.getColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddLatLng() {
|
||||
Polyline polyline = new PolylineOptions().add(new LatLng(0, 0)).getPolyline();
|
||||
assertNotNull("Points should not be null", polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAllLatLng() {
|
||||
List<LatLng> coordinates = new ArrayList<>();
|
||||
coordinates.add(new LatLng(0, 0));
|
||||
Polyline polyline = new PolylineOptions().addAll(coordinates).getPolyline();
|
||||
assertNotNull(polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
polylineOptions.width(1.0f);
|
||||
polylineOptions.color(2);
|
||||
polylineOptions.add(new LatLng(0, 0));
|
||||
|
||||
Polyline polyline = polylineOptions.getPolyline();
|
||||
assertEquals(1.0f, polyline.getWidth(), 0);
|
||||
assertEquals(2, polyline.getColor());
|
||||
assertNotNull("Points should not be null", polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
package com.mapbox.mapboxsdk.attribution;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AttributionParseTest {
|
||||
|
||||
private static final String STREETS_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">© Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://apps.mapbox.com/feedback/\" target=\"_blank\">Improve this map</a>\n";
|
||||
private static final String SATELLITE_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">© Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://apps.mapbox.com/feedback/\" target=\"_blank\">Improve this map</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">© DigitalGlobe</a>\n";
|
||||
|
||||
@Test
|
||||
public void testParseAttributionStringSatellite() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(SATELLITE_ATTRIBUTION)
|
||||
.build();
|
||||
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 4, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
|
||||
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
|
||||
break;
|
||||
case 3:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAttributionStringStreets() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.build();
|
||||
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 3, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
|
||||
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAttributionWithoutMapbox() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 2, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
|
||||
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAttributionArrayString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(new String[] {STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION})
|
||||
.build();
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 4, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
|
||||
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
|
||||
break;
|
||||
case 3:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHideImproveThisMapAttributionArrayString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(SATELLITE_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.build();
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 3, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseHideCopyrightAttributionArrayString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.build();
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 4, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
|
||||
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
|
||||
break;
|
||||
case 3:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputWithoutCopyRightString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.withImproveMap(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOutputWithCopyRightString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / © OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputWithoutCopyRightWithoutMapboxString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.withImproveMap(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputWithCopyRightWithoutMapboxString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputSatelliteString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap / DigitalGlobe",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortOpenStreetMapString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OSM / DigitalGlobe",
|
||||
attributionParser.createAttributionString(true)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortOpenStreetMapWithoutCopyrightString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OSM / DigitalGlobe",
|
||||
attributionParser.createAttributionString(true)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImproveThisMapString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(true)
|
||||
.withCopyrightSign(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OSM / Improve This Map",
|
||||
attributionParser.createAttributionString(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.mapbox.mapboxsdk.camera;
|
||||
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CameraPositionTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertNotNull("cameraPosition should not be null", cameraPosition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultTypedArrayBuilder() {
|
||||
TypedArray typedArray = null;
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
|
||||
assertEquals("bearing should match", -1, cameraPosition.bearing, DELTA);
|
||||
assertNull("latlng should be null", cameraPosition.target);
|
||||
assertEquals("tilt should match", -1, cameraPosition.tilt, DELTA);
|
||||
assertEquals("zoom should match", -1, cameraPosition.zoom, DELTA);
|
||||
assertNull("padding should be null", cameraPosition.padding);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypedArrayBuilder() {
|
||||
float bearing = 180;
|
||||
float zoom = 12;
|
||||
float latitude = 10;
|
||||
float longitude = 11;
|
||||
float tilt = 44;
|
||||
|
||||
TypedArray typedArray = mock(TypedArray.class);
|
||||
when(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraBearing, 0.0f)).thenReturn(bearing);
|
||||
when(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraTargetLat, 0.0f)).thenReturn(latitude);
|
||||
when(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraTargetLng, 0.0f)).thenReturn(longitude);
|
||||
when(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoom, 0.0f)).thenReturn(zoom);
|
||||
when(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraTilt, 0.0f)).thenReturn(tilt);
|
||||
doNothing().when(typedArray).recycle();
|
||||
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
|
||||
assertEquals("bearing should match", bearing, cameraPosition.bearing, DELTA);
|
||||
assertEquals("latlng should match", new LatLng(latitude, longitude), cameraPosition.target);
|
||||
assertEquals("tilt should match", tilt, cameraPosition.tilt, DELTA);
|
||||
assertEquals("zoom should match", zoom, cameraPosition.zoom, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertEquals("toString should match", "Target: LatLng [latitude=1.0, longitude=2.0, altitude=0.0], Zoom:3.0, "
|
||||
+ "Bearing:5.0, Tilt:4.0, Padding:[0.0, 500.0, 0.0, 0.0]", cameraPosition.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertEquals("hashCode should match", -420915327, cameraPosition.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomUpdateBuilder() {
|
||||
float zoomLevel = 5;
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder(
|
||||
(CameraUpdateFactory.ZoomUpdate) CameraUpdateFactory.zoomTo(zoomLevel));
|
||||
assertEquals("zoom should match", zoomLevel, builder.build().zoom, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionBearing = new CameraPosition(latLng, 3, 4, 9, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionTilt = new CameraPosition(latLng, 3, 9, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionZoom = new CameraPosition(latLng, 9, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionTarget = new CameraPosition(new LatLng(), 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionPadding = new CameraPosition(new LatLng(), 3, 4, 5, new double[] {0, 501, 0, 0});
|
||||
|
||||
assertEquals("cameraPosition should match itself", cameraPosition, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match null", null, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match object", new Object(), cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for bearing", cameraPositionBearing, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for tilt", cameraPositionTilt, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for zoom", cameraPositionZoom, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for target", cameraPositionTarget, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for padding", cameraPositionPadding, cameraPosition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
CameraPosition cameraPosition1 = new CameraPosition(new LatLng(1, 2), 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
Parcel parcel = Parcel.obtain();
|
||||
cameraPosition1.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
CameraPosition cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel);
|
||||
assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.mapbox.mapboxsdk.constants;
|
||||
|
||||
public class AppConstant {
|
||||
|
||||
public static final int STYLE_VERSION = 9;
|
||||
}
|
||||
@@ -0,0 +1,813 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
import com.mapbox.mapboxsdk.constants.GeometryConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LatLngBoundsTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
private LatLngBounds latLngBounds;
|
||||
private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
|
||||
private static final LatLng LAT_LNG_NOT_NULL_ISLAND = new LatLng(2, 2);
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
|
||||
latLngBoundsBuilder.include(LAT_LNG_NULL_ISLAND).include(LAT_LNG_NOT_NULL_ISLAND);
|
||||
assertNotNull("latLng should not be null", latLngBoundsBuilder.build());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidLatLngBoundsException.class)
|
||||
public void noLatLngs() {
|
||||
new LatLngBounds.Builder().build();
|
||||
}
|
||||
|
||||
@Test(expected = InvalidLatLngBoundsException.class)
|
||||
public void oneLatLngs() {
|
||||
new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void latitiudeSpan() {
|
||||
assertEquals("Span should be the same", 2, latLngBounds.getLatitudeSpan(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longitudeSpan() {
|
||||
assertEquals("Span should be the same", 2, latLngBounds.getLongitudeSpan(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void coordinateSpan() {
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanBuilder1() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -170))
|
||||
.include(new LatLng(-10, 170))
|
||||
.build();
|
||||
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanBuilder2() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(-10, -170))
|
||||
.include(new LatLng(10, 170))
|
||||
.build();
|
||||
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanFrom1() {
|
||||
latLngBounds = LatLngBounds.from(10, -170, -10, -190);
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 20),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanFrom2() {
|
||||
latLngBounds = LatLngBounds.from(10, 170, -10, -170);
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroLongitudeSpan() {
|
||||
latLngBounds = LatLngBounds.from(10, 10, -10, 10);
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 0),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter1() {
|
||||
latLngBounds = LatLngBounds.from(10, -175, -10, -195);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, -185), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter2() {
|
||||
latLngBounds = LatLngBounds.from(10, 195, -10, 175);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 185), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter3() {
|
||||
latLngBounds = LatLngBounds.from(10, -170, -10, -190);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, -180), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter4() {
|
||||
latLngBounds = LatLngBounds.from(10, 180, -10, 0);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 90), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter5() {
|
||||
latLngBounds = LatLngBounds.from(10, 180, -10, 0);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 90), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void centerForBoundsWithSameLongitude() {
|
||||
latLngBounds = LatLngBounds.from(10, 10, -10, 10);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 10), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void centerForBoundsWithSameLatitude() {
|
||||
latLngBounds = LatLngBounds.from(10, 10, 10, -10);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(10, 0), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void center() {
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(1, 1), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEmptySpan() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertFalse("Should not be empty", latLngBounds.isEmptySpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includeSameLatLngs() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals(latLngBounds.getNorthEast(), LAT_LNG_NOT_NULL_ISLAND);
|
||||
assertEquals(latLngBounds.getSouthWest(), LAT_LNG_NULL_ISLAND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toLatLngs() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
|
||||
assertArrayEquals("LatLngs should match",
|
||||
new LatLng[] {LAT_LNG_NOT_NULL_ISLAND, LAT_LNG_NULL_ISLAND},
|
||||
latLngBounds.toLatLngs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void include() {
|
||||
assertTrue("LatLng should be included", latLngBounds.contains(new LatLng(1, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includes() {
|
||||
List<LatLng> points = new ArrayList<>();
|
||||
points.add(LAT_LNG_NULL_ISLAND);
|
||||
points.add(LAT_LNG_NOT_NULL_ISLAND);
|
||||
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.includes(points)
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build();
|
||||
|
||||
assertEquals("LatLngBounds should match", latLngBounds1, latLngBounds2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOrderDoesNotMatter() {
|
||||
LatLngBounds sameLongitudeFirst = new LatLngBounds.Builder()
|
||||
.include(new LatLng(50, 10)) // southWest
|
||||
.include(new LatLng(60, 10))
|
||||
.include(new LatLng(60, 20)) // northEast
|
||||
.include(new LatLng(50, 20))
|
||||
.include(new LatLng(50, 10)) // southWest again
|
||||
.build();
|
||||
|
||||
LatLngBounds sameLatitudeFirst = new LatLngBounds.Builder()
|
||||
.include(new LatLng(50, 20))
|
||||
.include(new LatLng(50, 10)) // southWest
|
||||
.include(new LatLng(60, 10))
|
||||
.include(new LatLng(60, 20)) // northEast
|
||||
.include(new LatLng(50, 20))
|
||||
.build();
|
||||
|
||||
assertEquals(sameLatitudeFirst, sameLongitudeFirst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOverDateline1() {
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -170))
|
||||
.include(new LatLng(-10, -175))
|
||||
.include(new LatLng(0, -190))
|
||||
.build();
|
||||
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same",
|
||||
new LatLngSpan(20, 20), latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOverDateline2() {
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 170))
|
||||
.include(new LatLng(-10, 175))
|
||||
.include(new LatLng(0, 190))
|
||||
.build();
|
||||
|
||||
assertEquals("LatLngSpan should be the same",
|
||||
new LatLngSpan(20, 20), latLngBounds.getSpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOverDateline3() {
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -190))
|
||||
.include(new LatLng(-10, -170))
|
||||
.include(new LatLng(0, -180))
|
||||
.include(new LatLng(5, -180))
|
||||
.build();
|
||||
|
||||
assertEquals("LatLngSpan should be the same",
|
||||
new LatLngSpan(20, 20), latLngBounds.getSpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsNot() {
|
||||
assertFalse("LatLng should not be included",
|
||||
latLngBounds.contains(new LatLng(3, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsBoundsInWorld() {
|
||||
assertTrue("LatLngBounds should be contained in the world",
|
||||
LatLngBounds.world().contains(latLngBounds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worldSpan() {
|
||||
assertEquals("LatLngBounds world span should be 180, 360",
|
||||
GeometryConstants.LATITUDE_SPAN, LatLngBounds.world().getLatitudeSpan(), DELTA);
|
||||
assertEquals("LatLngBounds world span should be 180, 360",
|
||||
GeometryConstants.LONGITUDE_SPAN, LatLngBounds.world().getLongitudeSpan(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySpan() {
|
||||
LatLngBounds latLngBounds = LatLngBounds.from(
|
||||
GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE,
|
||||
GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE);
|
||||
assertTrue("LatLngBounds empty span", latLngBounds.isEmptySpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsBounds() {
|
||||
LatLngBounds inner = new LatLngBounds.Builder()
|
||||
.include(new LatLng(-5, -5))
|
||||
.include(new LatLng(5, 5))
|
||||
.build();
|
||||
LatLngBounds outer = new LatLngBounds.Builder()
|
||||
.include(new LatLng(-10, -10))
|
||||
.include(new LatLng(10, 10))
|
||||
.build();
|
||||
assertTrue(outer.contains(inner));
|
||||
assertFalse(inner.contains(outer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
assertEquals(2147483647, latLngBounds.hashCode(), -1946419200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equality() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals("equality should match", this.latLngBounds, latLngBounds);
|
||||
assertEquals("not equal to a different object type",
|
||||
this.latLngBounds.equals(LAT_LNG_NOT_NULL_ISLAND), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals(latLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersect() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(1, 1))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals("intersect should match", latLngBounds,
|
||||
latLngBounds.intersect(this.latLngBounds.getLatNorth(),
|
||||
this.latLngBounds.getLonEast(),
|
||||
this.latLngBounds.getLatSouth(),
|
||||
this.latLngBounds.getLonWest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectNot() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(new LatLng(9, 8))
|
||||
.build();
|
||||
assertNull(latLngBounds.intersect(this.latLngBounds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.intersect(200, 200, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectSouthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(0, 0, -10, -10)
|
||||
.intersect(0, 0, -200, -200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectSouthLessThanNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latNorth cannot be less than latSouth");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.intersect(0, 200, 20, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectEastLessThanWestCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("lonEast cannot be less than lonWest");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(10, -10, 0, 0)
|
||||
.intersect(0, 200, 20, 0);
|
||||
}
|
||||
|
||||
public void intersectEastDoesNotWrapCheck() {
|
||||
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(10, 210, 0, 0);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(90, 200, 0, 0);
|
||||
|
||||
LatLngBounds intersectLatLngBounds = LatLngBounds.from(10, 200, 0, 0);
|
||||
|
||||
assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds);
|
||||
assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectDoesNotWestWrapCheck() {
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(0, 0, -10, -210);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(0, 0, -90, -200);
|
||||
|
||||
LatLngBounds intersectLatLngBounds = LatLngBounds.from(0, 0, -10, -200);
|
||||
|
||||
assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds);
|
||||
assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerUnion() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(1, 1))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals("union should match", latLngBounds, latLngBounds.intersect(this.latLngBounds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outerUnion() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(new LatLng(9, 8))
|
||||
.build();
|
||||
assertEquals("outer union should match",
|
||||
latLngBounds.union(this.latLngBounds),
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 170))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 190))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine2() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 170))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 165))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine3() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 195))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 190))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine4() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -160))
|
||||
.include(new LatLng(0, -200))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, -170))
|
||||
.include(new LatLng(-10, -175))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -200))
|
||||
.include(new LatLng(-10, -160))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine5() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 200))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 170))
|
||||
.include(new LatLng(-10, 175))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLineReturnLongerThanWorldLonSpan() {
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(10, 200, -10, -10);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(10, 10, -10, -200);
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1, union2);
|
||||
assertEquals(union1, LatLngBounds.from(10, 200, -10, -200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds unionLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.union(200, 200, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionSouthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds unionLatLngBounds =
|
||||
LatLngBounds.from(0, 0, -10, -10)
|
||||
.union(0, 0, -200, -200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionSouthLessThanNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latNorth cannot be less than latSouth");
|
||||
|
||||
LatLngBounds unionLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.union(0, 200, 20, 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void unionEastDoesNotWrapCheck() {
|
||||
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(10, 10, 0, 0);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(90, 200, 0, 0);
|
||||
LatLngBounds unionLatLngBounds = LatLngBounds.from(90, 200, 0, 0);
|
||||
|
||||
assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds);
|
||||
assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionWestDoesNotWrapCheck() {
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(0, 0, -10, -10);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(0, 0, -90, -200);
|
||||
|
||||
LatLngBounds unionLatLngBounds = LatLngBounds.from(0, 0, -90, -200);
|
||||
|
||||
assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds);
|
||||
assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void northWest() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("NorthWest should match", latLngBounds.getNorthWest(), new LatLng(maxLat, minLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void southWest() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("SouthWest should match", latLngBounds.getSouthWest(), new LatLng(minLat, minLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void northEast() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("NorthEast should match", latLngBounds.getNorthEast(), new LatLng(maxLat, maxLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void southEast() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("SouthEast should match", latLngBounds.getSouthEast(), new LatLng(minLat, maxLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(new LatLng(9, 8))
|
||||
.build();
|
||||
Parcelable parcel = MockParcel.obtain(latLngBounds);
|
||||
assertEquals("Parcel should match original object", parcel, latLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromTileID() {
|
||||
LatLngBounds bounds = LatLngBounds.from(0, 0, 0);
|
||||
assertEquals(GeometryConstants.MIN_WRAP_LONGITUDE, bounds.getLonWest(), DELTA);
|
||||
assertEquals(GeometryConstants.MIN_MERCATOR_LATITUDE, bounds.getLatSouth(), DELTA);
|
||||
assertEquals(GeometryConstants.MAX_WRAP_LONGITUDE, bounds.getLonEast(), DELTA);
|
||||
assertEquals(GeometryConstants.MAX_MERCATOR_LATITUDE, bounds.getLatNorth(), DELTA);
|
||||
|
||||
bounds = LatLngBounds.from(10, 288, 385);
|
||||
assertEquals(-78.75, bounds.getLonWest(), DELTA);
|
||||
assertEquals(40.446947059600497, bounds.getLatSouth(), DELTA);
|
||||
assertEquals(-78.3984375, bounds.getLonEast(), DELTA);
|
||||
assertEquals(40.713955826286039, bounds.getLatNorth(), DELTA);
|
||||
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksNorthLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
LatLngBounds.from(Double.NaN, 0, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksEastLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
LatLngBounds.from(0, Double.NaN, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksNorthLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(95, 0, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksNorthLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(-95, 0, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksEastLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
LatLngBounds.from(0, Double.POSITIVE_INFINITY, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksSouthLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
LatLngBounds.from(20, 20, Double.NaN, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksWesttLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
LatLngBounds.from(20, 20, 0, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksSouthLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(20, 20, 95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksSouthLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(20, 20, -95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksWestLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
LatLngBounds.from(20, 20, 0, Double.POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorCheckLatSouthGreaterLatNorth() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latNorth cannot be less than latSouth");
|
||||
LatLngBounds.from(0, 20, 20, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorCheckLonWestGreaterLonEast() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("lonEast cannot be less than lonWest");
|
||||
LatLngBounds.from(20, 0, 0, 20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class LatLngSpanTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
assertNotNull("latLngSpan should not be null", latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
assertEquals("latLngSpan is not equal to a LatLng", latLngSpan.equals(LAT_LNG_NULL_ISLAND), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(latitude, 0.0);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, longitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeMethod() {
|
||||
double latitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
latLngSpan.setLatitudeSpan(latitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeMethod() {
|
||||
double longitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
latLngSpan.setLongitudeSpan(longitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
LatLngSpan object = new LatLngSpan(1, 2);
|
||||
Parcelable parcel = MockParcel.obtain(object);
|
||||
assertEquals("parcel should match initial object", object, parcel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.location.Location;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class LatLngTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng latLng = new LatLng(0.0, 0.0);
|
||||
assertNotNull("latLng should not be null", latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeEmptyConstructor() {
|
||||
LatLng latLng = new LatLng();
|
||||
assertEquals("latitude default value", latLng.getLatitude(), 0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeEmptyConstructor() {
|
||||
LatLng latLng = new LatLng();
|
||||
assertEquals("longitude default value", latLng.getLongitude(), 0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeEmptyConstructor() {
|
||||
LatLng latLng1 = new LatLng();
|
||||
assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.2;
|
||||
LatLng latLng = new LatLng(latitude, 3.4);
|
||||
assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 3.4;
|
||||
LatLng latLng = new LatLng(1.2, longitude);
|
||||
assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeConstructor() {
|
||||
LatLng latLng1 = new LatLng(1.2, 3.4);
|
||||
assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA);
|
||||
|
||||
double altitude = 5.6;
|
||||
LatLng latLng2 = new LatLng(1.2, 3.4, altitude);
|
||||
assertEquals("altitude default value", latLng2.getAltitude(), altitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetter() {
|
||||
LatLng latLng = new LatLng(1.2, 3.4);
|
||||
latLng.setLatitude(3);
|
||||
assertEquals("latitude should match", 3, latLng.getLatitude(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSetter() {
|
||||
LatLng latLng = new LatLng(1.2, 3.4);
|
||||
latLng.setLongitude(3);
|
||||
assertEquals("longitude should match", 3, latLng.getLongitude(), DELTA);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
new LatLng(Double.NaN, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
new LatLng(0, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng(95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng(-95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
new LatLng(0, Double.POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetterChecksNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
new LatLng().setLatitude(Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSetterChecksNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
new LatLng().setLongitude(Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetterChecksGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng().setLatitude(95);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetterChecksLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng().setLatitude(-95);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSetterChecksInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
new LatLng().setLongitude(Double.NEGATIVE_INFINITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeSetter() {
|
||||
LatLng latLng = new LatLng(1.2, 3.4);
|
||||
latLng.setAltitude(3);
|
||||
assertEquals("altitude should match", 3, latLng.getAltitude(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLngConstructor() {
|
||||
LatLng latLng1 = new LatLng(1.2, 3.4);
|
||||
LatLng latLng2 = new LatLng(latLng1);
|
||||
assertEquals("latLng should match", latLng1, latLng2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistanceTo() {
|
||||
LatLng latLng1 = new LatLng(0.0, 0.0);
|
||||
LatLng latLng2 = new LatLng(1.0, 1.0);
|
||||
assertEquals("distances should match",
|
||||
latLng1.distanceTo(latLng2),
|
||||
157298.7453847275, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistanceToSamePoint() {
|
||||
LatLng latLng1 = new LatLng(40.71199035644531, -74.0081);
|
||||
LatLng latLng2 = new LatLng(40.71199035644531, -74.0081);
|
||||
double distance = latLng1.distanceTo(latLng2);
|
||||
assertEquals("distance should match", 0.0, distance, DELTA);
|
||||
}
|
||||
|
||||
// Regression test for #14216
|
||||
@Test
|
||||
public void testDistanceToClosePointNotNaN() {
|
||||
LatLng latLng = new LatLng(40.00599, -105.29261);
|
||||
LatLng other = new LatLng(40.005990000000025, -105.29260999999997);
|
||||
double distance = latLng.distanceTo(other);
|
||||
assertNotEquals(distance, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocationProvider() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
|
||||
// Mock the location class
|
||||
Location locationMocked = mock(Location.class);
|
||||
when(locationMocked.getLatitude()).thenReturn(latitude);
|
||||
when(locationMocked.getLongitude()).thenReturn(longitude);
|
||||
when(locationMocked.getAltitude()).thenReturn(altitude);
|
||||
|
||||
// Test the constructor
|
||||
LatLng latLng = new LatLng(locationMocked);
|
||||
assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA);
|
||||
assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA);
|
||||
assertEquals("altitude should match", latLng.getAltitude(), altitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("hash code should match", latLng.hashCode(), -151519232);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("string should match",
|
||||
latLng.toString(),
|
||||
"LatLng [latitude=1.2, longitude=3.4, altitude=5.6]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsOther() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng1 = new LatLng(latitude, longitude, altitude);
|
||||
LatLng latLng2 = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("LatLng should match", latLng1, latLng2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsItself() {
|
||||
LatLng latLng = new LatLng(1, 2, 3);
|
||||
assertEquals("LatLng should match", latLng, latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEquals() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
assertNotEquals("LatLng should match", latLng, new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
LatLng latLng = new LatLng(45.0, -185.0);
|
||||
Parcelable parcel = MockParcel.obtain(latLng);
|
||||
assertEquals("parcel should match initial object", latLng, parcel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapped() {
|
||||
LatLng originalLatLng = new LatLng(45.0, -185.0);
|
||||
LatLng newLatlng = originalLatLng.wrap();
|
||||
assertNotSame(" new wrapped LatLng is created", originalLatLng, newLatlng);
|
||||
assertEquals("longitude wrapped value", originalLatLng.getLongitude(), -185.0, DELTA);
|
||||
assertEquals("longitude wrapped value", newLatlng.getLongitude(), 175.0, DELTA);
|
||||
|
||||
newLatlng = new LatLng(45.0, 180.0).wrap();
|
||||
assertEquals("longitude wrapped max value", newLatlng.getLongitude(), 180.0, DELTA);
|
||||
|
||||
newLatlng = new LatLng(45.0, -180.0).wrap();
|
||||
assertEquals("longitude wrapped min value", newLatlng.getLongitude(), -180.0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnnecessaryWrapped() {
|
||||
LatLng latLng = new LatLng(45.0, 50.0).wrap();
|
||||
assertEquals("longitude wrapped value", latLng.getLongitude(), 50.0, DELTA);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ProjectedMetersTest {
|
||||
|
||||
private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0);
|
||||
assertNotNull("projectedMeters should not be null", projectedMeters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0);
|
||||
assertEquals("projectedMeters is not equal to a LatLng", projectedMeters.equals(LAT_LNG_NULL_ISLAND), false);
|
||||
assertEquals("projectedMeters is equal to itself", projectedMeters.equals(projectedMeters), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNorthing() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(1.0, 0.0);
|
||||
assertEquals("northing should be 1", 1, projectedMeters.getNorthing(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEasting() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 1.0);
|
||||
assertEquals("easting should be 1", 1, projectedMeters.getEasting(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
ProjectedMeters projectedMeters1 = new ProjectedMeters(1, 2);
|
||||
ProjectedMeters projectedMeters2 = new ProjectedMeters(projectedMeters1);
|
||||
assertEquals("projectedmeters should match", projectedMeters1, projectedMeters2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
ProjectedMeters meters = new ProjectedMeters(1, 2);
|
||||
assertEquals("hashcode should match", -1048576, meters.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
ProjectedMeters meters = new ProjectedMeters(1, 1);
|
||||
assertEquals("toString should match", "ProjectedMeters [northing=1.0, easting=1.0]", meters.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
ProjectedMeters meters = new ProjectedMeters(1, 1);
|
||||
Parcelable parcel = MockParcel.obtain(meters);
|
||||
assertEquals("parcel should match initial object", meters, parcel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class VisibleRegionTest {
|
||||
|
||||
private static final LatLng FAR_LEFT = new LatLng(52, -12);
|
||||
private static final LatLng NEAR_LEFT = new LatLng(34, -12);
|
||||
private static final LatLng FAR_RIGHT = new LatLng(52, 26);
|
||||
private static final LatLng NEAR_RIGHT = new LatLng(34, 26);
|
||||
private static final LatLngBounds BOUNDS =
|
||||
new LatLngBounds.Builder().include(FAR_LEFT).include(FAR_RIGHT).include(NEAR_LEFT).include(NEAR_RIGHT).build();
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertNotNull("region should not be null", region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("visibleRegion is not equal to a LatLng", region.equals(FAR_LEFT), false);
|
||||
assertEquals("visibleRegion is equal to itself", region.equals(region), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFarLeftConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.farLeft, FAR_LEFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNearLeftConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.nearLeft, NEAR_LEFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFarRightConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.farRight, FAR_RIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNearRightConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.nearRight, NEAR_RIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLngBoundsConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLngBounds should match", region.latLngBounds, BOUNDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
VisibleRegion regionLeft = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
VisibleRegion regionRight = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("VisibleRegions should match", regionLeft, regionRight);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("hashcode should match", -923534102, region.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("string should match",
|
||||
"[farLeft [LatLng [latitude=52.0, longitude=-12.0, altitude=0.0]], "
|
||||
+ "farRight [LatLng [latitude=52.0, longitude=26.0, altitude=0.0]], "
|
||||
+ "nearLeft [LatLng [latitude=34.0, longitude=-12.0, altitude=0.0]], "
|
||||
+ "nearRight [LatLng [latitude=34.0, longitude=26.0, altitude=0.0]], "
|
||||
+ "latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]",
|
||||
region.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
Parcelable parcel = MockParcel.obtain(region);
|
||||
assertEquals("parcel should match initial object", region, parcel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEventListener;
|
||||
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 com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.SENSOR_DELAY_MICROS;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
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;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CompassEngineTest {
|
||||
|
||||
private LocationComponentCompassEngine compassEngine;
|
||||
|
||||
@Mock
|
||||
private WindowManager windowManager;
|
||||
|
||||
@Mock
|
||||
private SensorManager sensorManager;
|
||||
|
||||
@Mock
|
||||
private Sensor compassSensor;
|
||||
|
||||
@Mock
|
||||
private CompassListener compassListener;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)).thenReturn(compassSensor);
|
||||
compassEngine = new LocationComponentCompassEngine(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 LocationComponentCompassEngine(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 LocationComponentCompassEngine(windowManager, sensorManager);
|
||||
|
||||
verify(sensorManager, times(1)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listener_registerOnAdd() {
|
||||
compassEngine.addCompassListener(compassListener);
|
||||
verify(sensorManager)
|
||||
.registerListener(any(SensorEventListener.class), eq(compassSensor), eq(SENSOR_DELAY_MICROS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listener_unregisterOnRemove() {
|
||||
compassEngine.addCompassListener(compassListener);
|
||||
compassEngine.removeCompassListener(compassListener);
|
||||
verify(sensorManager).unregisterListener(any(SensorEventListener.class), eq(compassSensor));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.animation.Animator
|
||||
import android.location.Location
|
||||
import android.util.SparseArray
|
||||
import android.view.animation.LinearInterpolator
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION
|
||||
import com.mapbox.mapboxsdk.location.MapboxAnimator.*
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Projection
|
||||
import io.mockk.*
|
||||
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 LocationAnimatorCoordinatorTest {
|
||||
|
||||
private lateinit var locationAnimatorCoordinator: LocationAnimatorCoordinator
|
||||
private val cameraPosition: CameraPosition = CameraPosition.DEFAULT
|
||||
|
||||
private val animatorProvider: MapboxAnimatorProvider = mockk()
|
||||
private val animatorSetProvider: MapboxAnimatorSetProvider = mockk()
|
||||
|
||||
private val projection: Projection = mockk()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
locationAnimatorCoordinator = LocationAnimatorCoordinator(projection, animatorSetProvider, animatorProvider)
|
||||
configureAnimatorProvider()
|
||||
every { projection.getMetersPerPixelAtLatitude(any()) } answers { 1.0 }
|
||||
every { animatorSetProvider.startAnimation(any(), any(), any()) } answers {}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(getListenerHoldersSet(
|
||||
ANIMATOR_LAYER_LATLNG,
|
||||
ANIMATOR_CAMERA_LATLNG,
|
||||
ANIMATOR_LAYER_GPS_BEARING,
|
||||
ANIMATOR_LAYER_COMPASS_BEARING,
|
||||
ANIMATOR_CAMERA_GPS_BEARING,
|
||||
ANIMATOR_CAMERA_COMPASS_BEARING,
|
||||
ANIMATOR_LAYER_ACCURACY,
|
||||
ANIMATOR_ZOOM,
|
||||
ANIMATOR_TILT
|
||||
))
|
||||
}
|
||||
|
||||
private fun configureAnimatorProvider() {
|
||||
// workaround https://github.com/mockk/mockk/issues/229#issuecomment-457816131
|
||||
registerInstanceFactory { AnimationsValueChangeListener<Float> {} }
|
||||
registerInstanceFactory { AnimationsValueChangeListener<LatLng> {} }
|
||||
val previousFloatSlot = slot<Float>()
|
||||
val targetFloatSlot = slot<Float>()
|
||||
val listenerSlot = slot<MapboxAnimator.AnimationsValueChangeListener<*>>()
|
||||
val maxFpsSlot = slot<Int>()
|
||||
every {
|
||||
animatorProvider.floatAnimator(capture(previousFloatSlot), capture(targetFloatSlot), capture(listenerSlot), capture(maxFpsSlot))
|
||||
} answers {
|
||||
MapboxFloatAnimator(previousFloatSlot.captured, targetFloatSlot.captured, listenerSlot.captured, maxFpsSlot.captured)
|
||||
}
|
||||
|
||||
val previousLatLngSlot = slot<LatLng>()
|
||||
val targetLatLngSlot = slot<LatLng>()
|
||||
every {
|
||||
animatorProvider.latLngAnimator(capture(previousLatLngSlot), capture(targetLatLngSlot), capture(listenerSlot), capture(maxFpsSlot))
|
||||
} answers {
|
||||
MapboxLatLngAnimator(previousLatLngSlot.captured, targetLatLngSlot.captured, listenerSlot.captured, maxFpsSlot.captured)
|
||||
}
|
||||
|
||||
val callback = slot<MapboxMap.CancelableCallback>()
|
||||
every {
|
||||
animatorProvider.cameraAnimator(capture(previousFloatSlot), capture(targetFloatSlot), capture(listenerSlot), capture(callback))
|
||||
} answers {
|
||||
MapboxCameraAnimatorAdapter(previousFloatSlot.captured, targetFloatSlot.captured, listenerSlot.captured, callback.captured)
|
||||
}
|
||||
every {
|
||||
animatorProvider.cameraAnimator(capture(previousFloatSlot), capture(targetFloatSlot), capture(listenerSlot), null)
|
||||
} answers {
|
||||
MapboxCameraAnimatorAdapter(previousFloatSlot.captured, targetFloatSlot.captured, listenerSlot.captured, null)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorsAreCreated() {
|
||||
locationAnimatorCoordinator.feedNewLocation(Location(""), cameraPosition, false)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_LATLNG] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_GPS_BEARING] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_LATLNG] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 35f
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val cameraLatLngTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_LATLNG]?.target as LatLng
|
||||
assertEquals(cameraLatLngTarget.latitude, cameraLatLngTarget.latitude)
|
||||
|
||||
val layerLatLngTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_LATLNG]?.target as LatLng
|
||||
assertEquals(layerLatLngTarget.latitude, layerLatLngTarget.latitude)
|
||||
|
||||
val cameraBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_GPS_BEARING]?.target as Float
|
||||
assertEquals(location.bearing, cameraBearingTarget)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(location.bearing, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue_correctRotation_1() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 0f
|
||||
|
||||
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
|
||||
every { animator.animatedValue } returns 270f
|
||||
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)
|
||||
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(360f, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue_correctRotation_2() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 90f
|
||||
|
||||
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
|
||||
every { animator.animatedValue } returns 280f
|
||||
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)
|
||||
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(450f, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue_correctRotation_3() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 300f
|
||||
|
||||
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
|
||||
every { animator.animatedValue } returns 450f
|
||||
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)
|
||||
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(-60f, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue_correctRotation_4() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 350f
|
||||
|
||||
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
|
||||
every { animator.animatedValue } returns 10f
|
||||
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)
|
||||
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(-10f, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue_correctRotation_5() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 90f
|
||||
|
||||
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
|
||||
every { animator.animatedValue } returns -280f
|
||||
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)
|
||||
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(90f, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_animatorValue_correctRotation_6() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 270f
|
||||
|
||||
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
|
||||
every { animator.animatedValue } returns -350f
|
||||
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)
|
||||
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(-90f, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_isNorth_animatorsAreCreated() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 35f
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, false)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_LATLNG] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_GPS_BEARING] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_LATLNG] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewLocation_isNorth_animatorValue() {
|
||||
val location = Location("")
|
||||
location.latitude = 51.0
|
||||
location.longitude = 17.0
|
||||
location.bearing = 35f
|
||||
locationAnimatorCoordinator.feedNewLocation(location, cameraPosition, true)
|
||||
|
||||
val cameraLatLngTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_LATLNG]?.target as LatLng
|
||||
assertEquals(cameraLatLngTarget.latitude, cameraLatLngTarget.latitude)
|
||||
|
||||
val layerLatLngTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_LATLNG]?.target as LatLng
|
||||
assertEquals(layerLatLngTarget.latitude, layerLatLngTarget.latitude)
|
||||
|
||||
val cameraBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_GPS_BEARING]?.target as Float
|
||||
assertEquals(0f, cameraBearingTarget)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_GPS_BEARING]?.target as Float
|
||||
assertEquals(location.bearing, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewCompassBearing_animatorsAreCreated() {
|
||||
locationAnimatorCoordinator.feedNewCompassBearing(77f, cameraPosition)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_COMPASS_BEARING] != null)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_COMPASS_BEARING] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewCompassBearing_animatorValue() {
|
||||
val bearing = 77f
|
||||
locationAnimatorCoordinator.feedNewCompassBearing(bearing, cameraPosition)
|
||||
|
||||
val cameraBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_COMPASS_BEARING]?.target as Float
|
||||
assertEquals(bearing, cameraBearingTarget)
|
||||
|
||||
val layerBearingTarget = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_COMPASS_BEARING]?.target as Float
|
||||
assertEquals(bearing, layerBearingTarget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewAccuracyRadius_animatorsCreated() {
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(150f, false)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewAccuracyRadius_animatorValue() {
|
||||
val accuracy = 150f
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(accuracy, false)
|
||||
|
||||
val layerAccuracy = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]?.target as Float
|
||||
assertEquals(layerAccuracy, accuracy)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewAccuracyRadius_noAnimation_animatorsCreated() {
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(150f, true)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewAccuracyRadius_noAnimation_animatorValue() {
|
||||
val accuracy = 150f
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(accuracy, true)
|
||||
|
||||
val layerAccuracy = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]?.target as Float
|
||||
assertEquals(layerAccuracy, accuracy)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewZoomLevel_animatorsCreated() {
|
||||
locationAnimatorCoordinator.feedNewZoomLevel(
|
||||
15.0,
|
||||
cameraPosition,
|
||||
DEFAULT_TRACKING_ZOOM_ANIM_DURATION,
|
||||
null
|
||||
)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_ZOOM] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewZoomLevel_animatorValue() {
|
||||
val zoom = 15.0f
|
||||
locationAnimatorCoordinator.feedNewZoomLevel(
|
||||
zoom.toDouble(),
|
||||
cameraPosition,
|
||||
DEFAULT_TRACKING_ZOOM_ANIM_DURATION,
|
||||
null
|
||||
)
|
||||
|
||||
val animator = locationAnimatorCoordinator.animatorArray[ANIMATOR_ZOOM]
|
||||
assertEquals(zoom, animator.target)
|
||||
verify { animatorSetProvider.startAnimation(eq(listOf(animator)), any<LinearInterpolator>(), DEFAULT_TRACKING_ZOOM_ANIM_DURATION) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewTiltLevel_animatorsCreated() {
|
||||
locationAnimatorCoordinator.feedNewTilt(
|
||||
30.0,
|
||||
cameraPosition,
|
||||
DEFAULT_TRACKING_TILT_ANIM_DURATION,
|
||||
null
|
||||
)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_TILT] != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewTiltLevel_animatorValue() {
|
||||
val tilt = 30.0f
|
||||
locationAnimatorCoordinator.feedNewTilt(
|
||||
tilt.toDouble(),
|
||||
cameraPosition,
|
||||
DEFAULT_TRACKING_TILT_ANIM_DURATION,
|
||||
null
|
||||
)
|
||||
|
||||
val animator = locationAnimatorCoordinator.animatorArray[ANIMATOR_TILT]
|
||||
assertEquals(tilt, animator.target)
|
||||
verify { animatorSetProvider.startAnimation(eq(listOf(animator)), any<LinearInterpolator>(), DEFAULT_TRACKING_TILT_ANIM_DURATION) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cancelAllAnimators() {
|
||||
locationAnimatorCoordinator.feedNewLocation(Location(""), cameraPosition, true)
|
||||
locationAnimatorCoordinator.cancelAllAnimations()
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_LATLNG] == null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cancelZoomAnimators() {
|
||||
locationAnimatorCoordinator.feedNewZoomLevel(
|
||||
15.0,
|
||||
cameraPosition,
|
||||
DEFAULT_TRACKING_ZOOM_ANIM_DURATION,
|
||||
null
|
||||
)
|
||||
locationAnimatorCoordinator.cancelZoomAnimation()
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_ZOOM] == null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cancelTiltAnimation() {
|
||||
locationAnimatorCoordinator.feedNewTilt(
|
||||
30.0,
|
||||
cameraPosition,
|
||||
DEFAULT_TRACKING_TILT_ANIM_DURATION,
|
||||
null
|
||||
)
|
||||
|
||||
locationAnimatorCoordinator.cancelTiltAnimation()
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray[ANIMATOR_TILT] == null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetAllCameraAnimations_empty() {
|
||||
locationAnimatorCoordinator.resetAllCameraAnimations(cameraPosition, false)
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray.size() == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetAllLayerAnimations_empty() {
|
||||
locationAnimatorCoordinator.resetAllLayerAnimations()
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray.size() == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addNewListener() {
|
||||
val listener = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder = AnimatorListenerHolder(RenderMode.NORMAL, listener)
|
||||
val set = HashSet<AnimatorListenerHolder>().also {
|
||||
it.add(holder)
|
||||
}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(set)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.listeners.contains(listener))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateListeners() {
|
||||
val listener = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder = AnimatorListenerHolder(RenderMode.NORMAL, listener)
|
||||
val set = HashSet<AnimatorListenerHolder>().also {
|
||||
it.add(holder)
|
||||
}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(set)
|
||||
|
||||
val listener2 = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder2 = AnimatorListenerHolder(RenderMode.NORMAL, listener2)
|
||||
val listener3 = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder3 = AnimatorListenerHolder(CameraMode.TRACKING_GPS, listener3)
|
||||
val set2 = HashSet<AnimatorListenerHolder>().also {
|
||||
it.add(holder2)
|
||||
it.add(holder3)
|
||||
}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(set2)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.listeners.size() == 2)
|
||||
assertTrue(locationAnimatorCoordinator.listeners.contains(listener2))
|
||||
assertTrue(locationAnimatorCoordinator.listeners.contains(listener3))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewCompassBearing_withAnimation() {
|
||||
locationAnimatorCoordinator.setCompassAnimationEnabled(true)
|
||||
locationAnimatorCoordinator.feedNewCompassBearing(77f, cameraPosition)
|
||||
|
||||
val animators = mutableListOf<Animator>(
|
||||
locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_COMPASS_BEARING],
|
||||
locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_COMPASS_BEARING])
|
||||
|
||||
verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(LocationComponentConstants.COMPASS_UPDATE_RATE_MS)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewCompassBearing_withoutAnimation() {
|
||||
locationAnimatorCoordinator.setCompassAnimationEnabled(false)
|
||||
locationAnimatorCoordinator.feedNewCompassBearing(77f, cameraPosition)
|
||||
|
||||
val animators = mutableListOf<Animator>(
|
||||
locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_COMPASS_BEARING],
|
||||
locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_COMPASS_BEARING])
|
||||
|
||||
verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(0)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewAccuracy_withAnimation() {
|
||||
locationAnimatorCoordinator.setAccuracyAnimationEnabled(true)
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(150f, false)
|
||||
|
||||
val animators = mutableListOf<Animator>(
|
||||
locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY])
|
||||
|
||||
verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(LocationComponentConstants.ACCURACY_RADIUS_ANIMATION_DURATION)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun feedNewAccuracy_withoutAnimation() {
|
||||
locationAnimatorCoordinator.setAccuracyAnimationEnabled(false)
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(150f, false)
|
||||
|
||||
val animators = mutableListOf<Animator>(
|
||||
locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY])
|
||||
|
||||
verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(0)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxFps_setter() {
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(5)
|
||||
assertEquals(5, locationAnimatorCoordinator.maxAnimationFps)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxFps_moreThanZeroRequired() {
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(0)
|
||||
assertEquals(Int.MAX_VALUE, locationAnimatorCoordinator.maxAnimationFps)
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(-1)
|
||||
assertEquals(Int.MAX_VALUE, locationAnimatorCoordinator.maxAnimationFps)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxFps_givenToAnimator() {
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(5)
|
||||
locationAnimatorCoordinator.feedNewLocation(Location(""), cameraPosition, false)
|
||||
verify { animatorProvider.latLngAnimator(any(), any(), any(), 5) }
|
||||
verify { animatorProvider.floatAnimator(any(), any(), any(), 5) }
|
||||
}
|
||||
|
||||
private fun getListenerHoldersSet(vararg animatorTypes: Int): Set<AnimatorListenerHolder> {
|
||||
return HashSet<AnimatorListenerHolder>().also {
|
||||
for (type in animatorTypes) {
|
||||
it.add(AnimatorListenerHolder(type, mockk()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <E> SparseArray<E>.contains(listener: AnimationsValueChangeListener<*>?): Boolean {
|
||||
for (i in 0 until this.size()) {
|
||||
val element = this.get(this.keyAt(i))
|
||||
if (element == listener) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,119 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
|
||||
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.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LocationComponentActivationOptionsTest {
|
||||
|
||||
@Mock
|
||||
private Context context;
|
||||
@Mock
|
||||
private TypedArray array;
|
||||
@Mock
|
||||
private Resources resources;
|
||||
@Mock
|
||||
private Style style;
|
||||
|
||||
@Rule
|
||||
public MockitoRule mockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@NonNull
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(context.obtainStyledAttributes(R.style.mapbox_LocationComponent, R.styleable.mapbox_LocationComponent))
|
||||
.thenReturn(array);
|
||||
when(array.getResourceId(R.styleable.mapbox_LocationComponent_mapbox_foregroundDrawable, -1))
|
||||
.thenReturn(R.drawable.mapbox_user_icon);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanity() throws Exception {
|
||||
when(style.isFullyLoaded()).thenReturn(true);
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build();
|
||||
assertNotNull(locationComponentOptions);
|
||||
|
||||
LocationComponentActivationOptions locationComponentActivationOptions =
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build();
|
||||
assertNotNull(locationComponentActivationOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includingBothStyleResAndComponentOptions_causesExceptionToBeThrown() throws Exception {
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("You've provided both a style resource and a LocationComponentOptions"
|
||||
+ " object to the LocationComponentActivationOptions builder. You can't use both and "
|
||||
+ "you must choose one of the two to style the LocationComponent.");
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build();
|
||||
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.styleRes(R.style.mapbox_LocationComponent)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullContext_causesExceptionToBeThrown() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Context in LocationComponentActivationOptions is null.");
|
||||
|
||||
LocationComponentActivationOptions.builder(null, style)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullStyle_causesExceptionToBeThrown() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Style in LocationComponentActivationOptions is null. Make sure the Style object isn't null."
|
||||
+ " Wait for the map to fully load before passing the Style object to LocationComponentActivationOptions.");
|
||||
|
||||
LocationComponentActivationOptions.builder(context, null)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locationComponent_exceptionThrownWithDefaultLocationEngineButNotFullyLoadedStyle() throws Exception {
|
||||
|
||||
when(style.isFullyLoaded()).thenReturn(false);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Style in LocationComponentActivationOptions isn't fully loaded. Wait for the "
|
||||
+ "map to fully load before passing the Style object to "
|
||||
+ "LocationComponentActivationOptions.");
|
||||
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
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 LocationComponentOptionsTest {
|
||||
|
||||
@Mock
|
||||
private Context context;
|
||||
@Mock
|
||||
private TypedArray array;
|
||||
@Mock
|
||||
private Resources resources;
|
||||
|
||||
@NonNull
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(context.obtainStyledAttributes(R.style.mapbox_LocationComponent, R.styleable.mapbox_LocationComponent))
|
||||
.thenReturn(array);
|
||||
when(array.getResourceId(R.styleable.mapbox_LocationComponent_mapbox_foregroundDrawable, -1))
|
||||
.thenReturn(R.drawable.mapbox_user_icon);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanity() throws Exception {
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build();
|
||||
assertNotNull(locationComponentOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passingOutOfRangeAccuracyAlpha_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Accuracy alpha value must be between 0.0 and "
|
||||
+ "1.0.");
|
||||
LocationComponentOptions.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");
|
||||
LocationComponentOptions.builder(context)
|
||||
.elevation(-500)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passingBothLayerPositionOptions_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("You cannot set both layerAbove and layerBelow options."
|
||||
+ "Choose one or the other.");
|
||||
LocationComponentOptions.builder(context)
|
||||
.layerAbove("above")
|
||||
.layerBelow("below")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import junit.framework.Assert.assertFalse
|
||||
import junit.framework.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class LocationComponentPositionManagerTest {
|
||||
|
||||
private lateinit var style: Style
|
||||
private lateinit var layer: Layer
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
style = mockk(relaxed = true)
|
||||
layer = mockk(relaxed = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_noChange_null() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_noChange_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
val requiresUpdate = positionManager.update("above", null)
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_noChange_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
val requiresUpdate = positionManager.update(null, "below")
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromNull_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update("above", null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromNull_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update(null, "below")
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_toNull_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_toNull_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromValue_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above1", null)
|
||||
val requiresUpdate = positionManager.update("above2", null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromValue_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below1")
|
||||
val requiresUpdate = positionManager.update(null, "below2")
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_noModifier() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayer(layer) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerAbove(layer, "above") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerBelow(layer, "below") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_afterUpdate_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.update("above", null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerAbove(layer, "above") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_afterUpdate_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.update(null, "below")
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerBelow(layer, "below") }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
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.android.core.location.LocationEngine
|
||||
import com.mapbox.android.core.location.LocationEngineRequest
|
||||
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.modes.CameraMode
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.Transform
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentCaptor
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class LocationComponentTest {
|
||||
private lateinit var locationComponent: LocationComponent
|
||||
|
||||
@Mock
|
||||
private lateinit var locationComponentOptions: LocationComponentOptions
|
||||
|
||||
@Mock
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
|
||||
@Mock
|
||||
private lateinit var transform: Transform
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var locationEngine: LocationEngine
|
||||
|
||||
@Mock
|
||||
private lateinit var locationEngineRequest: LocationEngineRequest
|
||||
|
||||
@Mock
|
||||
private lateinit var currentListener: LocationComponent.CurrentLocationEngineCallback
|
||||
|
||||
@Mock
|
||||
private lateinit var lastListener: LocationComponent.LastLocationEngineCallback
|
||||
|
||||
@Mock
|
||||
private lateinit var compassEngine: CompassEngine
|
||||
|
||||
@Mock
|
||||
private lateinit var locationLayerController: LocationLayerController
|
||||
|
||||
@Mock
|
||||
private lateinit var locationCameraController: LocationCameraController
|
||||
|
||||
@Mock
|
||||
private lateinit var locationAnimatorCoordinator: LocationAnimatorCoordinator
|
||||
|
||||
@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>
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
developerAnimationListeners = mutableListOf()
|
||||
locationComponent = LocationComponent(mapboxMap, transform, developerAnimationListeners, 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, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
|
||||
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
|
||||
|
||||
doReturn(mock(TypedArray::class.java)).`when`(context)
|
||||
.obtainStyledAttributes(R.style.mapbox_LocationComponent, R.styleable.mapbox_LocationComponent)
|
||||
|
||||
val resources = mock(Resources::class.java)
|
||||
|
||||
doReturn(resources).`when`(context).resources
|
||||
doReturn(0f).`when`(resources)
|
||||
.getDimension(R.dimen.mapbox_locationComponentTrackingMultiFingerMoveThreshold)
|
||||
doReturn(0f).`when`(resources)
|
||||
.getDimension(R.dimen.mapbox_locationComponentTrackingMultiFingerMoveThreshold)
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), true, locationEngineRequest)
|
||||
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun activateWithDefaultLocationEngineRequestAndOptionsTestDefaultLocationEngine() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), true, locationEngineRequest, locationComponentOptions)
|
||||
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
|
||||
Assert.assertNotNull(locationComponent.locationEngine)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun activateWithDefaultLocationEngineRequestAndOptionsTestCustomLocationEngine() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), false, locationEngineRequest, locationComponentOptions)
|
||||
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
|
||||
Assert.assertNull(locationComponent.locationEngine)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun locationUpdatesWhenEnabledDisableTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
verify(locationEngine, times(0)).removeLocationUpdates(currentListener)
|
||||
verify(locationEngine, times(0)).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
|
||||
|
||||
locationComponent.onStart()
|
||||
verify(locationEngine, times(0)).removeLocationUpdates(currentListener)
|
||||
verify(locationEngine, times(0)).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
|
||||
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
verify(locationEngine).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
|
||||
|
||||
locationComponent.isLocationComponentEnabled = false
|
||||
verify(locationEngine).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
|
||||
verify(locationEngine).removeLocationUpdates(currentListener)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun locationUpdatesWhenStartedStoppedTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
locationComponent.onStop()
|
||||
verify(locationEngine).removeLocationUpdates(currentListener)
|
||||
|
||||
locationComponent.onStart()
|
||||
verify(locationEngine, times(2)).requestLocationUpdates(eq(locationEngineRequest), eq(currentListener), any(Looper::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun locationUpdatesWhenNewRequestTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val newRequest = mock(LocationEngineRequest::class.java)
|
||||
locationComponent.locationEngineRequest = newRequest
|
||||
verify(locationEngine).removeLocationUpdates(currentListener)
|
||||
verify(locationEngine).requestLocationUpdates(eq(newRequest), eq(currentListener), any(Looper::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lastLocationUpdateOnStartTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
verify(locationEngine).getLastLocation(lastListener)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transitionCallbackFinishedTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
val listener = mock(OnLocationCameraTransitionListener::class.java)
|
||||
|
||||
val callback = ArgumentCaptor.forClass(OnLocationCameraTransitionListener::class.java)
|
||||
locationComponent.setCameraMode(CameraMode.TRACKING, listener)
|
||||
verify(locationCameraController).setCameraMode(eq(CameraMode.TRACKING), any(), eq(TRANSITION_ANIMATION_DURATION_MS), isNull(), isNull(), isNull(), callback.capture())
|
||||
callback.value.onLocationCameraTransitionFinished(CameraMode.TRACKING)
|
||||
|
||||
verify(listener).onLocationCameraTransitionFinished(CameraMode.TRACKING)
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(CameraPosition.DEFAULT, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transitionCallbackCanceledTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
val listener = mock(OnLocationCameraTransitionListener::class.java)
|
||||
|
||||
val callback = ArgumentCaptor.forClass(OnLocationCameraTransitionListener::class.java)
|
||||
locationComponent.setCameraMode(CameraMode.TRACKING, listener)
|
||||
verify(locationCameraController).setCameraMode(eq(CameraMode.TRACKING), any(), eq(TRANSITION_ANIMATION_DURATION_MS), isNull(), isNull(), isNull(), callback.capture())
|
||||
callback.value.onLocationCameraTransitionCanceled(CameraMode.TRACKING)
|
||||
|
||||
verify(listener).onLocationCameraTransitionCanceled(CameraMode.TRACKING)
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(CameraPosition.DEFAULT, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transitionCustomFinishedTest() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
val listener = mock(OnLocationCameraTransitionListener::class.java)
|
||||
|
||||
val callback = ArgumentCaptor.forClass(OnLocationCameraTransitionListener::class.java)
|
||||
locationComponent.setCameraMode(CameraMode.TRACKING, 1200, 14.0, 13.0, 45.0, listener)
|
||||
verify(locationCameraController).setCameraMode(eq(CameraMode.TRACKING), any(), eq(1200L), eq(14.0), eq(13.0), eq(45.0), callback.capture())
|
||||
callback.value.onLocationCameraTransitionFinished(CameraMode.TRACKING)
|
||||
|
||||
verify(listener).onLocationCameraTransitionFinished(CameraMode.TRACKING)
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(CameraPosition.DEFAULT, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_listenWhenConsumedByNoneCamera() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationCameraController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.cameraMode = CameraMode.NONE_COMPASS
|
||||
verify(compassEngine).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_listenWhenConsumedByTrackingCamera() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationCameraController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.cameraMode = CameraMode.TRACKING_COMPASS
|
||||
verify(compassEngine).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_listenWhenConsumedByLayer() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
verify(compassEngine).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_notListenWhenNotConsumed() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(false)
|
||||
`when`(locationCameraController.isConsumingCompass).thenReturn(false)
|
||||
locationComponent.renderMode = RenderMode.GPS
|
||||
locationComponent.renderMode = RenderMode.NORMAL
|
||||
locationComponent.cameraMode = CameraMode.TRACKING
|
||||
locationComponent.cameraMode = CameraMode.NONE
|
||||
locationComponent.cameraMode = CameraMode.NONE_GPS
|
||||
locationComponent.cameraMode = CameraMode.TRACKING_GPS
|
||||
locationComponent.cameraMode = CameraMode.TRACKING_GPS_NORTH
|
||||
verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_removeListenerOnChange() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(false)
|
||||
locationComponent.renderMode = RenderMode.NORMAL
|
||||
verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_removeListenerOnStop() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
locationComponent.onStop()
|
||||
verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_reAddListenerOnStart() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
locationComponent.onStop()
|
||||
locationComponent.onStart()
|
||||
verify(compassEngine, times(2)).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_removeListenerOnStyleStartLoad() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
locationComponent.onStartLoadingMap()
|
||||
verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_reAddListenerOnStyleLoadFinished() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
locationComponent.onStartLoadingMap()
|
||||
locationComponent.onFinishLoadingStyle()
|
||||
verify(compassEngine, times(2)).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_reAddListenerOnlyWhenEnabled() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
locationComponent.isLocationComponentEnabled = false
|
||||
|
||||
locationComponent.onStartLoadingMap()
|
||||
locationComponent.onFinishLoadingStyle()
|
||||
verify(compassEngine).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_notAdListenerWhenDisabled() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.onStart()
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compass_notAdListenerWhenStopped() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
|
||||
|
||||
`when`(locationLayerController.isConsumingCompass).thenReturn(true)
|
||||
locationComponent.renderMode = RenderMode.COMPASS
|
||||
verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun developerAnimationCalled() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
for (listener in developerAnimationListeners) {
|
||||
listener.onDeveloperAnimationStarted()
|
||||
}
|
||||
verify(locationCameraController).setCameraMode(eq(CameraMode.NONE), isNull<Location>(), eq(TRANSITION_ANIMATION_DURATION_MS), isNull<Double>(), isNull<Double>(), isNull<Double>(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internal_cameraTrackingChangedListener_onCameraTrackingDismissed() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val cameraChangeListener: OnCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener::class.java)
|
||||
locationComponent.addOnCameraTrackingChangedListener(cameraChangeListener)
|
||||
|
||||
locationComponent.cameraTrackingChangedListener.onCameraTrackingDismissed()
|
||||
|
||||
verify(cameraChangeListener).onCameraTrackingDismissed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internal_cameraTrackingChangedListener_onCameraTrackingChanged() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val cameraValueListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
val layerValueListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
`when`(locationCameraController.animationListeners).thenReturn(setOf(cameraValueListener))
|
||||
`when`(locationLayerController.animationListeners).thenReturn(setOf(layerValueListener))
|
||||
val cameraChangeListener: OnCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener::class.java)
|
||||
locationComponent.addOnCameraTrackingChangedListener(cameraChangeListener)
|
||||
|
||||
locationComponent.cameraTrackingChangedListener.onCameraTrackingChanged(CameraMode.TRACKING_GPS)
|
||||
|
||||
verify(locationAnimatorCoordinator).cancelZoomAnimation()
|
||||
verify(locationAnimatorCoordinator).cancelTiltAnimation()
|
||||
verify(locationAnimatorCoordinator).updateAnimatorListenerHolders(eq(setOf(cameraValueListener, layerValueListener)))
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(any(), anyBoolean())
|
||||
verify(locationAnimatorCoordinator).resetAllLayerAnimations()
|
||||
verify(cameraChangeListener).onCameraTrackingChanged(CameraMode.TRACKING_GPS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internal_renderModeChangedListener_onRenderModeChanged() {
|
||||
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val cameraListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
val layerListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
`when`(locationCameraController.animationListeners).thenReturn(setOf(cameraListener))
|
||||
`when`(locationLayerController.animationListeners).thenReturn(setOf(layerListener))
|
||||
val renderChangeListener: OnRenderModeChangedListener = mock(OnRenderModeChangedListener::class.java)
|
||||
locationComponent.addOnRenderModeChangedListener(renderChangeListener)
|
||||
|
||||
locationComponent.renderModeChangedListener.onRenderModeChanged(RenderMode.NORMAL)
|
||||
|
||||
verify(locationAnimatorCoordinator).updateAnimatorListenerHolders(eq(setOf(cameraListener, layerListener)))
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(any(), anyBoolean())
|
||||
verify(locationAnimatorCoordinator).resetAllLayerAnimations()
|
||||
verify(renderChangeListener).onRenderModeChanged(RenderMode.NORMAL)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,718 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_STALE_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_STALE_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.LOCATION_SOURCE;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_RADIUS;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_COMPASS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_ICON_OFFSET;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_GPS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_SHADOW_ICON_OFFSET;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_ACCURACY;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_COMPASS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_GPS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_LATLNG;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
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 LocationLayerControllerTest {
|
||||
|
||||
private MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
private Style style = mock(Style.class);
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
when(mapboxMap.getStyle()).thenReturn(style);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_locationSourceIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addSource(locationSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_shadowLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_backgroundLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_foregroundLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_bearingLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
String layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(bearingLayer, layerBelow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_accuracyLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_numberOfCachedLayerIdsIsConstant() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
controller.initializeComponents(mapboxMap.getStyle(), options);
|
||||
|
||||
assertEquals(5, controller.layerSet.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleShadowWithValidElevation() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.elevation()).thenReturn(2f);
|
||||
|
||||
// Style is applied on initialization
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(SHADOW_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_ignoreStyleShadowWithInvalidElevation() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.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(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.elevation()).thenReturn(0f);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style, times(0)).addImage(SHADOW_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleForegroundFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.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 LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleForegroundStaleFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.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 LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(FOREGROUND_STALE_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBackgroundFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.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 LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(BACKGROUND_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBackgroundStaleFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.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 LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(BACKGROUND_STALE_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBearingFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.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 LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(BEARING_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowChanged() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
Layer bearingLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer2);
|
||||
Layer foregroundLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer2);
|
||||
Layer backgroundLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer2);
|
||||
Layer shadowLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer2);
|
||||
Layer accuracyLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer2);
|
||||
String layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
layerController.applyStyle(options);
|
||||
|
||||
verify(style).removeLayer(BEARING_LAYER);
|
||||
verify(style).removeLayer(FOREGROUND_LAYER);
|
||||
verify(style).removeLayer(BACKGROUND_LAYER);
|
||||
verify(style).removeLayer(SHADOW_LAYER);
|
||||
verify(style).removeLayer(ACCURACY_LAYER);
|
||||
|
||||
verify(style).addLayerBelow(bearingLayer2, layerBelow);
|
||||
verify(style).addLayerBelow(foregroundLayer2, BEARING_LAYER);
|
||||
verify(style).addLayerBelow(backgroundLayer2, FOREGROUND_LAYER);
|
||||
verify(style).addLayerBelow(shadowLayer2, BACKGROUND_LAYER);
|
||||
verify(style).addLayerBelow(accuracyLayer2, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowNotChanged() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
|
||||
String layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
options = mock(LocationComponentOptions.class);
|
||||
layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
layerController.applyStyle(options);
|
||||
|
||||
verify(style, times(0)).removeLayer(any(String.class));
|
||||
verify(style, times(5)).addLayerBelow(any(Layer.class), any(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowNotChangedNull() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
options = mock(LocationComponentOptions.class);
|
||||
layerController.applyStyle(options);
|
||||
|
||||
verify(style, times(0)).removeLayer(any(String.class));
|
||||
verify(style, times(1)).addLayer(any(Layer.class));
|
||||
verify(style, times(4)).addLayerBelow(any(Layer.class), Mockito.<String>any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateForegroundOffset_foregroundIconPropertyIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
|
||||
layer.updateForegroundOffset(2d);
|
||||
|
||||
verify(locationFeature).addProperty(eq(PROPERTY_FOREGROUND_ICON_OFFSET), any(JsonElement.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateForegroundOffset_shadowPropertyIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.updateForegroundOffset(2d);
|
||||
|
||||
verify(locationFeature).addProperty(eq(PROPERTY_SHADOW_ICON_OFFSET), any(JsonElement.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewLatLngValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_LATLNG, layer.getAnimationListeners()).onNewAnimationValue(new LatLng());
|
||||
|
||||
// wanted twice (once for initialization)
|
||||
verify(locationSource, times(2)).setGeoJson(locationFeature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewGpsBearingValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float gpsBearing = 2f;
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_GPS_BEARING, layer.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewGpsBearingValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.COMPASS);
|
||||
float gpsBearing = 2f;
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_GPS_BEARING, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewCompassBearingValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.COMPASS);
|
||||
float compassBearing = 2f;
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_COMPASS_BEARING, layer.getAnimationListeners())
|
||||
.onNewAnimationValue(compassBearing);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewCompassBearingValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float compassBearing = 2f;
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_COMPASS_BEARING, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewAccuracyRadiusValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.NORMAL);
|
||||
float accuracyRadiusValue = 2f;
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_ACCURACY, layer.getAnimationListeners())
|
||||
.onNewAnimationValue(accuracyRadiusValue);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewAccuracyRadiusValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float accuracyRadiusValue = 2f;
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_ACCURACY, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0))
|
||||
.addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderModeChanged_doNotNotifyAboutDuplicates_NORMAL() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
controller.setRenderMode(RenderMode.NORMAL);
|
||||
controller.setRenderMode(RenderMode.NORMAL);
|
||||
|
||||
verify(internalRenderModeChangedListener, times(1)).onRenderModeChanged(RenderMode.NORMAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderModeChanged_doNotNotifyAboutDuplicates_GPS() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
controller.setRenderMode(RenderMode.GPS);
|
||||
controller.setRenderMode(RenderMode.GPS);
|
||||
|
||||
verify(internalRenderModeChangedListener, times(1)).onRenderModeChanged(RenderMode.GPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layerHidden_renderModeChanged_layerShown_foregroundIconUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.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);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmap);
|
||||
|
||||
int drawableGpsResId = 789;
|
||||
when(options.gpsDrawable()).thenReturn(drawableGpsResId);
|
||||
|
||||
Bitmap bitmapGps = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableGpsResId, tintColor)).thenReturn(bitmapGps);
|
||||
|
||||
controller.hide();
|
||||
|
||||
controller.setRenderMode(RenderMode.GPS);
|
||||
|
||||
controller.show();
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmapGps);
|
||||
}
|
||||
|
||||
private LayerFeatureProvider buildFeatureProvider(@NonNull LocationComponentOptions options) {
|
||||
LayerFeatureProvider provider = mock(LayerFeatureProvider.class);
|
||||
when(provider.generateLocationFeature(null, options)).thenReturn(mock(Feature.class));
|
||||
return provider;
|
||||
}
|
||||
|
||||
private LayerFeatureProvider buildFeatureProvider(Feature feature, @NonNull LocationComponentOptions options) {
|
||||
LayerFeatureProvider provider = mock(LayerFeatureProvider.class);
|
||||
when(provider.generateLocationFeature(null, options)).thenReturn(feature);
|
||||
return provider;
|
||||
}
|
||||
|
||||
private LayerSourceProvider buildLayerProvider() {
|
||||
LayerSourceProvider layerSourceProvider = mock(LayerSourceProvider.class);
|
||||
|
||||
Layer shadowLayer = mock(Layer.class);
|
||||
when(shadowLayer.getId()).thenReturn(SHADOW_LAYER);
|
||||
when(layerSourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer);
|
||||
|
||||
Layer backgroundLayer = mock(Layer.class);
|
||||
when(backgroundLayer.getId()).thenReturn(BACKGROUND_LAYER);
|
||||
when(layerSourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer);
|
||||
|
||||
Layer foregroundLayer = mock(Layer.class);
|
||||
when(foregroundLayer.getId()).thenReturn(FOREGROUND_LAYER);
|
||||
when(layerSourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer);
|
||||
|
||||
Layer bearingLayer = mock(Layer.class);
|
||||
when(bearingLayer.getId()).thenReturn(BEARING_LAYER);
|
||||
when(layerSourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer);
|
||||
|
||||
Layer accuracyLayer = mock(Layer.class);
|
||||
when(accuracyLayer.getId()).thenReturn(ACCURACY_LAYER);
|
||||
when(layerSourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer);
|
||||
return layerSourceProvider;
|
||||
}
|
||||
|
||||
private <T> MapboxAnimator.AnimationsValueChangeListener<T> getAnimationListener(
|
||||
@MapboxAnimator.Type int animatorType,
|
||||
Set<AnimatorListenerHolder> holders) {
|
||||
for (AnimatorListenerHolder holder : holders) {
|
||||
@MapboxAnimator.Type int type = holder.getAnimatorType();
|
||||
if (type == animatorType) {
|
||||
return holder.getListener();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxAnimatorTest {
|
||||
|
||||
@Test
|
||||
fun fps_unlimited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(0f, 10f, listener, Int.MAX_VALUE)
|
||||
|
||||
for (i in 0 until 5)
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
|
||||
verify(exactly = 5) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fps_limited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(0f, 10f, listener, 5)
|
||||
|
||||
for (i in 0 until 5) {
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
Thread.sleep(150)
|
||||
}
|
||||
|
||||
verify(exactly = 3) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mapbox.mapboxsdk.log
|
||||
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class LoggerTest {
|
||||
|
||||
private val logger: LoggerDefinition = mockk(relaxed = true)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
Logger.setLoggerDefinition(logger)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verbosityLogLevel() {
|
||||
Logger.setVerbosity(Logger.VERBOSE)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
verify { logger.v(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verbosityLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.DEBUG)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.v(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun debugLogLevel() {
|
||||
Logger.setVerbosity(Logger.VERBOSE)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
verify { logger.d(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun debugLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.WARN)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.d(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun warnLogLevel() {
|
||||
Logger.setVerbosity(Logger.WARN)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
verify { logger.w(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun warnLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.ERROR)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.w(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun errorLogLevel() {
|
||||
Logger.setVerbosity(Logger.ERROR)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun errorLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.NONE)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noneLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.NONE)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.v(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.d(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.w(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG: String = "TAG"
|
||||
const val MESSAGE: String = "message"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class AnnotationManagerTest {
|
||||
|
||||
@Test
|
||||
public void checksAddAMarker() throws Exception {
|
||||
NativeMap aNativeMapView = mock(NativeMapView.class);
|
||||
MapView aMapView = mock(MapView.class);
|
||||
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
|
||||
IconManager aIconManager = mock(IconManager.class);
|
||||
Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray);
|
||||
Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager);
|
||||
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
|
||||
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
|
||||
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
|
||||
AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray,
|
||||
aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
Marker aMarker = mock(Marker.class);
|
||||
long aId = 5L;
|
||||
when(aNativeMapView.addMarker(aMarker)).thenReturn(aId);
|
||||
BaseMarkerOptions aMarkerOptions = mock(BaseMarkerOptions.class);
|
||||
MapboxMap aMapboxMap = mock(MapboxMap.class);
|
||||
when(aMarkerOptions.getMarker()).thenReturn(aMarker);
|
||||
|
||||
annotationManager.addMarker(aMarkerOptions, aMapboxMap);
|
||||
|
||||
assertEquals(aMarker, annotationManager.getAnnotations().get(0));
|
||||
assertEquals(aMarker, annotationManager.getAnnotation(aId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksAddMarkers() throws Exception {
|
||||
NativeMapView aNativeMapView = mock(NativeMapView.class);
|
||||
MapView aMapView = mock(MapView.class);
|
||||
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
|
||||
IconManager aIconManager = mock(IconManager.class);
|
||||
Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray);
|
||||
Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager);
|
||||
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
|
||||
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
|
||||
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
|
||||
AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray,
|
||||
aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
|
||||
long firstId = 1L;
|
||||
long secondId = 2L;
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions firstMarkerOption = new MarkerOptions().position(new LatLng()).title("first");
|
||||
MarkerOptions secondMarkerOption = new MarkerOptions().position(new LatLng()).title("second");
|
||||
|
||||
markerList.add(firstMarkerOption);
|
||||
markerList.add(secondMarkerOption);
|
||||
MapboxMap aMapboxMap = mock(MapboxMap.class);
|
||||
when(aNativeMapView.addMarker(any(Marker.class))).thenReturn(firstId, secondId);
|
||||
|
||||
when(aNativeMapView.addMarkers(ArgumentMatchers.<Marker>anyList()))
|
||||
.thenReturn(new long[] {firstId, secondId});
|
||||
|
||||
annotationManager.addMarkers(markerList, aMapboxMap);
|
||||
|
||||
assertEquals(2, annotationManager.getAnnotations().size());
|
||||
assertEquals("first", ((Marker) annotationManager.getAnnotations().get(0)).getTitle());
|
||||
assertEquals("second", ((Marker) annotationManager.getAnnotations().get(1)).getTitle());
|
||||
assertEquals("first", ((Marker) annotationManager.getAnnotation(firstId)).getTitle());
|
||||
assertEquals("second", ((Marker) annotationManager.getAnnotation(secondId)).getTitle());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,586 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import com.google.common.util.concurrent.ExecutionError;
|
||||
import com.mapbox.mapboxsdk.log.Logger;
|
||||
import com.mapbox.mapboxsdk.log.LoggerDefinition;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests integration of MapChangeDispatcher and see if events are correctly forwarded.
|
||||
*/
|
||||
public class MapChangeReceiverTest {
|
||||
|
||||
private static final String TEST_STRING = "mapChangeRandom";
|
||||
|
||||
private MapChangeReceiver mapChangeEventManager;
|
||||
|
||||
@Mock
|
||||
private MapView.OnCameraWillChangeListener onCameraWillChangeListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnCameraDidChangeListener onCameraDidChangeListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnCameraIsChangingListener onCameraIsChangingListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnWillStartLoadingMapListener onWillStartLoadingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishLoadingMapListener onDidFinishLoadingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFailLoadingMapListener onDidFailLoadingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnWillStartRenderingFrameListener onWillStartRenderingFrameListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishRenderingFrameListener onDidFinishRenderingFrameListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnWillStartRenderingMapListener onWillStartRenderingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishRenderingMapListener onDidFinishRenderingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidBecomeIdleListener onDidBecomeIdleListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishLoadingStyleListener onDidFinishLoadingStyleListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnSourceChangedListener onSourceChangedListener;
|
||||
|
||||
@Mock
|
||||
private LoggerDefinition loggerDefinition;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mapChangeEventManager = new MapChangeReceiver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionWillChangeListener() {
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
|
||||
mapChangeEventManager.removeOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionWillChangeAnimatedListener() {
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
mapChangeEventManager.removeOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraIsChangingListener() {
|
||||
mapChangeEventManager.addOnCameraIsChangingListener(onCameraIsChangingListener);
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
verify(onCameraIsChangingListener).onCameraIsChanging();
|
||||
mapChangeEventManager.removeOnCameraIsChangingListener(onCameraIsChangingListener);
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
verify(onCameraIsChangingListener).onCameraIsChanging();
|
||||
|
||||
mapChangeEventManager.addOnCameraIsChangingListener(onCameraIsChangingListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraIsChangingListener).onCameraIsChanging();
|
||||
try {
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraIsChangingListener).onCameraIsChanging();
|
||||
try {
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionDidChangeListener() {
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
mapChangeEventManager.removeOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionDidChangeAnimatedListener() {
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
mapChangeEventManager.removeOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWillStartLoadingMapListener() {
|
||||
mapChangeEventManager.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener);
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
verify(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
mapChangeEventManager.removeOnWillStartLoadingMapListener(onWillStartLoadingMapListener);
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
verify(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
|
||||
mapChangeEventManager.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishLoadingMapListener() {
|
||||
mapChangeEventManager.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener);
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
verify(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
mapChangeEventManager.removeOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener);
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
verify(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
|
||||
mapChangeEventManager.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFailLoadingMapListener() {
|
||||
mapChangeEventManager.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener);
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
verify(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
mapChangeEventManager.removeOnDidFailLoadingMapListener(onDidFailLoadingMapListener);
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
verify(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
|
||||
mapChangeEventManager.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWillStartRenderingFrameListener() {
|
||||
mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
verify(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
mapChangeEventManager.removeOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
verify(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
|
||||
mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingFrameListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingFrameFullyRenderedListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWillStartRenderingMapListener() {
|
||||
mapChangeEventManager.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener);
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
verify(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
mapChangeEventManager.removeOnWillStartRenderingMapListener(onWillStartRenderingMapListener);
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
verify(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
|
||||
mapChangeEventManager.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingMapListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingMapFullyRenderedListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidBecomeIdleListener() {
|
||||
mapChangeEventManager.addOnDidBecomeIdleListener(onDidBecomeIdleListener);
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
verify(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
mapChangeEventManager.removeOnDidBecomeIdleListener(onDidBecomeIdleListener);
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
verify(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
|
||||
mapChangeEventManager.addOnDidBecomeIdleListener(onDidBecomeIdleListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
try {
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
try {
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishLoadingStyleListener() {
|
||||
mapChangeEventManager.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener);
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
verify(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
mapChangeEventManager.removeOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener);
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
verify(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
|
||||
mapChangeEventManager.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSourceChangedListener() {
|
||||
mapChangeEventManager.addOnSourceChangedListener(onSourceChangedListener);
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
verify(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
mapChangeEventManager.removeOnSourceChangedListener(onSourceChangedListener);
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
verify(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
|
||||
mapChangeEventManager.addOnSourceChangedListener(onSourceChangedListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.graphics.PointF;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import com.mapbox.android.gestures.MoveGestureDetector;
|
||||
import com.mapbox.android.gestures.RotateGestureDetector;
|
||||
import com.mapbox.android.gestures.ShoveGestureDetector;
|
||||
import com.mapbox.android.gestures.StandardScaleGestureDetector;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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 MapTouchListenersTest {
|
||||
|
||||
@Nullable
|
||||
private MapGestureDetector mapGestureDetector;
|
||||
private LatLng latLng;
|
||||
private PointF pointF;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
latLng = new LatLng();
|
||||
pointF = new PointF();
|
||||
|
||||
Projection projection = mock(Projection.class);
|
||||
when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
|
||||
mapGestureDetector = new MapGestureDetector(null,
|
||||
null, projection, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMapClickListenerTest() throws Exception {
|
||||
MapboxMap.OnMapClickListener listener = mock(MapboxMap.OnMapClickListener.class);
|
||||
mapGestureDetector.addOnMapClickListener(listener);
|
||||
mapGestureDetector.notifyOnMapClickListeners(pointF);
|
||||
verify(listener, times(1)).onMapClick(latLng);
|
||||
|
||||
mapGestureDetector.removeOnMapClickListener(listener);
|
||||
mapGestureDetector.notifyOnMapClickListeners(pointF);
|
||||
verify(listener, times(1)).onMapClick(latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMapLongClickListenerTest() throws Exception {
|
||||
MapboxMap.OnMapLongClickListener listener = mock(MapboxMap.OnMapLongClickListener.class);
|
||||
mapGestureDetector.addOnMapLongClickListener(listener);
|
||||
mapGestureDetector.notifyOnMapLongClickListeners(pointF);
|
||||
verify(listener, times(1)).onMapLongClick(latLng);
|
||||
|
||||
mapGestureDetector.removeOnMapLongClickListener(listener);
|
||||
mapGestureDetector.notifyOnMapLongClickListeners(pointF);
|
||||
verify(listener, times(1)).onMapLongClick(latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onFlingListenerTest() throws Exception {
|
||||
MapboxMap.OnFlingListener listener = mock(MapboxMap.OnFlingListener.class);
|
||||
mapGestureDetector.addOnFlingListener(listener);
|
||||
mapGestureDetector.notifyOnFlingListeners();
|
||||
verify(listener, times(1)).onFling();
|
||||
|
||||
mapGestureDetector.removeOnFlingListener(listener);
|
||||
mapGestureDetector.notifyOnFlingListeners();
|
||||
verify(listener, times(1)).onFling();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMoveListenerTest() throws Exception {
|
||||
MapboxMap.OnMoveListener listener = mock(MapboxMap.OnMoveListener.class);
|
||||
MoveGestureDetector detector = mock(MoveGestureDetector.class);
|
||||
mapGestureDetector.addOnMoveListener(listener);
|
||||
mapGestureDetector.notifyOnMoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveEndListeners(detector);
|
||||
verify(listener, times(1)).onMoveBegin(detector);
|
||||
verify(listener, times(1)).onMove(detector);
|
||||
verify(listener, times(1)).onMoveEnd(detector);
|
||||
|
||||
mapGestureDetector.removeOnMoveListener(listener);
|
||||
mapGestureDetector.notifyOnMoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveEndListeners(detector);
|
||||
verify(listener, times(1)).onMoveBegin(detector);
|
||||
verify(listener, times(1)).onMove(detector);
|
||||
verify(listener, times(1)).onMoveEnd(detector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onRotateListenerTest() throws Exception {
|
||||
MapboxMap.OnRotateListener listener = mock(MapboxMap.OnRotateListener.class);
|
||||
RotateGestureDetector detector = mock(RotateGestureDetector.class);
|
||||
mapGestureDetector.addOnRotateListener(listener);
|
||||
mapGestureDetector.notifyOnRotateBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateEndListeners(detector);
|
||||
verify(listener, times(1)).onRotateBegin(detector);
|
||||
verify(listener, times(1)).onRotate(detector);
|
||||
verify(listener, times(1)).onRotateEnd(detector);
|
||||
|
||||
mapGestureDetector.removeOnRotateListener(listener);
|
||||
mapGestureDetector.notifyOnRotateBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateEndListeners(detector);
|
||||
verify(listener, times(1)).onRotateBegin(detector);
|
||||
verify(listener, times(1)).onRotate(detector);
|
||||
verify(listener, times(1)).onRotateEnd(detector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onScaleListenerTest() throws Exception {
|
||||
MapboxMap.OnScaleListener listener = mock(MapboxMap.OnScaleListener.class);
|
||||
StandardScaleGestureDetector detector = mock(StandardScaleGestureDetector.class);
|
||||
mapGestureDetector.addOnScaleListener(listener);
|
||||
mapGestureDetector.notifyOnScaleBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleEndListeners(detector);
|
||||
verify(listener, times(1)).onScaleBegin(detector);
|
||||
verify(listener, times(1)).onScale(detector);
|
||||
verify(listener, times(1)).onScaleEnd(detector);
|
||||
|
||||
mapGestureDetector.removeOnScaleListener(listener);
|
||||
mapGestureDetector.notifyOnScaleBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleEndListeners(detector);
|
||||
verify(listener, times(1)).onScaleBegin(detector);
|
||||
verify(listener, times(1)).onScale(detector);
|
||||
verify(listener, times(1)).onScaleEnd(detector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onShoveListenerTest() throws Exception {
|
||||
MapboxMap.OnShoveListener listener = mock(MapboxMap.OnShoveListener.class);
|
||||
ShoveGestureDetector detector = mock(ShoveGestureDetector.class);
|
||||
mapGestureDetector.addShoveListener(listener);
|
||||
mapGestureDetector.notifyOnShoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveEndListeners(detector);
|
||||
verify(listener, times(1)).onShoveBegin(detector);
|
||||
verify(listener, times(1)).onShove(detector);
|
||||
verify(listener, times(1)).onShoveEnd(detector);
|
||||
|
||||
mapGestureDetector.removeShoveListener(listener);
|
||||
mapGestureDetector.notifyOnShoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveEndListeners(detector);
|
||||
verify(listener, times(1)).onShoveBegin(detector);
|
||||
verify(listener, times(1)).onShove(detector);
|
||||
verify(listener, times(1)).onShoveEnd(detector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.content.res.TypedArray
|
||||
import com.mapbox.mapboxsdk.R
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.RelaxedMockK
|
||||
import io.mockk.verify
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxMapOptionsAttrsTest {
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var options: MapboxMapOptions
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var typedArray: TypedArray
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var context: Context
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var resources: Resources
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this)
|
||||
every {
|
||||
context.resources
|
||||
}.returns(resources)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun enabledLocalIdeographFontFamily() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(any())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localIdeographFontFamily() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
val font = "foo"
|
||||
mockLocalIdeographString(font)
|
||||
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(font)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localIdeographFontFamilies() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
val fonts = arrayOf("foo", "bar")
|
||||
mockLocalIdeographStringArray(fonts)
|
||||
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(*fonts)
|
||||
}
|
||||
}
|
||||
|
||||
private fun mockEnableLocalIdeograph(enabled: Boolean) {
|
||||
every {
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_localIdeographEnabled, true)
|
||||
}.returns(enabled)
|
||||
}
|
||||
|
||||
private fun mockLocalIdeographString(font: String) {
|
||||
every {
|
||||
typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily)
|
||||
}.returns(font)
|
||||
}
|
||||
|
||||
private fun mockLocalIdeographStringArray(fonts: Array<String>) {
|
||||
val resId = 9000
|
||||
|
||||
every {
|
||||
typedArray.getResourceId(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamilies, 0)
|
||||
}.returns(resId)
|
||||
|
||||
every {
|
||||
resources.getStringArray(resId)
|
||||
}.returns(fonts)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MapboxMapOptionsTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("should not be null", new MapboxMapOptions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDebugEnabled() {
|
||||
assertFalse(new MapboxMapOptions().getDebugActive());
|
||||
assertTrue(new MapboxMapOptions().debugActive(true).getDebugActive());
|
||||
assertFalse(new MapboxMapOptions().debugActive(false).getDebugActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassEnabled() {
|
||||
assertTrue(new MapboxMapOptions().compassEnabled(true).getCompassEnabled());
|
||||
assertFalse(new MapboxMapOptions().compassEnabled(false).getCompassEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassGravity() {
|
||||
assertEquals(Gravity.TOP | Gravity.END, new MapboxMapOptions().getCompassGravity());
|
||||
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity());
|
||||
assertNotEquals(Gravity.START, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassMargins() {
|
||||
assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().compassMargins(
|
||||
new int[] {0, 1, 2, 3}).getCompassMargins()));
|
||||
assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().compassMargins(
|
||||
new int[] {0, 0, 0, 0}).getCompassMargins()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoEnabled() {
|
||||
assertTrue(new MapboxMapOptions().logoEnabled(true).getLogoEnabled());
|
||||
assertFalse(new MapboxMapOptions().logoEnabled(false).getLogoEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoGravity() {
|
||||
assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getLogoGravity());
|
||||
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity());
|
||||
assertNotEquals(Gravity.START, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoMargins() {
|
||||
assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().logoMargins(
|
||||
new int[] {0, 1, 2, 3}).getLogoMargins()));
|
||||
assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().logoMargins(
|
||||
new int[] {0, 0, 0, 0}).getLogoMargins()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionTintColor() {
|
||||
assertEquals(-1, new MapboxMapOptions().getAttributionTintColor());
|
||||
assertEquals(Color.RED, new MapboxMapOptions().attributionTintColor(Color.RED).getAttributionTintColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionEnabled() {
|
||||
assertTrue(new MapboxMapOptions().attributionEnabled(true).getAttributionEnabled());
|
||||
assertFalse(new MapboxMapOptions().attributionEnabled(false).getAttributionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionGravity() {
|
||||
assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getAttributionGravity());
|
||||
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity());
|
||||
assertNotEquals(Gravity.START, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionMargins() {
|
||||
assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().attributionMargins(
|
||||
new int[] {0, 1, 2, 3}).getAttributionMargins()));
|
||||
assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().attributionMargins(
|
||||
new int[] {0, 0, 0, 0}).getAttributionMargins()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinZoom() {
|
||||
assertEquals(MapboxConstants.MINIMUM_ZOOM, new MapboxMapOptions().getMinZoomPreference(), DELTA);
|
||||
assertEquals(5.0f, new MapboxMapOptions().minZoomPreference(5.0f).getMinZoomPreference(), DELTA);
|
||||
assertNotEquals(2.0f, new MapboxMapOptions().minZoomPreference(5.0f).getMinZoomPreference(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxZoom() {
|
||||
assertEquals(MapboxConstants.MAXIMUM_ZOOM, new MapboxMapOptions().getMaxZoomPreference(), DELTA);
|
||||
assertEquals(5.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA);
|
||||
assertNotEquals(2.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getTiltGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().tiltGesturesEnabled(true).getTiltGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().tiltGesturesEnabled(false).getTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getScrollGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().scrollGesturesEnabled(true).getScrollGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().scrollGesturesEnabled(false).getScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getZoomGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().zoomGesturesEnabled(true).getZoomGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().zoomGesturesEnabled(false).getZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getRotateGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().rotateGesturesEnabled(true).getRotateGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().rotateGesturesEnabled(false).getRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCamera() {
|
||||
CameraPosition position = new CameraPosition.Builder().build();
|
||||
assertEquals(new CameraPosition.Builder(position).build(), new MapboxMapOptions().camera(position).getCamera());
|
||||
assertNotEquals(new CameraPosition.Builder().target(new LatLng(1, 1)), new MapboxMapOptions().camera(position));
|
||||
assertNull(new MapboxMapOptions().getCamera());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefetchesTiles() {
|
||||
// Default value
|
||||
assertTrue(new MapboxMapOptions().getPrefetchesTiles());
|
||||
|
||||
// Check mutations
|
||||
assertTrue(new MapboxMapOptions().setPrefetchesTiles(true).getPrefetchesTiles());
|
||||
assertFalse(new MapboxMapOptions().setPrefetchesTiles(false).getPrefetchesTiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossSourceCollisions() {
|
||||
// Default value
|
||||
assertTrue(new MapboxMapOptions().getCrossSourceCollisions());
|
||||
|
||||
// check mutations
|
||||
assertTrue(new MapboxMapOptions().crossSourceCollisions(true).getCrossSourceCollisions());
|
||||
assertFalse(new MapboxMapOptions().crossSourceCollisions(false).getCrossSourceCollisions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalIdeographFontFamily_enabledByDefault() {
|
||||
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(RuntimeEnvironment.application, null);
|
||||
assertEquals(MapboxConstants.DEFAULT_FONT, options.getLocalIdeographFontFamily());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
|
||||
import io.mockk.*
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxMapTest {
|
||||
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
|
||||
private lateinit var transform: Transform
|
||||
|
||||
private lateinit var cameraChangeDispatcher: CameraChangeDispatcher
|
||||
|
||||
private lateinit var developerAnimationListener: MapboxMap.OnDeveloperAnimationListener
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
cameraChangeDispatcher = spyk()
|
||||
developerAnimationListener = mockk(relaxed = true)
|
||||
nativeMapView = mockk(relaxed = true)
|
||||
transform = mockk(relaxed = true)
|
||||
mapboxMap = MapboxMap(nativeMapView, transform, mockk(relaxed = true), null, null, cameraChangeDispatcher, listOf(developerAnimationListener))
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.nativePtr } returns 5
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTransitionOptions() {
|
||||
val expected = TransitionOptions(100, 200)
|
||||
mapboxMap.style?.transition = expected
|
||||
verify { nativeMapView.transitionOptions = expected }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.moveCamera(update, callback)
|
||||
verify { transform.moveCamera(mapboxMap, update, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.easeCamera(update, callback)
|
||||
verify { transform.easeCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, true, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.animateCamera(update, callback)
|
||||
verify { transform.animateCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScrollBy() {
|
||||
mapboxMap.scrollBy(100f, 200f)
|
||||
verify { nativeMapView.moveBy(100.0, 200.0, 0) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResetNorth() {
|
||||
mapboxMap.resetNorth()
|
||||
verify { transform.resetNorth() }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFocalBearing() {
|
||||
mapboxMap.setFocalBearing(35.0, 100f, 200f, 1000)
|
||||
verify { transform.setBearing(35.0, 100f, 200f, 1000) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
mapboxMap.setMinZoomPreference(10.0)
|
||||
verify { transform.minZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
mapboxMap.setMaxZoomPreference(10.0)
|
||||
verify { transform.maxZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFpsListener() {
|
||||
val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>()
|
||||
mapboxMap.onFpsChangedListener = fpsChangedListener
|
||||
assertEquals("Listener should match", fpsChangedListener, mapboxMap.onFpsChangedListener)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTilePrefetch() {
|
||||
mapboxMap.prefetchesTiles = true
|
||||
verify { nativeMapView.prefetchTiles = true }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCameraForLatLngBounds() {
|
||||
val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build()
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(bounds)
|
||||
verify { nativeMapView.setLatLngBounds(bounds) }
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun testAnimateCameraChecksDurationPositive() {
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun testEaseCameraChecksDurationPositive() {
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetNativeMapPtr() {
|
||||
assertEquals(5, mapboxMap.nativeMapPtr)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNativeMapIsNotCalledOnStateSave() {
|
||||
clearMocks(nativeMapView)
|
||||
mapboxMap.onSaveInstanceState(mockk(relaxed = true))
|
||||
verify { nativeMapView wasNot Called }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCameraChangeDispatcherCleared() {
|
||||
mapboxMap.onDestroy()
|
||||
verify { cameraChangeDispatcher.onDestroy() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStyleClearedOnDestroy() {
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
mapboxMap.setStyle(builder)
|
||||
|
||||
mapboxMap.onDestroy()
|
||||
verify(exactly = 1) { style.clear() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStyleCallbackNotCalledWhenPreviousFailed() {
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true)
|
||||
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFailLoadingStyle()
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStyleCallbackNotCalledWhenPreviousNotFinished() {
|
||||
// regression test for #14337
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true)
|
||||
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.util.Pair
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils
|
||||
import io.mockk.mockk
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class StyleBuilderTest {
|
||||
|
||||
@Test
|
||||
fun testFromUrl() {
|
||||
val expected = Style.MAPBOX_STREETS
|
||||
val builder = Style.Builder()
|
||||
builder.fromUrl(expected)
|
||||
assertEquals(expected, builder.uri)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFromJson() {
|
||||
val expected = "{}"
|
||||
val builder = Style.Builder()
|
||||
builder.fromJson(expected)
|
||||
assertEquals(expected, builder.json)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayer() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
val builder = Style.Builder()
|
||||
builder.withLayer(layer)
|
||||
assertEquals(layer, builder.layers[0].layer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayers() {
|
||||
val layer1 = mockk<SymbolLayer>()
|
||||
val layer2 = mockk<SymbolLayer>()
|
||||
val builder = Style.Builder()
|
||||
builder.withLayers(layer1, layer2)
|
||||
assertEquals(layer1, builder.layers[0].layer)
|
||||
assertEquals(layer2, builder.layers[1].layer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayerAt() {
|
||||
val expectedIndex = 5
|
||||
val layer = mockk<SymbolLayer>()
|
||||
val builder = Style.Builder()
|
||||
builder.withLayerAt(layer, expectedIndex)
|
||||
assertEquals(layer, builder.layers[0].layer)
|
||||
assertEquals(expectedIndex, (builder.layers[0] as Style.Builder.LayerAtWrapper).index)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayerAbove() {
|
||||
val expectedAbove = "above"
|
||||
val layer = mockk<SymbolLayer>()
|
||||
val builder = Style.Builder()
|
||||
builder.withLayerAbove(layer, expectedAbove)
|
||||
assertEquals(layer, builder.layers[0].layer)
|
||||
assertEquals(expectedAbove, (builder.layers[0] as Style.Builder.LayerAboveWrapper).aboveLayer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayerBelow() {
|
||||
val expectedBelow = "above"
|
||||
val layer = mockk<SymbolLayer>()
|
||||
val builder = Style.Builder()
|
||||
builder.withLayerBelow(layer, expectedBelow)
|
||||
assertEquals(layer, builder.layers[0].layer)
|
||||
assertEquals(expectedBelow, (builder.layers[0] as Style.Builder.LayerBelowWrapper).belowLayer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithSource() {
|
||||
val source = mockk<GeoJsonSource>()
|
||||
val builder = Style.Builder()
|
||||
builder.withSource(source)
|
||||
assertEquals(source, builder.sources[0])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithSources() {
|
||||
val source1 = mockk<GeoJsonSource>()
|
||||
val source2 = mockk<GeoJsonSource>()
|
||||
val builder = Style.Builder()
|
||||
builder.withSources(source1, source2)
|
||||
assertEquals(source1, builder.sources[0])
|
||||
assertEquals(source2, builder.sources[1])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImage() {
|
||||
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
|
||||
val builder = Style.Builder()
|
||||
builder.withImage("id", bitmap)
|
||||
assertEquals(bitmap, builder.images[0].bitmap)
|
||||
assertEquals("id", builder.images[0].id)
|
||||
assertEquals(false, builder.images[0].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImages() {
|
||||
val bitmap1 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
|
||||
val bitmap2 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
|
||||
val builder = Style.Builder()
|
||||
builder.withBitmapImages(Pair("id1", bitmap1), Pair("id2", bitmap2))
|
||||
assertEquals(bitmap1, builder.images[0].bitmap)
|
||||
assertEquals("id1", builder.images[0].id)
|
||||
assertEquals(false, builder.images[0].sdf)
|
||||
assertEquals(bitmap2, builder.images[1].bitmap)
|
||||
assertEquals("id2", builder.images[1].id)
|
||||
assertEquals(false, builder.images[1].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageSdf() {
|
||||
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
|
||||
val builder = Style.Builder()
|
||||
builder.withImage("id", bitmap, true)
|
||||
assertEquals(bitmap, builder.images[0].bitmap)
|
||||
assertEquals("id", builder.images[0].id)
|
||||
assertEquals(true, builder.images[0].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageSdfs() {
|
||||
val bitmap1 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
|
||||
val bitmap2 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
|
||||
val builder = Style.Builder()
|
||||
builder.withBitmapImages(true, Pair("id1", bitmap1), Pair("id2", bitmap2))
|
||||
assertEquals(bitmap1, builder.images[0].bitmap)
|
||||
assertEquals("id1", builder.images[0].id)
|
||||
assertEquals(true, builder.images[0].sdf)
|
||||
assertEquals(bitmap2, builder.images[1].bitmap)
|
||||
assertEquals("id2", builder.images[1].id)
|
||||
assertEquals(true, builder.images[1].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageDrawable() {
|
||||
val drawable = ShapeDrawable()
|
||||
drawable.intrinsicWidth = 1
|
||||
drawable.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withImage("id", drawable)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable)!!,
|
||||
builder.images[0].bitmap)
|
||||
)
|
||||
assertEquals("id", builder.images[0].id)
|
||||
assertEquals(false, builder.images[0].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageDrawableSdf() {
|
||||
val drawable = ShapeDrawable()
|
||||
drawable.intrinsicWidth = 1
|
||||
drawable.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withImage("id", drawable, true)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable)!!,
|
||||
builder.images[0].bitmap)
|
||||
)
|
||||
assertEquals("id", builder.images[0].id)
|
||||
assertEquals(true, builder.images[0].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageDrawables() {
|
||||
val drawable1 = ShapeDrawable()
|
||||
drawable1.intrinsicWidth = 1
|
||||
drawable1.intrinsicHeight = 1
|
||||
val drawable2 = ShapeDrawable()
|
||||
drawable2.intrinsicWidth = 1
|
||||
drawable2.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withDrawableImages(Pair<String, Drawable>("id1", drawable1), Pair<String, Drawable>("id2", drawable2))
|
||||
assertTrue(BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable1)!!,
|
||||
builder.images[0].bitmap)
|
||||
)
|
||||
assertEquals("id1", builder.images[0].id)
|
||||
assertEquals(false, builder.images[0].sdf)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable2)!!,
|
||||
builder.images[1].bitmap)
|
||||
)
|
||||
assertEquals("id2", builder.images[1].id)
|
||||
assertEquals(false, builder.images[1].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageSdfDrawables() {
|
||||
val drawable1 = ShapeDrawable()
|
||||
drawable1.intrinsicWidth = 1
|
||||
drawable1.intrinsicHeight = 1
|
||||
val drawable2 = ShapeDrawable()
|
||||
drawable2.intrinsicWidth = 1
|
||||
drawable2.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withDrawableImages(true, Pair<String, Drawable>("id1", drawable1), Pair<String, Drawable>("id2", drawable2))
|
||||
assertTrue(BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable1)!!,
|
||||
builder.images[0].bitmap)
|
||||
)
|
||||
assertEquals("id1", builder.images[0].id)
|
||||
assertEquals(true, builder.images[0].sdf)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable2)!!,
|
||||
builder.images[1].bitmap)
|
||||
)
|
||||
assertEquals("id2", builder.images[1].id)
|
||||
assertEquals(true, builder.images[1].sdf)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithTransitionOptions() {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder()
|
||||
builder.withTransition(transitionOptions)
|
||||
assertEquals(100, builder.transitionOptions.duration)
|
||||
assertEquals(200, builder.transitionOptions.delay)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,408 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants
|
||||
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
|
||||
import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import io.mockk.*
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class StyleTest {
|
||||
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
nativeMapView = mockk(relaxed = true)
|
||||
mapboxMap = MapboxMap(nativeMapView, null, null, null, null, null, null)
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFromUrl() {
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFromJson() {
|
||||
val builder = Style.Builder().fromJson("{}")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleJson = "{}" }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmptyBuilder() {
|
||||
val builder = Style.Builder()
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleJson = Style.EMPTY_JSON }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayer() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().withLayer(layer)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayerAbove() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().withLayerAbove(layer, "id")
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addLayerAbove(layer, "id") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayerBelow() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().withLayerBelow(layer, "id")
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "id") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithLayerAt() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().withLayerAt(layer, 1)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithSource() {
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().withSource(source)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithTransitionOptions() {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder().withTransition(transitionOptions)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingSource() {
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingLayer() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayer(layer)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingLayerAt() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerAt(layer, 1)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingLayerBelow() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingLayerAbove() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingTransitionOptions() {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFromCallback() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
mapboxMap.setStyle(builder, callback)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithCallback() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().withSource(source)
|
||||
mapboxMap.setStyle(builder, callback)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetAsyncWith() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
mapboxMap.getStyle(callback)
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().withSource(source)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetAsyncFrom() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
mapboxMap.getStyle(callback)
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().fromJson("{}")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleJson = "{}" }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetAsyncWithFrom() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
mapboxMap.getStyle(callback)
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetNullStyle() {
|
||||
Assert.assertNull(mapboxMap.style)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetNullWhileLoading() {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions)
|
||||
mapboxMap.setStyle(builder)
|
||||
Assert.assertNull(mapboxMap.style)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
Assert.assertNotNull(mapboxMap.style)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNotReinvokeSameListener() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
mapboxMap.getStyle(callback)
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().fromJson("{}")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleJson = "{}" }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun testIllegalStateExceptionWithStyleReload() {
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
val style = mapboxMap.style
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
style!!.addLayer(mockk<SymbolLayer>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddImage() {
|
||||
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
|
||||
val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", bitmap)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.SATELLITE }
|
||||
verify(exactly = 0) { nativeMapView.addImages(any()) }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addImages(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddDrawable() {
|
||||
val drawable = ShapeDrawable()
|
||||
drawable.intrinsicHeight = 10
|
||||
drawable.intrinsicWidth = 10
|
||||
val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", drawable)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.SATELLITE }
|
||||
verify(exactly = 0) { nativeMapView.addImages(any()) }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addImages(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSourceSkippedIfAdditionFails() {
|
||||
val source1 = mockk<GeoJsonSource>(relaxed = true)
|
||||
every { source1.id } returns "source1"
|
||||
val source2 = mockk<GeoJsonSource>(relaxed = true)
|
||||
every { source2.id } returns "source1" // same ID
|
||||
|
||||
val builder = Style.Builder().withSource(source1)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addSource(any()) } throws CannotAddSourceException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addSource(source2)
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Source that failed to be added shouldn't be cached", source1, mapboxMap.style!!.getSource("source1"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLayerSkippedIfAdditionFails() {
|
||||
val layer1 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer1.id } returns "layer1"
|
||||
val layer2 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer2.id } returns "layer1" // same ID
|
||||
|
||||
val builder = Style.Builder().withLayer(layer1)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addLayer(any()) } throws CannotAddLayerException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addLayer(layer2)
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLayerSkippedIfAdditionBelowFails() {
|
||||
val layer1 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer1.id } returns "layer1"
|
||||
val layer2 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer2.id } returns "layer1" // same ID
|
||||
|
||||
val builder = Style.Builder().withLayer(layer1)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addLayerBelow(any(), "") } throws CannotAddLayerException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addLayerBelow(layer2, "")
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLayerSkippedIfAdditionAboveFails() {
|
||||
val layer1 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer1.id } returns "layer1"
|
||||
val layer2 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer2.id } returns "layer1" // same ID
|
||||
|
||||
val builder = Style.Builder().withLayer(layer1)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addLayerAbove(any(), "") } throws CannotAddLayerException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addLayerAbove(layer2, "")
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLayerSkippedIfAdditionAtFails() {
|
||||
val layer1 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer1.id } returns "layer1"
|
||||
val layer2 = mockk<SymbolLayer>(relaxed = true)
|
||||
every { layer2.id } returns "layer1" // same ID
|
||||
|
||||
val builder = Style.Builder().withLayer(layer1)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addLayerAt(any(), 5) } throws CannotAddLayerException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addLayerAt(layer2, 5)
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import io.mockk.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class TransformTest {
|
||||
|
||||
private lateinit var mapView: MapView
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
private lateinit var transform: Transform
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
val cameraChangeDispatcher = spyk<CameraChangeDispatcher>()
|
||||
mapView = mockk()
|
||||
nativeMapView = mockk()
|
||||
transform = Transform(mapView, nativeMapView, cameraChangeDispatcher)
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT
|
||||
every { nativeMapView.cancelTransitions() } answers {}
|
||||
every { nativeMapView.jumpTo(any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.minZoom = any() } answers {}
|
||||
every { nativeMapView.maxZoom = any() } answers {}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0, null) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.moveCamera(mapboxMap, update, null) // Initialize camera position
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify(exactly = 1, verifyBlock = { nativeMapView.jumpTo(any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify { nativeMapView.easeTo(target, -1.0, -1.0, -1.0, null, 100, false) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify { nativeMapView.flyTo(target, -1.0, -1.0, -1.0, null, 100) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
transform.minZoom = 10.0
|
||||
verify { nativeMapView.minZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
transform.maxZoom = 10.0
|
||||
verify { nativeMapView.maxZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCancelNotInvokedFromOnFinish() {
|
||||
val slot = slot<MapView.OnCameraDidChangeListener>()
|
||||
every { mapView.addOnCameraDidChangeListener(capture(slot)) } answers { slot.captured.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
// regression test for https://github.com/mapbox/mapbox-gl-native/issues/13735
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
|
||||
val callback = object : MapboxMap.CancelableCallback {
|
||||
override fun onCancel() {
|
||||
throw IllegalStateException("onCancel shouldn't be called from onFinish")
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, null)
|
||||
}
|
||||
}
|
||||
transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, callback)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UiSettingsTest {
|
||||
|
||||
@InjectMocks
|
||||
Projection projection = mock(Projection.class);
|
||||
|
||||
@InjectMocks
|
||||
FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class);
|
||||
|
||||
@InjectMocks
|
||||
CompassView compassView = mock(CompassView.class);
|
||||
|
||||
@InjectMocks
|
||||
ImageView imageView = mock(ImageView.class);
|
||||
|
||||
@InjectMocks
|
||||
ImageView logoView = mock(ImageView.class);
|
||||
|
||||
@InjectMocks
|
||||
FrameLayout.LayoutParams layoutParams = mock(FrameLayout.LayoutParams.class);
|
||||
|
||||
private UiSettings uiSettings;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
uiSettings = new UiSettings(projection, focalPointChangeListener, compassView, imageView, logoView, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("uiSettings should not be null", uiSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassEnabled() {
|
||||
when(compassView.isEnabled()).thenReturn(true);
|
||||
uiSettings.setCompassEnabled(true);
|
||||
assertEquals("Compass should be enabled", true, uiSettings.isCompassEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassDisabled() {
|
||||
uiSettings.setCompassEnabled(false);
|
||||
assertEquals("Compass should be disabled", false, uiSettings.isCompassEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassGravity() {
|
||||
when(compassView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.gravity = Gravity.START;
|
||||
uiSettings.setCompassGravity(Gravity.START);
|
||||
assertEquals("Compass gravity should be same", Gravity.START, uiSettings.getCompassGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassMargins() {
|
||||
when(projection.getContentPadding()).thenReturn(new int[] {0, 0, 0, 0});
|
||||
when(compassView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.leftMargin = 1;
|
||||
layoutParams.topMargin = 2;
|
||||
layoutParams.rightMargin = 3;
|
||||
layoutParams.bottomMargin = 4;
|
||||
uiSettings.setCompassMargins(1, 2, 3, 4);
|
||||
assertTrue("Compass margin left should be same", uiSettings.getCompassMarginLeft() == 1);
|
||||
assertTrue("Compass margin top should be same", uiSettings.getCompassMarginTop() == 2);
|
||||
assertTrue("Compass margin right should be same", uiSettings.getCompassMarginRight() == 3);
|
||||
assertTrue("Compass margin bottom should be same", uiSettings.getCompassMarginBottom() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassFadeWhenFacingNorth() {
|
||||
when(compassView.isFadeCompassViewFacingNorth()).thenReturn(true);
|
||||
assertTrue("Compass should fade when facing north by default.", uiSettings.isCompassFadeWhenFacingNorth());
|
||||
uiSettings.setCompassFadeFacingNorth(false);
|
||||
when(compassView.isFadeCompassViewFacingNorth()).thenReturn(false);
|
||||
assertFalse("Compass fading should be disabled", uiSettings.isCompassFadeWhenFacingNorth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoEnabled() {
|
||||
uiSettings.setLogoEnabled(true);
|
||||
assertEquals("Logo should be enabled", true, uiSettings.isLogoEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoDisabled() {
|
||||
when(logoView.getVisibility()).thenReturn(View.GONE);
|
||||
uiSettings.setLogoEnabled(false);
|
||||
assertEquals("Logo should be disabled", false, uiSettings.isLogoEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoGravity() {
|
||||
layoutParams.gravity = Gravity.END;
|
||||
when(logoView.getLayoutParams()).thenReturn(layoutParams);
|
||||
uiSettings.setLogoGravity(Gravity.END);
|
||||
assertEquals("Logo gravity should be same", Gravity.END, uiSettings.getLogoGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoMargins() {
|
||||
when(projection.getContentPadding()).thenReturn(new int[] {0, 0, 0, 0});
|
||||
when(logoView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.leftMargin = 1;
|
||||
layoutParams.topMargin = 2;
|
||||
layoutParams.rightMargin = 3;
|
||||
layoutParams.bottomMargin = 4;
|
||||
uiSettings.setLogoMargins(1, 2, 3, 4);
|
||||
assertTrue("Compass margin left should be same", uiSettings.getLogoMarginLeft() == 1);
|
||||
assertTrue("Compass margin top should be same", uiSettings.getLogoMarginTop() == 2);
|
||||
assertTrue("Compass margin right should be same", uiSettings.getLogoMarginRight() == 3);
|
||||
assertTrue("Compass margin bottom should be same", uiSettings.getLogoMarginBottom() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionEnabled() {
|
||||
when(imageView.getVisibility()).thenReturn(View.VISIBLE);
|
||||
uiSettings.setAttributionEnabled(true);
|
||||
assertEquals("Attribution should be enabled", true, uiSettings.isAttributionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionDisabled() {
|
||||
when(imageView.getVisibility()).thenReturn(View.GONE);
|
||||
uiSettings.setAttributionEnabled(false);
|
||||
assertEquals("Attribution should be disabled", false, uiSettings.isAttributionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionGravity() {
|
||||
when(imageView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.gravity = Gravity.END;
|
||||
uiSettings.setAttributionGravity(Gravity.END);
|
||||
assertEquals("Attribution gravity should be same", Gravity.END, uiSettings.getAttributionGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionMargins() {
|
||||
when(imageView.getLayoutParams()).thenReturn(layoutParams);
|
||||
when(projection.getContentPadding()).thenReturn(new int[] {0, 0, 0, 0});
|
||||
layoutParams.leftMargin = 1;
|
||||
layoutParams.topMargin = 2;
|
||||
layoutParams.rightMargin = 3;
|
||||
layoutParams.bottomMargin = 4;
|
||||
uiSettings.setAttributionMargins(1, 2, 3, 4);
|
||||
assertTrue("Attribution margin left should be same", uiSettings.getAttributionMarginLeft() == 1);
|
||||
assertTrue("Attribution margin top should be same", uiSettings.getAttributionMarginTop() == 2);
|
||||
assertTrue("Attribution margin right should be same", uiSettings.getAttributionMarginRight() == 3);
|
||||
assertTrue("Attribution margin bottom should be same", uiSettings.getAttributionMarginBottom() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGesturesEnabled() {
|
||||
uiSettings.setRotateGesturesEnabled(true);
|
||||
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGesturesDisabled() {
|
||||
uiSettings.setRotateGesturesEnabled(false);
|
||||
assertEquals("Rotate gesture should be disabled", false, uiSettings.isRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGestureChangeAllowed() {
|
||||
uiSettings.setRotateGesturesEnabled(false);
|
||||
assertEquals("Rotate gesture should be false", false, uiSettings.isRotateGesturesEnabled());
|
||||
uiSettings.setRotateGesturesEnabled(true);
|
||||
assertEquals("Rotate gesture should be true", true, uiSettings.isRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGesturesEnabled() {
|
||||
uiSettings.setTiltGesturesEnabled(true);
|
||||
assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGesturesDisabled() {
|
||||
uiSettings.setTiltGesturesEnabled(false);
|
||||
assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGestureChangeAllowed() {
|
||||
uiSettings.setTiltGesturesEnabled(false);
|
||||
assertEquals("Tilt gesture should be false", false, uiSettings.isTiltGesturesEnabled());
|
||||
uiSettings.setTiltGesturesEnabled(true);
|
||||
assertEquals("Tilt gesture should be true", true, uiSettings.isTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGesturesEnabled() {
|
||||
uiSettings.setZoomGesturesEnabled(true);
|
||||
assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGesturesDisabled() {
|
||||
uiSettings.setZoomGesturesEnabled(false);
|
||||
assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGestureChangeAllowed() {
|
||||
uiSettings.setZoomGesturesEnabled(false);
|
||||
assertEquals("Zoom gesture should be false", false, uiSettings.isZoomGesturesEnabled());
|
||||
uiSettings.setZoomGesturesEnabled(true);
|
||||
assertEquals("Zoom gesture should be true", true, uiSettings.isZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleTapGesturesEnabled() {
|
||||
uiSettings.setDoubleTapGesturesEnabled(true);
|
||||
assertEquals("DoubleTap gesture should be enabled", true, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleTapGesturesDisabled() {
|
||||
uiSettings.setDoubleTapGesturesEnabled(false);
|
||||
assertEquals("DoubleTap gesture should be disabled", false, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleTapGestureChangeAllowed() {
|
||||
uiSettings.setDoubleTapGesturesEnabled(false);
|
||||
assertEquals("DoubleTap gesture should be false", false, uiSettings.isDoubleTapGesturesEnabled());
|
||||
uiSettings.setDoubleTapGesturesEnabled(true);
|
||||
assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGesturesEnabled() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(true);
|
||||
assertEquals("QuickZoom gesture should be enabled", true, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGesturesDisabled() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(false);
|
||||
assertEquals("QuickZoom gesture should be disabled", false, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGestureChangeAllowed() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(false);
|
||||
assertEquals("QuickZoom gesture should be false", false, uiSettings.isQuickZoomGesturesEnabled());
|
||||
uiSettings.setQuickZoomGesturesEnabled(true);
|
||||
assertEquals("QuickZoom gesture should be true", true, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesEnabled() {
|
||||
uiSettings.setScrollGesturesEnabled(true);
|
||||
assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesDisabled() {
|
||||
uiSettings.setScrollGesturesEnabled(false);
|
||||
assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGestureChangeAllowed() {
|
||||
uiSettings.setScrollGesturesEnabled(false);
|
||||
assertEquals("Scroll gesture should be false", false, uiSettings.isScrollGesturesEnabled());
|
||||
uiSettings.setScrollGesturesEnabled(true);
|
||||
assertEquals("Scroll gesture should be true", true, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScaleVelocityAnimationEnabled() {
|
||||
uiSettings.setScaleVelocityAnimationEnabled(true);
|
||||
assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScaleVelocityAnimationDisabled() {
|
||||
uiSettings.setScaleVelocityAnimationEnabled(false);
|
||||
assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateVelocityAnimationEnabled() {
|
||||
uiSettings.setRotateVelocityAnimationEnabled(true);
|
||||
assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateVelocityAnimationDisabled() {
|
||||
uiSettings.setRotateVelocityAnimationEnabled(false);
|
||||
assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlingVelocityAnimationEnabled() {
|
||||
uiSettings.setFlingVelocityAnimationEnabled(true);
|
||||
assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlingVelocityAnimationDisabled() {
|
||||
uiSettings.setFlingVelocityAnimationEnabled(false);
|
||||
assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllVelocityAnimationsEnabled() {
|
||||
uiSettings.setAllVelocityAnimationsEnabled(true);
|
||||
assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllVelocityAnimationsDisabled() {
|
||||
uiSettings.setAllVelocityAnimationsEnabled(false);
|
||||
assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableRotateWhenScalingEnabled() {
|
||||
uiSettings.setDisableRotateWhenScaling(true);
|
||||
assertEquals("Rotate disabling should be enabled", true,
|
||||
uiSettings.isDisableRotateWhenScaling());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableRotateWhenScalingDisabled() {
|
||||
uiSettings.setDisableRotateWhenScaling(false);
|
||||
assertEquals("Rotate disabling should be disabled", false,
|
||||
uiSettings.isDisableRotateWhenScaling());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncreaseScaleThresholdWhenRotatingEnabled() {
|
||||
uiSettings.setIncreaseScaleThresholdWhenRotating(true);
|
||||
assertEquals("Scale threshold increase should be enabled", true, uiSettings.isIncreaseScaleThresholdWhenRotating());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncreaseScaleThresholdWhenRotatingDisabled() {
|
||||
uiSettings.setIncreaseScaleThresholdWhenRotating(false);
|
||||
assertEquals("Scale threshold increase should be disabled", false,
|
||||
uiSettings.isIncreaseScaleThresholdWhenRotating());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllGesturesEnabled() {
|
||||
uiSettings.setAllGesturesEnabled(true);
|
||||
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());
|
||||
assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled());
|
||||
assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled());
|
||||
assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllGesturesDisabled() {
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
assertEquals("Rotate gesture should be enabled", false, uiSettings.isRotateGesturesEnabled());
|
||||
assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled());
|
||||
assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled());
|
||||
assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAreAllGesturesEnabled() {
|
||||
uiSettings.setAllGesturesEnabled(true);
|
||||
assertEquals("All gestures check should return true", true,
|
||||
uiSettings.areAllGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAreAllGesturesEnabledWithOneGestureDisabled() {
|
||||
uiSettings.setAllGesturesEnabled(true);
|
||||
uiSettings.setScrollGesturesEnabled(false);
|
||||
assertEquals("All gestures check should return false", false,
|
||||
uiSettings.areAllGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomRateDefaultValue() {
|
||||
assertEquals("Default zoom rate should be 1.0f", 1.0f,
|
||||
uiSettings.getZoomRate(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomRate() {
|
||||
uiSettings.setZoomRate(0.83f);
|
||||
assertEquals("Zoom rate should be 0.83f", 0.83f,
|
||||
uiSettings.getZoomRate(), 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mapbox.mapboxsdk.module.http
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxInjector
|
||||
import com.mapbox.mapboxsdk.http.HttpRequestUrl
|
||||
import io.mockk.mockk
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class HttpRequestUrlTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "pk.foobar", "foobar")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineFlagMapboxCom() {
|
||||
val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineFlagMapboxCn() {
|
||||
val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineFlagInvalidHost() {
|
||||
val expected = "http://foobar.com/path/of/no/return.pbf"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("foobar.com", "http://foobar.com/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnlineMapboxCom() {
|
||||
val expected = "http://mapbox.com/path/of/no/return.pbf?sku=foobar"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnlineMapboxCn() {
|
||||
val expected = "http://mapbox.cn/path/of/no/return.pbf?sku=foobar"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnlineInvalidHost() {
|
||||
val expected = "http://foobar.com/path/of/no/return.pbf"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("foobar.com", "http://foobar.com/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
MapboxInjector.clear()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.mapbox.mapboxsdk.module.http
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxInjector
|
||||
import io.mockk.mockk
|
||||
import junit.framework.Assert.assertEquals
|
||||
import okhttp3.OkHttpClient
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class HttpRequestUtilTest {
|
||||
|
||||
@Test
|
||||
fun replaceHttpClient() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "")
|
||||
|
||||
assertEquals(HttpRequestImpl.DEFAULT_CLIENT, HttpRequestImpl.client)
|
||||
|
||||
val httpMock = mockk<OkHttpClient>()
|
||||
HttpRequestUtil.setOkHttpClient(httpMock)
|
||||
assertEquals("Http client should have set to the mocked client",
|
||||
httpMock,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
|
||||
HttpRequestUtil.setOkHttpClient(null)
|
||||
assertEquals("Http client should have been reset to the default client",
|
||||
HttpRequestImpl.DEFAULT_CLIENT,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
|
||||
MapboxInjector.clear()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegion;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.mapbox.mapboxsdk.module.telemetry.PerformanceEvent.PerformanceAttribute;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MapEventFactoryTest {
|
||||
private static final float FONT_SCALE = 1.f;
|
||||
private static final int BATTERY_LEVEL = 50;
|
||||
private static final String CARRIER = "carrier";
|
||||
private static final String NETWORK_TYPE = "network";
|
||||
private static final String CREATED = "2019-04-09";
|
||||
private static final boolean PLUGIN = true;
|
||||
private static final float RESOLUTION = 1024.f;
|
||||
private static final boolean WIFI = true;
|
||||
private static final String SHAPE = "shape";
|
||||
private static final Double MIN_ZOOM = 1.0;
|
||||
private static final Double MAX_ZOOM = 10.0;
|
||||
private static final String STYLE_URL = "style url";
|
||||
private static final long SIZE_OF_RESOURCES_COMPLETED = 100;
|
||||
private static final long NUMBER_OF_TILE_COMPLETED = 1000;
|
||||
private static final int STATE = OfflineRegion.STATE_ACTIVE;
|
||||
private static final String SESSION_ID = "001";
|
||||
|
||||
private PhoneState phoneState;
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
phoneState = new PhoneState();
|
||||
phoneState.setAccessibilityFontScale(FONT_SCALE);
|
||||
phoneState.setBatteryLevel(BATTERY_LEVEL);
|
||||
phoneState.setCarrier(CARRIER);
|
||||
phoneState.setCellularNetworkType(NETWORK_TYPE);
|
||||
phoneState.setCreated(CREATED);
|
||||
phoneState.setOrientation(PhoneState.Orientation.ORIENTATION_LANDSCAPE);
|
||||
phoneState.setPluggedIn(PLUGIN);
|
||||
phoneState.setResolution(RESOLUTION);
|
||||
phoneState.setWifi(WIFI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapLoadEvent() {
|
||||
MapLoadEvent mapLoadEvent = MapEventFactory.buildMapLoadEvent(phoneState);
|
||||
assertEquals("Android - " + Build.VERSION.RELEASE, mapLoadEvent.getOperatingSystem());
|
||||
assertEquals(Build.MODEL, mapLoadEvent.getModel());
|
||||
assertNotNull(mapLoadEvent.getUserId());
|
||||
assertEquals(BATTERY_LEVEL, mapLoadEvent.getBatteryLevel());
|
||||
assertEquals(CARRIER, mapLoadEvent.getCarrier());
|
||||
assertEquals(NETWORK_TYPE, mapLoadEvent.getCellularNetworkType());
|
||||
assertEquals(CREATED, mapLoadEvent.getCreated());
|
||||
assertEquals("Landscape", mapLoadEvent.getOrientation());
|
||||
assertEquals(BuildConfig.MAPBOX_SDK_IDENTIFIER, mapLoadEvent.getSdkIdentifier());
|
||||
assertEquals(BuildConfig.MAPBOX_SDK_VERSION, mapLoadEvent.getSdkVersion());
|
||||
assertEquals(PLUGIN, mapLoadEvent.isPluggedIn());
|
||||
assertEquals(WIFI, mapLoadEvent.isWifi());
|
||||
assertEquals(FONT_SCALE, mapLoadEvent.getAccessibilityFontScale(), 0);
|
||||
String json = gson.toJson(mapLoadEvent);
|
||||
MapLoadEvent event = gson.fromJson(json, MapLoadEvent.class);
|
||||
assertEquals(mapLoadEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfflineDownloadEndEvent() {
|
||||
OfflineDownloadEndEvent offlineDownloadEndEvent = MapEventFactory.buildOfflineDownloadCompleteEvent(phoneState,
|
||||
SHAPE, MIN_ZOOM, MAX_ZOOM, STYLE_URL, SIZE_OF_RESOURCES_COMPLETED, NUMBER_OF_TILE_COMPLETED, STATE);
|
||||
assertEquals(SHAPE, offlineDownloadEndEvent.getShapeForOfflineRegion());
|
||||
assertEquals(MIN_ZOOM, offlineDownloadEndEvent.getMinZoom());
|
||||
assertEquals(MAX_ZOOM, offlineDownloadEndEvent.getMaxZoom());
|
||||
assertEquals(STYLE_URL, offlineDownloadEndEvent.getStyleURL());
|
||||
assertEquals(SIZE_OF_RESOURCES_COMPLETED, offlineDownloadEndEvent.getSizeOfResourcesCompleted());
|
||||
assertEquals(NUMBER_OF_TILE_COMPLETED, offlineDownloadEndEvent.getNumberOfTilesCompleted());
|
||||
assertEquals(String.valueOf(STATE), offlineDownloadEndEvent.getState());
|
||||
assertEquals(CREATED, offlineDownloadEndEvent.getCreated());
|
||||
String json = gson.toJson(offlineDownloadEndEvent);
|
||||
OfflineDownloadEndEvent event = gson.fromJson(json, OfflineDownloadEndEvent.class);
|
||||
assertEquals(offlineDownloadEndEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfflineDownloadStartEvent() {
|
||||
OfflineDownloadStartEvent offlineDownloadStartEvent = MapEventFactory.buildOfflineDownloadStartEvent(phoneState,
|
||||
SHAPE, MIN_ZOOM, MAX_ZOOM, STYLE_URL);
|
||||
assertEquals(SHAPE, offlineDownloadStartEvent.getShapeForOfflineRegion());
|
||||
assertEquals(MIN_ZOOM, offlineDownloadStartEvent.getMinZoom());
|
||||
assertEquals(MAX_ZOOM, offlineDownloadStartEvent.getMaxZoom());
|
||||
assertEquals(STYLE_URL, offlineDownloadStartEvent.getStyleURL());
|
||||
assertEquals(CREATED, offlineDownloadStartEvent.getCreated());
|
||||
String json = gson.toJson(offlineDownloadStartEvent);
|
||||
OfflineDownloadStartEvent event = gson.fromJson(json, OfflineDownloadStartEvent.class);
|
||||
assertEquals(offlineDownloadStartEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerformanceEvent() {
|
||||
String nameAttribute = "nameAttribute";
|
||||
String valueAttribute = "100";
|
||||
String nameCounters = "nameCounters";
|
||||
Double valuesCounters = 1000.0;
|
||||
JsonObject metaData = new JsonObject();
|
||||
metaData.addProperty("os", "android");
|
||||
metaData.addProperty("manufacturer", Build.MANUFACTURER);
|
||||
metaData.addProperty("brand", Build.BRAND);
|
||||
metaData.addProperty("device", Build.MODEL);
|
||||
metaData.addProperty("version", Build.VERSION.RELEASE);
|
||||
metaData.addProperty("abi", Build.CPU_ABI);
|
||||
metaData.addProperty("country", Locale.getDefault().getISO3Country());
|
||||
metaData.addProperty("ram", "ram");
|
||||
metaData.addProperty("screenSize", "1000");
|
||||
|
||||
Bundle data = mock(Bundle.class);
|
||||
ArrayList<PerformanceEvent.PerformanceAttribute<String>> attribtueList = new ArrayList<>();
|
||||
PerformanceAttribute<String> attribute = new PerformanceAttribute<>(nameAttribute, valueAttribute);
|
||||
attribtueList.add(attribute);
|
||||
ArrayList<PerformanceEvent.PerformanceAttribute<Double>> countersList = new ArrayList<>();
|
||||
PerformanceAttribute<Double> counter = new PerformanceAttribute<>(nameCounters, valuesCounters);
|
||||
countersList.add(counter);
|
||||
when(data.getString("attributes")).thenReturn(gson.toJson(attribtueList));
|
||||
when(data.getString("counters")).thenReturn(gson.toJson(countersList));
|
||||
when(data.getString("metadata")).thenReturn(metaData.toString());
|
||||
PerformanceEvent performanceEvent = MapEventFactory.buildPerformanceEvent(phoneState,
|
||||
SESSION_ID, data);
|
||||
assertEquals(CREATED, performanceEvent.getCreated());
|
||||
assertEquals(metaData.toString(), performanceEvent.getMetadata().toString());
|
||||
assertEquals(SESSION_ID, performanceEvent.getSessionId());
|
||||
List<PerformanceEvent.PerformanceAttribute<String>> attributeList = performanceEvent.getAttributes();
|
||||
assertEquals(1, attribtueList.size());
|
||||
assertEquals(attribute, attribtueList.get(0));
|
||||
List<PerformanceEvent.PerformanceAttribute<Double>> counterList = performanceEvent.getCounters();
|
||||
assertEquals(1, counterList.size());
|
||||
assertEquals(counter, counterList.get(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Ignore("mapbox-gl-native#14691")
|
||||
public class SchemaTest {
|
||||
private static final String MAP_LOAD = "map.load";
|
||||
private static final String MAP_PERFORMANCE = "mobile.performance_trace";
|
||||
private static final String OFFLINE_DOWNLOAD_END = "map.offlineDownload.end";
|
||||
private static final String OFFLINE_DOWNLOAD_START = "map.offlineDownload.start";
|
||||
private static ArrayList<JsonObject> schemaArray;
|
||||
|
||||
@BeforeClass
|
||||
public static void downloadSchema() throws Exception {
|
||||
unpackSchemas();
|
||||
}
|
||||
|
||||
private static ByteArrayInputStream getFileBytes() throws IOException {
|
||||
InputStream inputStream = SchemaTest.class.getClassLoader().getResourceAsStream("mobile-event-schemas.jsonl.gz");
|
||||
byte[] byteOut = IOUtils.toByteArray(inputStream);
|
||||
|
||||
return new ByteArrayInputStream(byteOut);
|
||||
}
|
||||
|
||||
private static void unpackSchemas() throws IOException {
|
||||
ByteArrayInputStream bais = getFileBytes();
|
||||
GZIPInputStream gzis = new GZIPInputStream(bais);
|
||||
InputStreamReader reader = new InputStreamReader(gzis);
|
||||
BufferedReader in = new BufferedReader(reader);
|
||||
|
||||
schemaArray = new ArrayList<>();
|
||||
|
||||
Gson gson = new Gson();
|
||||
String readed;
|
||||
while ((readed = in.readLine()) != null) {
|
||||
JsonObject schema = gson.fromJson(readed, JsonObject.class);
|
||||
schemaArray.add(schema);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkOfflineDownloadEndEventSize() {
|
||||
JsonObject schema = grabSchema(OFFLINE_DOWNLOAD_END);
|
||||
List<Field> fields = grabClassFields(OfflineDownloadEndEvent.class);
|
||||
|
||||
assertEquals(schema.size(), fields.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkOfflineDownloadEndEventFields() {
|
||||
JsonObject schema = grabSchema(OFFLINE_DOWNLOAD_END);
|
||||
List<Field> fields = grabClassFields(OfflineDownloadEndEvent.class);
|
||||
|
||||
schemaContainsFields(schema, fields);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkOfflineDownloadStartEventSize() {
|
||||
JsonObject schema = grabSchema(OFFLINE_DOWNLOAD_START);
|
||||
List<Field> fields = grabClassFields(OfflineDownloadStartEvent.class);
|
||||
|
||||
assertEquals(schema.size(), fields.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkOfflineDownloadStartEventFields() {
|
||||
JsonObject schema = grabSchema(OFFLINE_DOWNLOAD_START);
|
||||
List<Field> fields = grabClassFields(OfflineDownloadStartEvent.class);
|
||||
|
||||
schemaContainsFields(schema, fields);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMapLoadEventSize() {
|
||||
JsonObject schema = grabSchema(MAP_LOAD);
|
||||
List<Field> fields = grabClassFields(MapLoadEvent.class);
|
||||
|
||||
assertEquals(schema.size(), fields.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMapLoadEventFields() {
|
||||
JsonObject schema = grabSchema(MAP_LOAD);
|
||||
List<Field> fields = grabClassFields(MapLoadEvent.class);
|
||||
|
||||
schemaContainsFields(schema, fields);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPerformanceEventSize() {
|
||||
JsonObject schema = grabSchema(MAP_PERFORMANCE);
|
||||
List<Field> fields = grabClassFields(PerformanceEvent.class);
|
||||
|
||||
assertEquals(schema.size(), fields.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPerformanceEventFields() {
|
||||
JsonObject schema = grabSchema(MAP_PERFORMANCE);
|
||||
List<Field> fields = grabClassFields(PerformanceEvent.class);
|
||||
|
||||
schemaContainsFields(schema, fields);
|
||||
}
|
||||
|
||||
private void schemaContainsFields(JsonObject schema, List<Field> fields) {
|
||||
int distanceRemainingCount = 0;
|
||||
int durationRemainingCount = 0;
|
||||
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
String thisField = String.valueOf(fields.get(i));
|
||||
String[] fieldArray = thisField.split(" ");
|
||||
String[] typeArray = fieldArray[fieldArray.length - 2].split("\\.");
|
||||
String type = typeArray[typeArray.length - 1];
|
||||
|
||||
String[] nameArray = fieldArray[fieldArray.length - 1].split("\\.");
|
||||
String field = nameArray[nameArray.length - 1];
|
||||
|
||||
SerializedName serializedName = fields.get(i).getAnnotation(SerializedName.class);
|
||||
|
||||
if (serializedName != null) {
|
||||
field = serializedName.value();
|
||||
}
|
||||
|
||||
if (field.equalsIgnoreCase("durationRemaining")) {
|
||||
durationRemainingCount++;
|
||||
|
||||
if (durationRemainingCount > 1) {
|
||||
field = "step" + field;
|
||||
}
|
||||
}
|
||||
|
||||
if (field.equalsIgnoreCase("distanceRemaining")) {
|
||||
distanceRemainingCount++;
|
||||
|
||||
if (distanceRemainingCount > 1) {
|
||||
field = "step" + field;
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject thisSchema = findSchema(schema, field);
|
||||
assertNotNull(thisSchema);
|
||||
|
||||
if (thisSchema.has("type")) {
|
||||
typesMatch(thisSchema, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JsonObject findSchema(JsonObject schema, String field) {
|
||||
JsonObject thisSchema = schema.getAsJsonObject(field);
|
||||
|
||||
return thisSchema;
|
||||
}
|
||||
|
||||
private void typesMatch(JsonObject schema, String type) {
|
||||
if (type.equalsIgnoreCase("int") || type.equalsIgnoreCase("integer")
|
||||
|| type.equalsIgnoreCase("double") || type.equalsIgnoreCase("float")
|
||||
|| type.equalsIgnoreCase("long")) {
|
||||
type = "number";
|
||||
}
|
||||
|
||||
if (type.contains("[]") || type.equalsIgnoreCase("list")) {
|
||||
type = "array";
|
||||
}
|
||||
if (type.equalsIgnoreCase("jsonobject")) {
|
||||
type = "object";
|
||||
}
|
||||
Class<? extends JsonElement> typeClass = schema.get("type").getClass();
|
||||
JsonElement jsonElement = new JsonParser().parse(type.toLowerCase());
|
||||
|
||||
if (typeClass == JsonPrimitive.class) {
|
||||
JsonElement typePrimitive = schema.get("type");
|
||||
assertTrue(typePrimitive.equals(jsonElement));
|
||||
} else {
|
||||
JsonArray arrayOfTypes = schema.getAsJsonArray("type");
|
||||
assertTrue(arrayOfTypes.contains(jsonElement));
|
||||
}
|
||||
}
|
||||
|
||||
private JsonObject grabSchema(String eventName) {
|
||||
for (JsonObject thisSchema : schemaArray) {
|
||||
String name = thisSchema.get("name").getAsString();
|
||||
|
||||
if (name.equalsIgnoreCase(eventName)) {
|
||||
Gson gson = new Gson();
|
||||
String schemaString = gson.toJson(thisSchema.get("properties"));
|
||||
JsonObject schema = gson.fromJson(thisSchema.get("properties"), JsonObject.class);
|
||||
|
||||
if (schema.has("step")) {
|
||||
JsonObject stepJson = schema.get("step").getAsJsonObject();
|
||||
JsonObject stepProperties = stepJson.get("properties").getAsJsonObject();
|
||||
|
||||
String stepPropertiesJson = gson.toJson(stepProperties);
|
||||
schemaString = generateStepSchemaString(stepPropertiesJson, schemaString);
|
||||
|
||||
schema = gson.fromJson(schemaString, JsonObject.class);
|
||||
schema.remove("step");
|
||||
}
|
||||
|
||||
schema.remove("userAgent");
|
||||
schema.remove("received");
|
||||
schema.remove("token");
|
||||
schema.remove("authorization");
|
||||
schema.remove("owner");
|
||||
schema.remove("locationAuthorization");
|
||||
schema.remove("locationEnabled");
|
||||
schema.remove("skuId");
|
||||
//temporary need to work out a solution to include this data
|
||||
schema.remove("platform");
|
||||
|
||||
return schema;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Field> grabClassFields(Class aClass) {
|
||||
List<Field> fields = new ArrayList<>();
|
||||
Field[] allFields = aClass.getDeclaredFields();
|
||||
for (Field field : allFields) {
|
||||
if (Modifier.isPrivate(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
|
||||
fields.add(field);
|
||||
}
|
||||
}
|
||||
Field[] superFields = aClass.getSuperclass().getDeclaredFields();
|
||||
for (Field field : superFields) {
|
||||
if (Modifier.isPrivate(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
|
||||
fields.add(field);
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
private String generateStepSchemaString(String stepJson, String schemaString) {
|
||||
stepJson = stepJson.replace("\"distanceRemaining\"", "\"stepdistanceRemaining\"");
|
||||
stepJson = stepJson.replace("durationRemaining", "stepdurationRemaining");
|
||||
stepJson = stepJson.replaceFirst("\\{", ",");
|
||||
schemaString = schemaString.replaceAll("}$", "");
|
||||
schemaString = schemaString + stepJson;
|
||||
|
||||
return schemaString;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
package com.mapbox.mapboxsdk.telemetry;
|
||||
|
||||
import com.mapbox.android.telemetry.TelemetryUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
public class HttpTransportTest {
|
||||
|
||||
@Test
|
||||
public void testNonAsciiUserAgent() {
|
||||
|
||||
final String swedishUserAgent = "Sveriges Fjäll/1.0/1 MapboxEventsAndroid/4.0.0-SNAPSHOT";
|
||||
final String asciiVersion = "Sveriges Fj?ll/1.0/1 MapboxEventsAndroid/4.0.0-SNAPSHOT";
|
||||
|
||||
assertEquals("asciiVersion and swedishUserAgent should match", asciiVersion,
|
||||
TelemetryUtils.toHumanReadableAscii(swedishUserAgent));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mapbox.mapboxsdk.utils
|
||||
|
||||
import android.graphics.Color
|
||||
import junit.framework.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class ColorUtilsTest {
|
||||
|
||||
@Test
|
||||
fun rgbaToColor_decimalComponent() {
|
||||
val input = "rgba(255,128.0000952303,0,0.7)"
|
||||
val result = ColorUtils.rgbaToColor(input)
|
||||
Assert.assertEquals(Color.argb(255, 128, 0, (0.7 * 255).toInt()), result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rgbaToColor_decimalComponent_floor() {
|
||||
val input = "rgba(255,128.70123,0,0.7)"
|
||||
val result = ColorUtils.rgbaToColor(input)
|
||||
Assert.assertEquals(Color.argb(255, 128, 0, (0.7 * 255).toInt()), result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package com.mapbox.mapboxsdk.utils;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyByte;
|
||||
import static org.mockito.Matchers.anyDouble;
|
||||
import static org.mockito.Matchers.anyFloat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MockParcel {
|
||||
|
||||
@Nullable
|
||||
public static Parcelable obtain(@NonNull Parcelable object) {
|
||||
return obtain(object, 0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Parcelable obtain(@NonNull Parcelable object, int describeContentsValue) {
|
||||
testDescribeContents(object, describeContentsValue);
|
||||
testParcelableArray(object);
|
||||
return testParcelable(object);
|
||||
}
|
||||
|
||||
public static Parcelable testParcelable(@NonNull Parcelable object) {
|
||||
Parcel parcel = ParcelMocker.obtain(object);
|
||||
object.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
try {
|
||||
Field field = object.getClass().getDeclaredField("CREATOR");
|
||||
field.setAccessible(true);
|
||||
Class<?> creatorClass = field.getType();
|
||||
Object fieldValue = field.get(object);
|
||||
Method myMethod = creatorClass.getDeclaredMethod("createFromParcel", Parcel.class);
|
||||
return (Parcelable) myMethod.invoke(fieldValue, parcel);
|
||||
} catch (Exception exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testParcelableArray(@NonNull Parcelable object) {
|
||||
Parcelable[] objects = new Parcelable[] {object};
|
||||
Parcel parcel = ParcelMocker.obtain(objects);
|
||||
parcel.writeParcelableArray(objects, 0);
|
||||
parcel.setDataPosition(0);
|
||||
Parcelable[] parcelableArray = parcel.readParcelableArray(object.getClass().getClassLoader());
|
||||
assertArrayEquals("parcel should match initial object", objects, parcelableArray);
|
||||
}
|
||||
|
||||
public static void testDescribeContents(@NonNull Parcelable object, int describeContentsValue) {
|
||||
if (describeContentsValue == 0) {
|
||||
assertEquals("\nExpecting a describeContents() value of 0 for a " + object.getClass().getSimpleName()
|
||||
+ " instance." + "\nYou can provide a different value for describeContentValue through the obtain method.",
|
||||
0,
|
||||
object.describeContents());
|
||||
} else {
|
||||
assertEquals("Expecting a describeContents() value of " + describeContentsValue,
|
||||
describeContentsValue,
|
||||
object.describeContents());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ParcelMocker {
|
||||
|
||||
public static Parcel obtain(@NonNull Parcelable target) {
|
||||
Parcel parcel = new ParcelMocker(target).getMockedParcel();
|
||||
target.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
return parcel;
|
||||
}
|
||||
|
||||
public static Parcel obtain(@NonNull Parcelable[] targets) {
|
||||
if (targets.length == 0) {
|
||||
throw new IllegalArgumentException("The passed argument may not be empty");
|
||||
}
|
||||
Parcel parcel = new ParcelMocker(targets[0]).getMockedParcel();
|
||||
parcel.writeParcelableArray(targets, 0);
|
||||
parcel.setDataPosition(0);
|
||||
return parcel;
|
||||
}
|
||||
|
||||
private List<Object> objects;
|
||||
private Object object;
|
||||
private Parcel mockedParcel;
|
||||
private int position;
|
||||
|
||||
private ParcelMocker(Object o) {
|
||||
this.object = o;
|
||||
mockedParcel = mock(Parcel.class);
|
||||
objects = new ArrayList<>();
|
||||
setupMock();
|
||||
}
|
||||
|
||||
private Parcel getMockedParcel() {
|
||||
return mockedParcel;
|
||||
}
|
||||
|
||||
private void setupMock() {
|
||||
setupWrites();
|
||||
setupReads();
|
||||
setupOthers();
|
||||
}
|
||||
|
||||
private void setupWrites() {
|
||||
Answer<Void> writeValueAnswer = new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object parameter = invocation.getArguments()[0];
|
||||
objects.add(parameter);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Answer<Void> writeArrayAnswer = new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] parameters = (Object[]) invocation.getArguments()[0];
|
||||
objects.add(parameters.length);
|
||||
for (Object o : parameters) {
|
||||
objects.add(o);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Answer<Void> writeIntArrayAnswer = new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
int[] parameters = (int[]) invocation.getArguments()[0];
|
||||
if (parameters != null) {
|
||||
objects.add(parameters.length);
|
||||
for (Object o : parameters) {
|
||||
objects.add(o);
|
||||
}
|
||||
} else {
|
||||
objects.add(-1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeByte(anyByte());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeLong(anyLong());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeString(anyString());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeInt(anyInt());
|
||||
doAnswer(writeIntArrayAnswer).when(mockedParcel).writeIntArray(any(int[].class));
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeDouble(anyDouble());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeFloat(anyFloat());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeParcelable(any(Parcelable.class), eq(0));
|
||||
doAnswer(writeArrayAnswer).when(mockedParcel).writeParcelableArray(any(Parcelable[].class), eq(0));
|
||||
}
|
||||
|
||||
private void setupReads() {
|
||||
when(mockedParcel.readInt()).then(new Answer<Integer>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Integer) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readByte()).thenAnswer(new Answer<Byte>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Byte answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Byte) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readLong()).thenAnswer(new Answer<Long>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Long answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Long) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readString()).thenAnswer(new Answer<String>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (String) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readDouble()).thenAnswer(new Answer<Double>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Double answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Double) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readFloat()).thenAnswer(new Answer<Float>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Float answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Float) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readParcelable(Parcelable.class.getClassLoader())).thenAnswer(new Answer<Parcelable>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Parcelable answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Parcelable) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readParcelableArray(Parcelable.class.getClassLoader())).thenAnswer(new Answer<Object[]>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Object[] answer(InvocationOnMock invocation) throws Throwable {
|
||||
int size = (Integer) objects.get(position++);
|
||||
Field field = object.getClass().getDeclaredField("CREATOR");
|
||||
field.setAccessible(true);
|
||||
Class<?> creatorClass = field.getType();
|
||||
Object fieldValue = field.get(object);
|
||||
Method myMethod = creatorClass.getDeclaredMethod("newArray", int.class);
|
||||
Object[] array = (Object[]) myMethod.invoke(fieldValue, size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = objects.get(position++);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
});
|
||||
when(mockedParcel.createIntArray()).then(new Answer<int[]>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public int[] answer(InvocationOnMock invocation) throws Throwable {
|
||||
int size = (Integer) objects.get(position++);
|
||||
if (size == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int[] array = new int[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = (Integer) objects.get(position++);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupOthers() {
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Void answer(@NonNull InvocationOnMock invocation) throws Throwable {
|
||||
position = ((Integer) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockedParcel).setDataPosition(anyInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user