summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java91
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java45
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java210
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/camera/CameraPositionTest.java85
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/constants/StyleVersionTest.java20
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java37
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java25
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java80
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/StyleInitializerTest.java75
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java138
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java79
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/utils/MockParcel.java299
17 files changed, 1099 insertions, 152 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java
new file mode 100644
index 0000000000..76658c242f
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java
@@ -0,0 +1,91 @@
+package com.mapbox.mapboxsdk.annotations;
+
+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;
+ 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);
+ }
+
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java
index cc38ca40b8..a55672e86b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java
@@ -1,17 +1,17 @@
package com.mapbox.mapboxsdk.annotations;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
+import android.os.Parcelable;
-import com.mapbox.mapboxsdk.annotations.Marker;
-import com.mapbox.mapboxsdk.annotations.MarkerOptions;
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 {
@@ -70,8 +70,8 @@ public class MarkerTest {
@Test
public void testHashCode() {
- Marker marker = new MarkerOptions().position(new LatLng(10, 12)).getMarker();
- assertEquals("hash code should match", marker.hashCode(), -1946419200);
+ Marker marker = new MarkerOptions().getMarker();
+ assertEquals("hash code should match", marker.hashCode(), 0);
}
@Test
@@ -88,6 +88,35 @@ public class MarkerTest {
}
@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();
@@ -116,4 +145,10 @@ public class MarkerTest {
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);
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java
new file mode 100644
index 0000000000..ed8e4ff323
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java
@@ -0,0 +1,210 @@
+package com.mapbox.mapboxsdk.annotations;
+
+import android.graphics.Bitmap;
+import android.os.Parcelable;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.testapp.R;
+import com.mapbox.mapboxsdk.utils.MockParcel;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class MarkerViewTest {
+
+ @Test
+ public void testSanity() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions();
+ assertNotNull("markerOptions should not be null", markerOptions);
+ }
+
+ @Test
+ public void testMarker() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions();
+ assertNotNull("marker should not be null", markerOptions.getMarker());
+ }
+
+ @Test
+ public void testPosition() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng(10, 12));
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals(marker.getPosition(), new LatLng(10, 12));
+ assertEquals(markerOptions.getPosition(), new LatLng(10, 12));
+ }
+
+ @Test
+ public void testSnippet() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().snippet("Mapbox");
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals(marker.getSnippet(), "Mapbox");
+ }
+
+ @Test
+ public void testTitle() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().title("Mapbox");
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals(marker.getTitle(), "Mapbox");
+ assertEquals(markerOptions.getTitle(), "Mapbox");
+ }
+
+ @Test
+ public void testIcon() {
+ Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
+ Icon icon = IconFactory.recreate("test", bitmap);
+ MarkerViewOptions markerOptions = new MarkerViewOptions().icon(icon);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("Icon should match", icon, marker.getIcon());
+ assertEquals("Icon should match", icon, markerOptions.getIcon());
+ }
+
+ @Test
+ public void testFlat() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().flat(true);
+ MarkerView marker = markerOptions.getMarker();
+ assertTrue("flat should be true", marker.isFlat());
+ }
+
+ @Test
+ public void testFlatDefault() {
+ assertFalse("default value of flat should be false", new MarkerViewOptions().getMarker().isFlat());
+ }
+
+ @Test
+ public void testAnchor() {
+ float anchorU = 1;
+ float anchorV = 1;
+ MarkerViewOptions markerOptions = new MarkerViewOptions().anchor(anchorU, anchorV);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("anchorU should match ", anchorU, marker.getAnchorU(), 0);
+ assertEquals("anchorU should match ", anchorV, marker.getAnchorV(), 0);
+ }
+
+ @Test
+ public void testAnchorDefault() {
+ MarkerView marker = new MarkerViewOptions().getMarker();
+ assertEquals("anchorU should match ", 0.5, marker.getAnchorU(), 0);
+ assertEquals("anchorU should match ", 1, marker.getAnchorV(), 0);
+ }
+
+ @Test
+ public void testInfoWindowAnchor() {
+ float anchorU = 1;
+ float anchorV = 1;
+ MarkerViewOptions markerOptions = new MarkerViewOptions().infoWindowAnchor(anchorU, anchorV);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("anchorU should match ", 1, marker.getInfoWindowAnchorU(), 0);
+ assertEquals("anchorU should match ", 1, marker.getInfoWindowAnchorV(), 0);
+ }
+
+ @Test
+ public void testInfoWindowAnchorDefault() {
+ MarkerView marker = new MarkerViewOptions().getMarker();
+ assertEquals("anchorU should match ", 0.5, marker.getInfoWindowAnchorU(), 0);
+ assertEquals("anchorU should match ", 0, marker.getInfoWindowAnchorV(), 0);
+ }
+
+ @Test
+ public void testSelectAnimRes() {
+ int animatorRes = R.animator.rotate_360;
+ MarkerViewOptions markerOptions = new MarkerViewOptions().selectAnimatorResource(animatorRes);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("select animator resource should match ", animatorRes, marker.getSelectAnimRes(), 0);
+ }
+
+ @Test
+ public void testDeselectAnimRes() {
+ int animatorRes = R.animator.rotate_360;
+ MarkerViewOptions markerOptions = new MarkerViewOptions().deselectAnimatorResource(animatorRes);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("deselect animator resource should match ", animatorRes, marker.getDeselectAnimRes(), 0);
+ }
+
+ @Test
+ public void testRotation() {
+ int rotation = 90;
+ MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(rotation);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("rotation should match ", rotation, marker.getRotation(), 0);
+ }
+
+ @Test
+ public void testVisible() {
+ boolean visible = false;
+ MarkerViewOptions markerOptions = new MarkerViewOptions().visible(visible);
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("visible should match ", visible, marker.isVisible());
+ }
+
+ @Test
+ public void testVisibleDefault() {
+ assertTrue(new MarkerViewOptions().getMarker().isVisible());
+ }
+
+ @Test
+ public void testBuilder() {
+ MarkerView marker = new MarkerViewOptions().title("title").snippet("snippet").position(new LatLng(10, 12)).getMarker();
+ assertEquals(marker.getSnippet(), "snippet");
+
+ assertEquals(marker.getPosition(), new LatLng(10, 12));
+ }
+
+ @Test
+ public void testHashCode() {
+ MarkerView marker = new MarkerViewOptions().getMarker();
+ assertEquals("hash code should match", marker.hashCode(), 0);
+ }
+
+ @Test
+ public void testHashCodeBuilder() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng(10, 12));
+ assertEquals("hash code should match", markerOptions.hashCode(), 0);
+ }
+
+ @Test
+ public void testEquals() {
+ MarkerView markerOne = new MarkerViewOptions().position(new LatLng(0, 0)).getMarker();
+ MarkerView markerTwo = new MarkerViewOptions().position(new LatLng(0, 0)).getMarker();
+ assertEquals(markerOne, markerTwo);
+ }
+
+ @Test
+ public void testEqualsItself() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng(0, 0));
+ MarkerView marker = markerOptions.getMarker();
+ assertEquals("MarkerView should match", marker, marker);
+ assertEquals("MarkerViewOptions should match", markerOptions, markerOptions);
+ }
+
+ @Test
+ public void testNotEquals() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng(0, 0));
+ MarkerView marker = markerOptions.getMarker();
+ assertNotEquals("MarkerViewOptions should match", markerOptions, new Object());
+ assertNotEquals("MarkerView should match", marker, new Object());
+ }
+
+ @Test
+ public void testEqualityBuilder() {
+ MarkerViewOptions markerOne = new MarkerViewOptions().position(new LatLng(0, 0));
+ MarkerViewOptions markerTwo = new MarkerViewOptions().position(new LatLng(0, 0));
+ assertEquals(markerOne, markerTwo);
+ }
+
+ @Test
+ public void testToString() {
+ MarkerView marker = new MarkerViewOptions().position(new LatLng(0, 0)).getMarker();
+ assertEquals(marker.toString(), "MarkerView [position[" + "LatLng [latitude=0.0, longitude=0.0, altitude=0.0]" + "]]");
+ }
+
+ @Test
+ public void testParcelable() {
+ MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).title("t").snippet("s");
+ Parcelable parcelable = MockParcel.obtain(markerOptions);
+ assertEquals("Parcel should match original object", parcelable, markerOptions);
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/camera/CameraPositionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/camera/CameraPositionTest.java
index 222007df79..a8cca4c3c8 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/camera/CameraPositionTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/camera/CameraPositionTest.java
@@ -1,17 +1,28 @@
package com.mapbox.mapboxsdk.camera;
+import android.content.res.TypedArray;
+import android.os.Parcelable;
+
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MathConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.utils.MathUtils;
+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.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class CameraPositionTest {
+ private static final double DELTA = 1e-15;
+
@Test
public void testSanity() {
LatLng latLng = new LatLng(1, 2);
@@ -20,6 +31,55 @@ public class CameraPositionTest {
}
@Test
+ public void testDefaultTypedArrayBuilder() {
+ TypedArray typedArray = null;
+ CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
+ assertEquals("bearing should match", -1, cameraPosition.bearing, DELTA);
+ assertEquals("latlng should match", null, cameraPosition.target);
+ assertEquals("tilt should match", -1, cameraPosition.tilt, DELTA);
+ assertEquals("zoom should match", -1, cameraPosition.zoom, DELTA);
+ }
+
+ @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.MapView_direction, 0.0f)).thenReturn(bearing);
+ when(typedArray.getFloat(R.styleable.MapView_center_latitude, 0.0f)).thenReturn(latitude);
+ when(typedArray.getFloat(R.styleable.MapView_center_longitude, 0.0f)).thenReturn(longitude);
+ when(typedArray.getFloat(R.styleable.MapView_zoom, 0.0f)).thenReturn(zoom);
+ when(typedArray.getFloat(R.styleable.MapView_tilt, 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 testJniBuilder() {
+ double bearing = 180;
+ double zoom = 12;
+ double latitude = 10;
+ double longitude = 11;
+ double tilt = 44;
+
+ double[] cameraVars = new double[]{latitude, longitude, bearing, tilt, zoom};
+ CameraPosition cameraPosition = new CameraPosition.Builder(cameraVars).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);
@@ -74,4 +134,29 @@ public class CameraPositionTest {
(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);
+ CameraPosition cameraPositionBearing = new CameraPosition(latLng, 3, 4, 9);
+ CameraPosition cameraPositionTilt = new CameraPosition(latLng, 3, 9, 5);
+ CameraPosition cameraPositionZoom = new CameraPosition(latLng, 9, 4, 5);
+ CameraPosition cameraPositionTarget = new CameraPosition(new LatLng(), 3, 4, 5);
+
+ 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);
+ }
+
+ @Test
+ public void testParcelable() {
+ CameraPosition object = new CameraPosition(new LatLng(1, 2), 3, 4, 5);
+ Parcelable parcelable = MockParcel.obtain(object);
+ assertEquals("Parcel should match original object", parcelable, object);
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/constants/StyleVersionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/constants/StyleVersionTest.java
new file mode 100644
index 0000000000..078b4184ca
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/constants/StyleVersionTest.java
@@ -0,0 +1,20 @@
+package com.mapbox.mapboxsdk.constants;
+
+import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class StyleVersionTest {
+
+ private static final double DELTA = 1e-15;
+
+ @Test
+ public void testSanity() {
+ assertEquals("Style version should match, when upgrading, verify that integers.xml is updated",
+ AppConstant.STYLE_VERSION,
+ 9,
+ DELTA);
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
index f9cdf29b81..b667940a6f 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
@@ -1,6 +1,9 @@
package com.mapbox.mapboxsdk.geometry;
+import android.os.Parcelable;
+
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
+import com.mapbox.mapboxsdk.utils.MockParcel;
import org.junit.Before;
import org.junit.Test;
@@ -168,5 +171,13 @@ public class LatLngBoundsTest {
.build());
}
-
-}
+ @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);
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java
index 7bf164166c..e184097a43 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java
@@ -1,6 +1,8 @@
package com.mapbox.mapboxsdk.geometry;
-import com.mapbox.mapboxsdk.geometry.LatLngSpan;
+import android.os.Parcelable;
+
+import com.mapbox.mapboxsdk.utils.MockParcel;
import org.junit.Test;
@@ -54,4 +56,10 @@ public class LatLngSpanTest {
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);
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java
index e13efb9708..de5dbc5e09 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java
@@ -1,18 +1,16 @@
package com.mapbox.mapboxsdk.geometry;
import android.location.Location;
-import android.os.Parcel;
-import com.mapbox.mapboxsdk.geometry.LatLng;
+import android.os.Parcelable;
+
import com.mapbox.mapboxsdk.utils.MockParcel;
+
import org.junit.Test;
-import java.util.Objects;
-import static org.junit.Assert.assertArrayEquals;
+
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.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -164,7 +162,7 @@ public class LatLngTest {
@Test
public void testEqualsItself() {
- LatLng latLng = new LatLng(1,2,3);
+ LatLng latLng = new LatLng(1, 2, 3);
assertEquals("LatLng should match", latLng, latLng);
}
@@ -176,28 +174,9 @@ public class LatLngTest {
@Test
public void testParcelable() {
- LatLng latLng = new LatLng(1, 2, 3);
- Parcel parcel = MockParcel.obtain();
- latLng.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- LatLng parceledLatLng = LatLng.CREATOR.createFromParcel(parcel);
- assertEquals("parcel should match initial object", latLng, parceledLatLng);
- }
-
- @Test
- public void testParcelableArray() {
- LatLng[] latLngs = new LatLng[]{new LatLng(1, 2, 3), new LatLng(1, 2)};
- Parcel parcel = MockParcel.obtain();
- parcel.writeParcelableArray(latLngs, 0);
- parcel.setDataPosition(0);
- LatLng[] parceledLatLngs = (LatLng[]) parcel.readParcelableArray(LatLng.class.getClassLoader());
- assertArrayEquals("parcel should match initial object", latLngs, parceledLatLngs);
- }
-
- @Test
- public void testDescribeContents() {
- LatLng latLng = new LatLng(1.2, 3.4);
- assertEquals("contents should be 0", 0, latLng.describeContents(), DELTA);
+ LatLng latLng = new LatLng(45.0, -185.0);
+ Parcelable parcel = MockParcel.obtain(latLng);
+ assertEquals("parcel should match initial object", latLng, parcel);
}
@Test
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java
index bd40221706..5525684601 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java
@@ -1,5 +1,9 @@
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;
@@ -48,8 +52,15 @@ public class ProjectedMetersTest {
}
@Test
- public void testToString(){
+ 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);
- assertEquals("toString should match","ProjectedMeters [northing=1.0, easting=1.0]",meters.toString());
+ Parcelable parcel = MockParcel.obtain(meters);
+ assertEquals("parcel should match initial object", meters, parcel);
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java
index 0682d0878e..cad268c2ba 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java
@@ -1,5 +1,9 @@
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;
@@ -81,4 +85,10 @@ public class VisibleRegionTest {
, 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);
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
index 589084d17c..dbde9a4420 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
@@ -1,11 +1,13 @@
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.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.utils.MockParcel;
import org.junit.Test;
@@ -71,6 +73,12 @@ public class MapboxMapOptionsTest {
}
@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());
@@ -161,6 +169,23 @@ public class MapboxMapOptionsTest {
}
@Test
+ public void testMyLocationForegroundTint() {
+ assertEquals(Color.BLUE, new MapboxMapOptions().myLocationForegroundTintColor(Color.BLUE).getMyLocationForegroundTintColor());
+ }
+
+ @Test
+ public void testMyLocationBackgroundTint() {
+ assertEquals(Color.BLUE, new MapboxMapOptions().myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor());
+ }
+
+ @Test
+ public void testParceable() {
+ MapboxMapOptions options = new MapboxMapOptions().camera(new CameraPosition.Builder().build()).styleUrl("s").accessToken("a").debugActive(true).compassMargins(new int[]{0, 1, 2, 3});
+ MapboxMapOptions parceled = (MapboxMapOptions) MockParcel.obtain(options);
+ assertEquals(options, parceled);
+ }
+
+ @Test
public void testAccessToken() {
assertNull(new MapboxMapOptions().getAccessToken());
assertEquals("test", new MapboxMapOptions().accessToken("test").getAccessToken());
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
index 1705f44fa4..b69ba4e3f8 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -2,7 +2,9 @@ package com.mapbox.mapboxsdk.maps;
import android.graphics.Color;
import android.graphics.Point;
+import android.graphics.PointF;
+import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.Polygon;
@@ -12,6 +14,7 @@ import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import org.junit.Before;
import org.junit.Test;
@@ -26,6 +29,7 @@ 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.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -197,7 +201,7 @@ public class MapboxMapTest {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
mMapboxMap.setPadding(0, 0, 0, 0);
- verify(mOnCameraChangeListener, times(2)).onCameraChange(position);
+ verify(mOnCameraChangeListener, times(1)).onCameraChange(position);
}
//
@@ -372,6 +376,58 @@ public class MapboxMapTest {
}
//
+ // Camera - LatLngBounds
+ //
+ @Test
+ public void testLatLngBounds() {
+ LatLng la = new LatLng(34.053940, -118.242622);
+ LatLng ny = new LatLng(40.712730, -74.005953);
+ LatLng centroid = new LatLng(
+ (la.getLatitude() + ny.getLatitude()) / 2,
+ (la.getLongitude() + ny.getLongitude()) / 2);
+
+ Projection projection = mock(Projection.class);
+ when(projection.toScreenLocation(la)).thenReturn(new PointF(20, 20));
+ when(projection.toScreenLocation(ny)).thenReturn(new PointF(100, 100));
+ when(projection.fromScreenLocation(any(PointF.class))).thenReturn(centroid);
+
+ UiSettings uiSettings = mock(UiSettings.class);
+ when(uiSettings.getHeight()).thenReturn(1000f);
+
+ mMapboxMap.setProjection(projection);
+ mMapboxMap.setUiSettings(uiSettings);
+
+ LatLngBounds bounds = new LatLngBounds.Builder().include(la).include(ny).build();
+ mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 1));
+
+ assertEquals("LatLng should be same", centroid, mMapboxMap.getCameraPosition().target);
+ }
+
+
+ //
+ // CameraPositionUpdate - NPX target
+ //
+ @Test
+ public void testCamerePositionUpdateNullTarget() {
+ LatLng latLng = new LatLng(1, 1);
+ mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
+ mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(null));
+ assertEquals("LatLng should be same", latLng, mMapboxMap.getCameraPosition().target);
+ }
+
+ //
+ // Camera - ScrollBy
+ //
+ @Test
+ public void testScrollBy() {
+ LatLng latLng = new LatLng(1, 1);
+ mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
+ mMapboxMap.moveCamera(CameraUpdateFactory.scrollBy(0, 0));
+ assertEquals("LatLng should be same", latLng, mMapboxMap.getCameraPosition().target);
+ mMapboxMap.moveCamera(CameraUpdateFactory.scrollBy(12, 12));
+ }
+
+ //
// Camera - Zoom
//
@@ -523,7 +579,7 @@ public class MapboxMapTest {
@Test
public void testAddMarkers() {
- List<MarkerOptions> markerList = new ArrayList<>();
+ List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
markerList.add(markerOptions1);
@@ -536,14 +592,14 @@ public class MapboxMapTest {
@Test
public void testAddMarkersEmpty() {
- List<MarkerOptions> markerList = new ArrayList<>();
+ List<BaseMarkerOptions> markerList = new ArrayList<>();
mMapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 0", 0, mMapboxMap.getMarkers().size());
}
@Test
public void testAddMarkersSingleMarker() {
- List<MarkerOptions> markerList = new ArrayList<>();
+ List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions = new MarkerOptions().title("a");
markerList.add(markerOptions);
mMapboxMap.addMarkers(markerList);
@@ -686,7 +742,7 @@ public class MapboxMapTest {
@Test
public void testRemoveAnnotations() {
- List<MarkerOptions> markerList = new ArrayList<>();
+ List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
markerList.add(markerOptions1);
@@ -697,8 +753,20 @@ public class MapboxMapTest {
}
@Test
+ public void testClear() {
+ List<BaseMarkerOptions> markerList = new ArrayList<>();
+ MarkerOptions markerOptions1 = new MarkerOptions().title("a");
+ MarkerOptions markerOptions2 = new MarkerOptions().title("b");
+ markerList.add(markerOptions1);
+ markerList.add(markerOptions2);
+ mMapboxMap.addMarkers(markerList);
+ mMapboxMap.clear();
+ assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty());
+ }
+
+ @Test
public void testRemoveAnnotationsByList() {
- List<MarkerOptions> markerList = new ArrayList<>();
+ List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
markerList.add(markerOptions1);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/StyleInitializerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/StyleInitializerTest.java
new file mode 100644
index 0000000000..71d61a3d4b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/StyleInitializerTest.java
@@ -0,0 +1,75 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.content.Context;
+import android.content.res.Resources;
+
+import com.mapbox.mapboxsdk.testapp.R;
+import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+
+import java.util.Locale;
+
+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 StyleInitializerTest {
+
+ @InjectMocks
+ Context context = mock(Context.class);
+
+ @InjectMocks
+ Resources resources = mock(Resources.class);
+
+ MapView.StyleInitializer initializer;
+
+ @Before
+ public void beforeTest() {
+ MockitoAnnotations.initMocks(this);
+ when(context.getResources()).thenReturn(resources);
+ when(resources.getInteger(R.integer.style_version)).thenReturn(AppConstant.STYLE_VERSION);
+ initializer = new MapView.StyleInitializer(context);
+ }
+
+ @Test
+ public void testSanity() {
+ assertNotNull("initializer should not be null", initializer);
+ }
+
+ @Test
+ public void testDefaultStyle() {
+ assertTrue(initializer.isDefaultStyle());
+ assertEquals(String.format(Locale.US, "mapbox://styles/mapbox/streets-v%d", AppConstant.STYLE_VERSION), "mapbox://styles/mapbox/streets-v9");
+ }
+
+ @Test
+ public void testUpdateStyle() {
+ String customStyle = "test";
+ initializer.setStyle(customStyle);
+ assertFalse(initializer.isDefaultStyle());
+ assertEquals(customStyle, initializer.getStyle());
+ }
+
+ @Test
+ public void testUpdateStyleNull() {
+ String customStyle = null;
+ initializer.setStyle(customStyle);
+ assertTrue(initializer.isDefaultStyle());
+ assertEquals(String.format(Locale.US, "mapbox://styles/mapbox/streets-v%d", AppConstant.STYLE_VERSION), "mapbox://styles/mapbox/streets-v9");
+ }
+
+ @Test
+ public void testOverrideDefaultStyle() {
+ String customStyle = "test";
+ initializer.setStyle(customStyle, true);
+ assertTrue(initializer.isDefaultStyle());
+ assertEquals(customStyle, initializer.getStyle());
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java
index 4af44a3f49..300ed1d73a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.maps;
import android.view.Gravity;
+import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -9,42 +10,45 @@ import static org.junit.Assert.assertEquals;
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
MapView mMapView = mock(MapView.class);
+ UiSettings uiSettings;
+
+ @Before
+ public void beforeTest() {
+ uiSettings = new UiSettings(mMapView);
+ }
+
@Test
public void testSanity() {
- UiSettings uiSettings = new UiSettings(mMapView);
assertNotNull("uiSettings should not be null", uiSettings);
}
@Test
public void testCompassEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setCompassEnabled(true);
assertEquals("Compass should be enabled", true, uiSettings.isCompassEnabled());
}
@Test
public void testCompassDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setCompassEnabled(false);
assertEquals("Compass should be disabled", false, uiSettings.isCompassEnabled());
}
@Test
public void testCompassGravity() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setCompassGravity(Gravity.LEFT);
assertEquals("Compass gravity should be same", Gravity.LEFT, uiSettings.getCompassGravity());
}
@Test
public void testCompassMargins() {
- UiSettings uiSettings = new UiSettings(mMapView);
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);
@@ -54,28 +58,24 @@ public class UiSettingsTest {
@Test
public void testLogoEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setLogoEnabled(true);
assertEquals("Logo should be enabled", true, uiSettings.isLogoEnabled());
}
@Test
public void testLogoDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setLogoEnabled(false);
assertEquals("Logo should be disabled", false, uiSettings.isLogoEnabled());
}
@Test
public void testLogoGravity() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setLogoGravity(Gravity.RIGHT);
assertEquals("Logo gravity should be same", Gravity.RIGHT, uiSettings.getLogoGravity());
}
@Test
public void testLogoMargins() {
- UiSettings uiSettings = new UiSettings(mMapView);
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);
@@ -85,28 +85,24 @@ public class UiSettingsTest {
@Test
public void testAttributionEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setAttributionEnabled(true);
assertEquals("Attribution should be enabled", true, uiSettings.isAttributionEnabled());
}
@Test
public void testAttributionDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setAttributionEnabled(false);
assertEquals("Attribution should be disabled", false, uiSettings.isLogoEnabled());
}
@Test
public void testAttributionGravity() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setAttributionGravity(Gravity.RIGHT);
assertEquals("Attribution gravity should be same", Gravity.RIGHT, uiSettings.getAttributionGravity());
}
@Test
public void testAttributionMargins() {
- UiSettings uiSettings = new UiSettings(mMapView);
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);
@@ -116,77 +112,158 @@ public class UiSettingsTest {
@Test
public void testRotateGesturesEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setRotateGesturesEnabled(true);
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());
}
@Test
public void testRotateGesturesDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setRotateGesturesEnabled(false);
assertEquals("Rotate gesture should be disabled", false, uiSettings.isRotateGesturesEnabled());
}
@Test
+ public void testRotateGestureChange() {
+ assertEquals("Default state should be true", true, uiSettings.isRotateGestureChangeAllowed());
+ uiSettings.setRotateGestureChangeAllowed(false);
+ assertEquals("State should have been changed", false, uiSettings.isRotateGestureChangeAllowed());
+ }
+
+ @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 testRotateGestureChangeDisallowed() {
+ assertEquals("Rotate gesture should be true", true, uiSettings.isRotateGesturesEnabled());
+ uiSettings.setRotateGestureChangeAllowed(false);
+ uiSettings.setRotateGesturesEnabled(false);
+ assertEquals("Rotate gesture change should be ignored", true, uiSettings.isRotateGesturesEnabled());
+ }
+
+ @Test
public void testTiltGesturesEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setTiltGesturesEnabled(true);
assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled());
}
@Test
public void testTiltGesturesDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setTiltGesturesEnabled(false);
assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled());
}
@Test
+ public void testTiltGestureChange() {
+ assertEquals("Default state should be true", true, uiSettings.isTiltGestureChangeAllowed());
+ uiSettings.setTiltGestureChangeAllowed(false);
+ assertEquals("State should have been changed", false, uiSettings.isTiltGestureChangeAllowed());
+ }
+
+ @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 testTiltGestureChangeDisallowed() {
+ assertEquals("Tilt gesture should be true", true, uiSettings.isTiltGesturesEnabled());
+ uiSettings.setTiltGestureChangeAllowed(false);
+ uiSettings.setTiltGesturesEnabled(false);
+ assertEquals("Tilt gesture change should be ignored", true, uiSettings.isTiltGesturesEnabled());
+ }
+
+ @Test
public void testZoomGesturesEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setZoomGesturesEnabled(true);
assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled());
}
@Test
public void testZoomGesturesDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setZoomGesturesEnabled(false);
assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled());
}
@Test
+ public void testZoomGestureChange() {
+ assertEquals("Default state should be true", true, uiSettings.isZoomGestureChangeAllowed());
+ uiSettings.setZoomGestureChangeAllowed(false);
+ assertEquals("State should have been changed", false, uiSettings.isZoomGestureChangeAllowed());
+ }
+
+ @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 testZoomGestureChangeDisallowed() {
+ assertEquals("Zoom gesture should be true", true, uiSettings.isZoomGesturesEnabled());
+ uiSettings.setZoomGestureChangeAllowed(false);
+ uiSettings.setZoomGesturesEnabled(false);
+ assertEquals("Zooom gesture change should be ignored", true, uiSettings.isZoomGesturesEnabled());
+ }
+
+ @Test
public void testZoomControlsEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setZoomControlsEnabled(true);
assertEquals("Zoom controls should be enabled", true, uiSettings.isZoomControlsEnabled());
}
@Test
public void testZoomControlsDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setZoomControlsEnabled(false);
assertEquals("Zoom controls should be disabled", false, uiSettings.isZoomControlsEnabled());
}
@Test
public void testScrollGesturesEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setScrollGesturesEnabled(true);
assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled());
}
@Test
public void testScrollGesturesDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setScrollGesturesEnabled(false);
assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled());
}
@Test
+ public void testScrollGestureChange() {
+ assertEquals("Default state should be true", true, uiSettings.isScrollGestureChangeAllowed());
+ uiSettings.setScrollGestureChangeAllowed(false);
+ assertEquals("State should have been changed", false, uiSettings.isScrollGestureChangeAllowed());
+ }
+
+ @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 testScrollGestureChangeDisallowed() {
+ assertEquals("Scroll gesture should be true", true, uiSettings.isScrollGesturesEnabled());
+ uiSettings.setScrollGestureChangeAllowed(false);
+ uiSettings.setScrollGesturesEnabled(false);
+ assertEquals("Scroll gesture change should be ignored", true, uiSettings.isScrollGesturesEnabled());
+ }
+
+ @Test
public void testAllGesturesEnabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setAllGesturesEnabled(true);
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());
assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled());
@@ -196,7 +273,6 @@ public class UiSettingsTest {
@Test
public void testAllGesturesDisabled() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setAllGesturesEnabled(false);
assertEquals("Rotate gesture should be enabled", false, uiSettings.isRotateGesturesEnabled());
assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled());
@@ -206,8 +282,18 @@ public class UiSettingsTest {
@Test
public void testInvalidate() {
- UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.invalidate();
}
+ @Test
+ public void testHeight() {
+ when(mMapView.getMeasuredHeight()).thenReturn(1);
+ assertEquals("height should be same as mocked instance", 1, uiSettings.getHeight(), 0);
+ }
+
+ @Test
+ public void testWidth() {
+ when(mMapView.getMeasuredWidth()).thenReturn(1);
+ assertEquals("width should be same as mocked instance", 1, uiSettings.getWidth(), 0);
+ }
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java
new file mode 100644
index 0000000000..a03eb6acae
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java
@@ -0,0 +1,79 @@
+package com.mapbox.mapboxsdk.maps.widgets;
+
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+
+import com.mapbox.mapboxsdk.maps.MapView;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+
+import java.util.Arrays;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+public class MyLocationViewSettingsTest {
+
+ @InjectMocks
+ MapView mMapView = mock(MapView.class);
+
+ @InjectMocks
+ MyLocationView myLocationView = mock(MyLocationView.class);
+
+ MyLocationViewSettings locationViewSettings;
+
+ @Before
+ public void beforeTest() {
+ locationViewSettings = new MyLocationViewSettings(mMapView, myLocationView);
+ }
+
+ @Test
+ public void testSanity() {
+ assertNotNull("should not be null", locationViewSettings);
+ }
+
+ @Test
+ public void testForegroundDrawables() {
+ Drawable foregroundDrawable = mock(Drawable.class);
+ Drawable foregroundBearingDrawable = mock(Drawable.class);
+ locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable);
+ assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable());
+ assertEquals("foreground bearing should match", foregroundBearingDrawable, locationViewSettings.getForegroundBearingDrawable());
+ }
+
+ @Test
+ public void testBackgroundDrawable() {
+ Drawable backgroundDrawable = mock(Drawable.class);
+ int[] offset = new int[]{1, 2, 3, 4};
+ locationViewSettings.setBackgroundDrawable(backgroundDrawable, offset);
+ assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable());
+ assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset()));
+ }
+
+ @Test
+ public void testForegroundTint() {
+ int color = Color.RED;
+ locationViewSettings.setForegroundTintColor(Color.RED);
+ assertEquals("color should match", color, locationViewSettings.getForegroundTintColor());
+ }
+
+ @Test
+ public void testBackgroundTint() {
+ int color = Color.RED;
+ locationViewSettings.setBackgroundTintColor(Color.RED);
+ assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor());
+ }
+
+ @Test
+ public void testEnabled() {
+ assertFalse("initial state should be false", locationViewSettings.isEnabled());
+ locationViewSettings.setEnabled(true);
+ assertTrue("state should be true", locationViewSettings.isEnabled());
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java
new file mode 100644
index 0000000000..8be0d2c663
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java
@@ -0,0 +1,17 @@
+package com.mapbox.mapboxsdk.telemetry;
+
+import org.junit.Test;
+import okhttp3.internal.Util;
+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, Util.toHumanReadableAscii(swedishUserAgent));
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/utils/MockParcel.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/utils/MockParcel.java
index 9badde848e..aa0a4edd13 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/utils/MockParcel.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/utils/MockParcel.java
@@ -1,17 +1,24 @@
package com.mapbox.mapboxsdk.utils;
import android.os.Parcel;
-
-import com.mapbox.mapboxsdk.geometry.LatLng;
+import android.os.Parcelable;
+import android.support.annotation.NonNull;
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 junit.framework.Assert.assertNotNull;
+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;
@@ -22,97 +29,227 @@ import static org.mockito.Mockito.when;
public class MockParcel {
- public static Parcel obtain() {
- return new MockParcel().getMockedParcel();
+ public static Parcelable obtain(@NonNull Parcelable object) {
+ return obtain(object, 0);
}
- Parcel mockedParcel;
- int position;
- List<Object> objects;
+ public static Parcelable obtain(@NonNull Parcelable object, int describeContentsValue) {
+ testDescribeContents(object, describeContentsValue);
+ testParcelableArray(object);
+ return testParcelable(object);
+ }
- public Parcel getMockedParcel() {
- return mockedParcel;
+ 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 e) {
+ return null;
+ }
}
- public MockParcel() {
- mockedParcel = mock(Parcel.class);
- objects = new ArrayList<>();
- setupMock();
+ 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);
}
- private void setupMock() {
- setupWrites();
- setupReads();
- setupOthers();
+ 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 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;
- }
- };
+ private static class ParcelMocker {
- doAnswer(writeValueAnswer).when(mockedParcel).writeLong(anyLong());
- doAnswer(writeValueAnswer).when(mockedParcel).writeString(anyString());
- doAnswer(writeValueAnswer).when(mockedParcel).writeDouble(anyDouble());
- doAnswer(writeArrayAnswer).when(mockedParcel).writeParcelableArray(any(LatLng[].class), eq(0));
- }
+ public static Parcel obtain(@NonNull Parcelable target) {
+ Parcel parcel = new ParcelMocker(target).getMockedParcel();
+ target.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ return parcel;
+ }
- private void setupReads() {
- when(mockedParcel.readLong()).thenAnswer(new Answer<Long>() {
- @Override
- public Long answer(InvocationOnMock invocation) throws Throwable {
- return (Long) objects.get(position++);
- }
- });
- when(mockedParcel.readString()).thenAnswer(new Answer<String>() {
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
- return (String) objects.get(position++);
+ public static Parcel obtain(@NonNull Parcelable[] targets) {
+ if (targets.length == 0) {
+ throw new IllegalArgumentException("The passed argument may not be empty");
}
- });
- when(mockedParcel.readDouble()).thenAnswer(new Answer<Double>() {
- @Override
- public Double answer(InvocationOnMock invocation) throws Throwable {
- return (Double) objects.get(position++);
- }
- });
- when(mockedParcel.readParcelableArray(LatLng.class.getClassLoader())).thenAnswer(new Answer<LatLng[]>() {
- @Override
- public LatLng[] answer(InvocationOnMock invocation) throws Throwable {
- int size = (Integer) objects.get(position++);
- LatLng[] latLngs = LatLng.CREATOR.newArray(size);
- for (int i = 0; i < size; i++) {
- latLngs[i] = (LatLng) objects.get(position++);
+ 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;
}
- return latLngs;
- }
- });
- }
-
- private void setupOthers() {
- doAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- position = ((Integer) invocation.getArguments()[0]);
- return null;
- }
- }).when(mockedParcel).setDataPosition(anyInt());
+ };
+ 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>() {
+ @Override
+ public Integer answer(InvocationOnMock invocation) throws Throwable {
+ return (Integer) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readByte()).thenAnswer(new Answer<Byte>() {
+ @Override
+ public Byte answer(InvocationOnMock invocation) throws Throwable {
+ return (Byte) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readLong()).thenAnswer(new Answer<Long>() {
+ @Override
+ public Long answer(InvocationOnMock invocation) throws Throwable {
+ return (Long) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readString()).thenAnswer(new Answer<String>() {
+ @Override
+ public String answer(InvocationOnMock invocation) throws Throwable {
+ return (String) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readDouble()).thenAnswer(new Answer<Double>() {
+ @Override
+ public Double answer(InvocationOnMock invocation) throws Throwable {
+ return (Double) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readFloat()).thenAnswer(new Answer<Float>() {
+ @Override
+ public Float answer(InvocationOnMock invocation) throws Throwable {
+ return (Float) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readParcelable(Parcelable.class.getClassLoader())).thenAnswer(new Answer<Parcelable>() {
+ @Override
+ public Parcelable answer(InvocationOnMock invocation) throws Throwable {
+ return (Parcelable) objects.get(position++);
+ }
+ });
+ when(mockedParcel.readParcelableArray(Parcelable.class.getClassLoader())).thenAnswer(new Answer<Object[]>() {
+ @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[]>() {
+ @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>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ position = ((Integer) invocation.getArguments()[0]);
+ return null;
+ }
+ }).when(mockedParcel).setDataPosition(anyInt());
+ }
}
-
}