diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java')
24 files changed, 2255 insertions, 3070 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 index 76658c242f..611e4f978c 100644 --- 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 @@ -17,75 +17,75 @@ 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 - }; + @InjectMocks + private MapboxMap mapboxMap = mock(MapboxMap.class); + private Annotation annotation; + private Annotation compare = new Annotation() { + @Override + public long getId() { + return 1; } + }; - @Test - public void testSanity() { - assertNotNull("markerOptions should not be null", annotation); - } + @Before + public void beforeTest() { + annotation = new Annotation() { + // empty child + }; + } - @Test - public void testRemove() { - annotation.setId(1); - annotation.setMapboxMap(mapboxMap); - annotation.remove(); - verify(mapboxMap, times(1)).removeAnnotation(annotation); - } + @Test + public void testSanity() { + assertNotNull("markerOptions should not be null", annotation); + } - @Test - public void testRemoveUnboundMapboxMap() { - annotation.setId(1); - annotation.remove(); - verify(mapboxMap, times(0)).removeAnnotation(annotation); - } + @Test + public void testRemove() { + annotation.setId(1); + annotation.setMapboxMap(mapboxMap); + annotation.remove(); + verify(mapboxMap, times(1)).removeAnnotation(annotation); + } - @Test - public void testCompareToEqual() { - annotation.setId(1); - assertEquals("conparable equal", 0, annotation.compareTo(compare)); - } + @Test + public void testRemoveUnboundMapboxMap() { + annotation.setId(1); + annotation.remove(); + verify(mapboxMap, times(0)).removeAnnotation(annotation); + } - @Test - public void testCompareToHigher() { - annotation.setId(3); - assertEquals("conparable higher", -1, annotation.compareTo(compare)); - } + @Test + public void testCompareToEqual() { + annotation.setId(1); + assertEquals("conparable equal", 0, annotation.compareTo(compare)); + } - @Test - public void testCompareTolower() { - annotation.setId(0); - assertEquals("conparable lower", 1, annotation.compareTo(compare)); - } + @Test + public void testCompareToHigher() { + annotation.setId(3); + assertEquals("conparable higher", -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 testCompareTolower() { + annotation.setId(0); + assertEquals("conparable lower", 1, annotation.compareTo(compare)); + } - @Test - public void testHashcode() { - int id = 1; - annotation.setId(id); - assertSame("hashcode should match", annotation.hashCode(), id); - } + @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/IconTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java index 9e95451cb1..5f6f6b6c6d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java @@ -12,44 +12,44 @@ import static junit.framework.Assert.assertNotSame; public class IconTest { - @Mock - Bitmap mBitmap; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - } - - @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", mBitmap); - assertEquals("bitmap should match", mBitmap, icon.getBitmap()); - } - - @Test - public void testEquals() { - Icon icon1 = IconFactory.recreate("test", mBitmap); - Icon icon2 = IconFactory.recreate("test", mBitmap); - 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", mBitmap); - long expectedHashcode = 31 * mBitmap.hashCode() + "test".hashCode(); - assertEquals("hashcode should match", expectedHashcode, icon.hashCode()); - } + @Mock + Bitmap bitmap; + + @Before + public void beforeTest() { + MockitoAnnotations.initMocks(this); + } + + @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()); + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java index 1398f40009..94b629860e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java @@ -17,70 +17,70 @@ 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(); - } + @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(); + } } 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 c4c294fb98..fa571e06b1 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 @@ -16,145 +16,145 @@ 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); - } + @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); + } } 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 index 6cef1898bd..3c52c16422 100644 --- 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 @@ -23,265 +23,264 @@ import static org.mockito.Mockito.when; public class MarkerViewTest { - @Mock - MapboxMap mapboxMap; - - @Mock - MarkerViewManager markerViewManager; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testSanity() { - MarkerViewOptions markerOptions = new MarkerViewOptions(); - assertNotNull("markerOptions should not be null", markerOptions); - } - - @Test - public void testMarker() { - MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()); - assertNotNull("marker should not be null", markerOptions.getMarker()); - } - - @Test(expected = InvalidMarkerPositionException.class) - public void testInvalidMarker() { - new MarkerViewOptions().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").position(new LatLng()); - MarkerView marker = markerOptions.getMarker(); - assertEquals(marker.getSnippet(), "Mapbox"); - } - - @Test - public void testTitle() { - MarkerViewOptions markerOptions = new MarkerViewOptions().title("Mapbox").position(new LatLng()); - MarkerView marker = markerOptions.getMarker(); - assertEquals(marker.getTitle(), "Mapbox"); - assertEquals(markerOptions.getTitle(), "Mapbox"); - } - - @Test - public void testFlat() { - MarkerViewOptions markerOptions = new MarkerViewOptions().flat(true).position(new LatLng()); - 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().position(new LatLng()).getMarker().isFlat()); - } - - @Test - public void testAnchor() { - float anchorU = 1; - float anchorV = 1; - MarkerViewOptions markerOptions = new MarkerViewOptions().anchor(anchorU, anchorV).position(new LatLng()); - 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().position(new LatLng()).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().position(new LatLng()).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().position(new LatLng()).getMarker(); - assertEquals("anchorU should match ", 0.5, marker.getInfoWindowAnchorU(), 0); - assertEquals("anchorU should match ", 0, marker.getInfoWindowAnchorV(), 0); - } - - @Test - public void testRotation() { - int rotation = 90; - MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(rotation); - MarkerView marker = markerOptions.getMarker(); - assertEquals("rotation should match ", rotation, marker.getRotation(), 0); - } - - @Test - public void testRotationAboveMax() { - MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(390).position(new LatLng()); - MarkerView marker = markerOptions.getMarker(); - assertEquals(marker.getRotation(), 30, 0); - } - - @Test - public void testRotationBelowMin() { - MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(-10).position(new LatLng()); - MarkerView marker = markerOptions.getMarker(); - assertEquals(marker.getRotation(), 350, 0); - } - - @Test - public void testRotationUpdatePositive() { - float startRotation = 45; - float endRotation = 180; - float animationValue = 135; - - // allow calls to our mock - when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); - - MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); - MarkerView marker = markerOptions.getMarker(); - marker.setMapboxMap(mapboxMap); - - marker.setRotation(endRotation); - verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); - } - - @Test - public void testRotationUpdateNegative() { - float startRotation = 10; - float endRotation = 270; - float animationValue = -100; - - // allow calls to our mock - when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); - - MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); - MarkerView marker = markerOptions.getMarker(); - marker.setMapboxMap(mapboxMap); - - marker.setRotation(endRotation); - verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); - } - - @Test - public void testRotationUpdateMax() { - float startRotation = 359; - float endRotation = 0; - float animationValue = 1; - - // allow calls to our mock - when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); - - MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); - MarkerView marker = markerOptions.getMarker(); - marker.setMapboxMap(mapboxMap); - - marker.setRotation(endRotation); - verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); - } - - @Test - public void testRotationUpdateMin() { - float startRotation = 0; - float endRotation = 359; - float animationValue = -1; - - // allow calls to our mock - when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); - - MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); - MarkerView marker = markerOptions.getMarker(); - marker.setMapboxMap(mapboxMap); - - marker.setRotation(endRotation); - verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); - } - - @Test - public void testVisible() { - boolean visible = false; - MarkerViewOptions markerOptions = new MarkerViewOptions().visible(visible).position(new LatLng()); - MarkerView marker = markerOptions.getMarker(); - assertEquals("visible should match ", visible, marker.isVisible()); - } - - @Test - public void testVisibleDefault() { - assertTrue(new MarkerViewOptions().position(new LatLng()).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().position(new LatLng()).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); - } + @Mock + MapboxMap mapboxMap; + + @Mock + MarkerViewManager markerViewManager; + + @Before + public void beforeTest() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testSanity() { + MarkerViewOptions markerOptions = new MarkerViewOptions(); + assertNotNull("markerOptions should not be null", markerOptions); + } + + @Test + public void testMarker() { + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()); + assertNotNull("marker should not be null", markerOptions.getMarker()); + } + + @Test(expected = InvalidMarkerPositionException.class) + public void testInvalidMarker() { + new MarkerViewOptions().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").position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals(marker.getSnippet(), "Mapbox"); + } + + @Test + public void testTitle() { + MarkerViewOptions markerOptions = new MarkerViewOptions().title("Mapbox").position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals(marker.getTitle(), "Mapbox"); + assertEquals(markerOptions.getTitle(), "Mapbox"); + } + + @Test + public void testFlat() { + MarkerViewOptions markerOptions = new MarkerViewOptions().flat(true).position(new LatLng()); + 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().position( + new LatLng()).getMarker().isFlat()); + } + + @Test + public void testAnchor() { + float anchorU = 1; + float anchorV = 1; + MarkerViewOptions markerOptions = new MarkerViewOptions().anchor(anchorU, anchorV).position(new LatLng()); + 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().position(new LatLng()).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().position(new LatLng()).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().position(new LatLng()).getMarker(); + assertEquals("anchorU should match ", 0.5, marker.getInfoWindowAnchorU(), 0); + assertEquals("anchorU should match ", 0, marker.getInfoWindowAnchorV(), 0); + } + + @Test + public void testRotation() { + int rotation = 90; + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(rotation); + MarkerView marker = markerOptions.getMarker(); + assertEquals("rotation should match ", rotation, marker.getRotation(), 0); + } + + @Test + public void testRotationAboveMax() { + MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(390).position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals(marker.getRotation(), 30, 0); + } + + @Test + public void testRotationBelowMin() { + MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(-10).position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals(marker.getRotation(), 350, 0); + } + + @Test + public void testRotationUpdatePositive() { + float startRotation = 45; + float endRotation = 180; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, endRotation); + } + + @Test + public void testRotationUpdateNegative() { + float startRotation = 10; + float endRotation = 270; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, endRotation); + } + + @Test + public void testRotationUpdateMax() { + float startRotation = 359; + float endRotation = 0; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, 0); + } + + @Test + public void testRotationUpdateMin() { + float startRotation = 0; + float endRotation = 359; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, endRotation); + } + + @Test + public void testVisible() { + boolean visible = false; + MarkerViewOptions markerOptions = new MarkerViewOptions().visible(visible).position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals("visible should match ", visible, marker.isVisible()); + } + + @Test + public void testVisibleDefault() { + assertTrue(new MarkerViewOptions().position(new LatLng()).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().position(new LatLng()).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/annotations/PolygonTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java index 744bf55c07..3933c68887 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java @@ -1,9 +1,5 @@ package com.mapbox.mapboxsdk.annotations; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; import com.mapbox.mapboxsdk.geometry.LatLng; import org.junit.Test; @@ -16,64 +12,64 @@ 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 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 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 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 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 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 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 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)); + @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)); - } + 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)); + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java index b95c9dba2a..54bb0e8cf4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java @@ -1,7 +1,5 @@ package com.mapbox.mapboxsdk.annotations; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; import com.mapbox.mapboxsdk.geometry.LatLng; import org.junit.Test; @@ -14,64 +12,64 @@ 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 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 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 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 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 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 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 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)); + @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)); - } + 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)); + } } 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 bce020255e..a8aad8d639 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 @@ -18,108 +18,109 @@ 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); - CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5); - 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); - 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); - assertEquals("toString should match", "Target: LatLng [latitude=1.0, longitude=2.0, altitude=0.0], Zoom:3.0, Bearing:5.0, Tilt:4.0", cameraPosition.toString()); - } - - @Test - public void testHashcode() { - LatLng latLng = new LatLng(1, 2); - CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5); - assertEquals("hashCode should match", -1007681505, 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); - 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); - } -} + 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); + 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); + 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.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 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); + assertEquals("toString should match", "Target: LatLng [latitude=1.0, longitude=2.0, altitude=0.0], Zoom:3.0, " + + "Bearing:5.0, Tilt:4.0", cameraPosition.toString()); + } + + @Test + public void testHashcode() { + LatLng latLng = new LatLng(1, 2); + CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5); + assertEquals("hashCode should match", -1007681505, 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); + 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); + } +}
\ No newline at end of file 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 index 3d9b2a9364..5623afeb58 100644 --- 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 @@ -9,13 +9,13 @@ import static junit.framework.Assert.assertEquals; public class StyleVersionTest { - private static final double DELTA = 1e-15; + 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); - } + @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 b2cc1e9046..a42ca96cf5 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 @@ -20,185 +20,186 @@ import static org.junit.Assert.assertTrue; public class LatLngBoundsTest { - private static final double DELTA = 1e-15; - - private LatLngBounds mLatLngBounds; - 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() { - mLatLngBounds = 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 testNoLatLngs() { - new LatLngBounds.Builder().build(); - } - - @Test(expected = InvalidLatLngBoundsException.class) - public void testOneLatLngs() { - new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build(); - } - - @Test - public void testLatitiudeSpan() { - assertEquals("Span should be the same", 2, mLatLngBounds.getLatitudeSpan(), DELTA); - } - - @Test - public void testLongitudeSpan() { - assertEquals("Span should be the same", 2, mLatLngBounds.getLongitudeSpan(), DELTA); - } - - @Test - public void testCoordinateSpan() { - LatLngSpan latLngSpan = mLatLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan); - } - - @Test - public void testCenter() { - LatLng center = mLatLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(1, 1), center); - } - - @Test - public void testEmptySpan() { - mLatLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NOT_NULL_ISLAND) - .include(LAT_LNG_NOT_NULL_ISLAND) - .build(); - assertTrue("Should be empty", mLatLngBounds.isEmptySpan()); - } - - @Test - public void testNotEmptySpan() { - mLatLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NOT_NULL_ISLAND) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertFalse("Should not be empty", mLatLngBounds.isEmptySpan()); - } - - @Test - public void testToLatLngs() { - mLatLngBounds = 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}, - mLatLngBounds.toLatLngs()); - } - - @Test - public void testIncluding() { - assertTrue("LatLng should be included", mLatLngBounds.contains(new LatLng(1, 1))); - } - - @Test - public void testIncludes() { - 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 testNoIncluding() { - assertFalse("LatLng should not be included", mLatLngBounds.contains(new LatLng(3, 1))); - } - - @Test - public void testHashCode() { - assertEquals(2147483647, mLatLngBounds.hashCode(), -1946419200); - } - - @Test - public void testEquality() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NULL_ISLAND) - .include(LAT_LNG_NOT_NULL_ISLAND) - .build(); - assertEquals("equality should match", mLatLngBounds, latLngBounds); - assertEquals("not equal to a different object type", mLatLngBounds.equals(LAT_LNG_NOT_NULL_ISLAND), false); - } - - @Test - public void testToString() { - assertEquals(mLatLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0"); - } - - @Test - public void testIntersect() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(1, 1)) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertEquals("intersect should match", latLngBounds, latLngBounds.intersect(mLatLngBounds.getLatNorth(), mLatLngBounds.getLonEast(), mLatLngBounds.getLatSouth(), mLatLngBounds.getLonWest())); - } - - @Test - public void testNoIntersect() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(new LatLng(9, 8)) - .build(); - assertNull(latLngBounds.intersect(mLatLngBounds)); - } - - @Test - public void testInnerUnion() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(1, 1)) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertEquals("union should match", latLngBounds, latLngBounds.intersect(mLatLngBounds)); - } - - @Test - public void testOuterUnion() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(new LatLng(9, 8)) - .build(); - assertEquals("outer union should match", - latLngBounds.union(mLatLngBounds), - new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(LAT_LNG_NULL_ISLAND) - .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); - } + 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 testNoLatLngs() { + new LatLngBounds.Builder().build(); + } + + @Test(expected = InvalidLatLngBoundsException.class) + public void testOneLatLngs() { + new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build(); + } + + @Test + public void testLatitiudeSpan() { + assertEquals("Span should be the same", 2, latLngBounds.getLatitudeSpan(), DELTA); + } + + @Test + public void testLongitudeSpan() { + assertEquals("Span should be the same", 2, latLngBounds.getLongitudeSpan(), DELTA); + } + + @Test + public void testCoordinateSpan() { + LatLngSpan latLngSpan = latLngBounds.getSpan(); + assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan); + } + + @Test + public void testCenter() { + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(1, 1), center); + } + + @Test + public void testEmptySpan() { + latLngBounds = new LatLngBounds.Builder() + .include(LAT_LNG_NOT_NULL_ISLAND) + .include(LAT_LNG_NOT_NULL_ISLAND) + .build(); + assertTrue("Should be empty", latLngBounds.isEmptySpan()); + } + + @Test + public void testNotEmptySpan() { + 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 testToLatLngs() { + 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 testIncluding() { + assertTrue("LatLng should be included", latLngBounds.contains(new LatLng(1, 1))); + } + + @Test + public void testIncludes() { + 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 testNoIncluding() { + assertFalse("LatLng should not be included", latLngBounds.contains(new LatLng(3, 1))); + } + + @Test + public void testHashCode() { + assertEquals(2147483647, latLngBounds.hashCode(), -1946419200); + } + + @Test + public void testEquality() { + 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 testIntersect() { + 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 testNoIntersect() { + LatLngBounds latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(10, 10)) + .include(new LatLng(9, 8)) + .build(); + assertNull(latLngBounds.intersect(this.latLngBounds)); + } + + @Test + public void testInnerUnion() { + 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 testOuterUnion() { + 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 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 e184097a43..12297247cf 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 @@ -11,55 +11,55 @@ 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); + 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 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 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 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 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 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 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); - } + @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 de5dbc5e09..5cbf1fa63c 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 @@ -16,182 +16,182 @@ 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); - } - - @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), - 157425.53710839353, 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); - } - - @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 latLng = new LatLng(45.0, -185.0); - LatLng wrapped = latLng.wrap(); - assertNotSame(latLng, wrapped); - assertEquals("longitude wrapped value", wrapped.getLongitude(), 175.0, DELTA); - } - - @Test - public void testUnnecessaryWrapped() { - LatLng latLng = new LatLng(45.0, 50.0); - LatLng wrapped = latLng.wrap(); - assertNotSame(latLng, wrapped); - assertEquals("longitude wrapped value", wrapped.getLongitude(), 50.0, DELTA); - } + 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); + } + + @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), + 157425.53710839353, 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); + } + + @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 latLng = new LatLng(45.0, -185.0); + LatLng wrapped = latLng.wrap(); + assertNotSame(latLng, wrapped); + assertEquals("longitude wrapped value", wrapped.getLongitude(), 175.0, DELTA); + } + + @Test + public void testUnnecessaryWrapped() { + LatLng latLng = new LatLng(45.0, 50.0); + LatLng wrapped = latLng.wrap(); + assertNotSame(latLng, wrapped); + assertEquals("longitude wrapped value", wrapped.getLongitude(), 50.0, DELTA); + } } 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 5525684601..00fd125a1a 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 @@ -11,56 +11,56 @@ import static org.junit.Assert.assertNotNull; public class ProjectedMetersTest { - private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0); + 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 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 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 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 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 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 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 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); - } + @Test + public void testParcelable() { + ProjectedMeters meters = new ProjectedMeters(1, 1); + 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 cad268c2ba..12b779de5d 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 @@ -11,84 +11,85 @@ 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); - } + 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); + } } 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 dbde9a4420..ce0cb00b0b 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 @@ -7,7 +7,6 @@ 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; @@ -22,174 +21,170 @@ import static org.junit.Assert.assertTrue; public class MapboxMapOptionsTest { - @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, 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().getMinZoom()); - assertEquals(5.0f, new MapboxMapOptions().minZoom(5.0f).getMinZoom()); - assertNotEquals(2.0f, new MapboxMapOptions().minZoom(5.0f).getMinZoom()); - } - - @Test - public void testMaxZoom() { - assertEquals(MapboxConstants.MAXIMUM_ZOOM, new MapboxMapOptions().getMaxZoom()); - assertEquals(5.0f, new MapboxMapOptions().maxZoom(5.0f).getMaxZoom()); - assertNotEquals(2.0f, new MapboxMapOptions().maxZoom(5.0f).getMaxZoom()); - } - - @Test - public void testLocationEnabled() { - assertFalse(new MapboxMapOptions().getLocationEnabled()); - assertTrue(new MapboxMapOptions().locationEnabled(true).getLocationEnabled()); - assertFalse(new MapboxMapOptions().locationEnabled(false).getLocationEnabled()); - } - - @Test - public void testTiltGesturesEnabled() { - assertTrue(new MapboxMapOptions().getTiltGesturesEnabled()); - 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 testZoomControlsEnabled() { - assertFalse(new MapboxMapOptions().getZoomControlsEnabled()); - assertTrue(new MapboxMapOptions().zoomControlsEnabled(true).getZoomControlsEnabled()); - assertFalse(new MapboxMapOptions().zoomControlsEnabled(false).getZoomControlsEnabled()); - } - - @Test - public void testStyleUrl() { - assertEquals(Style.DARK, new MapboxMapOptions().styleUrl(Style.DARK).getStyle()); - assertNotEquals(Style.LIGHT, new MapboxMapOptions().styleUrl(Style.DARK).getStyle()); - assertNull(new MapboxMapOptions().getStyle()); - } - - @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 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()); - assertNotEquals("nottest", new MapboxMapOptions().accessToken("test").getStyle()); - } + 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, 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 testLocationEnabled() { + assertFalse(new MapboxMapOptions().getLocationEnabled()); + assertTrue(new MapboxMapOptions().locationEnabled(true).getLocationEnabled()); + assertFalse(new MapboxMapOptions().locationEnabled(false).getLocationEnabled()); + } + + @Test + public void testTiltGesturesEnabled() { + assertTrue(new MapboxMapOptions().getTiltGesturesEnabled()); + 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 testZoomControlsEnabled() { + assertFalse(new MapboxMapOptions().getZoomControlsEnabled()); + assertTrue(new MapboxMapOptions().zoomControlsEnabled(true).getZoomControlsEnabled()); + assertFalse(new MapboxMapOptions().zoomControlsEnabled(false).getZoomControlsEnabled()); + } + + @Test + public void testStyleUrl() { + assertEquals(Style.DARK, new MapboxMapOptions().styleUrl(Style.DARK).getStyle()); + assertNotEquals(Style.LIGHT, new MapboxMapOptions().styleUrl(Style.DARK).getStyle()); + assertNull(new MapboxMapOptions().getStyle()); + } + + @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 testMyLocationForegroundTint() { + assertEquals(Color.BLUE, new MapboxMapOptions() + .myLocationForegroundTintColor(Color.BLUE).getMyLocationForegroundTintColor()); + } + + @Test + public void testMyLocationBackgroundTint() { + assertEquals(Color.BLUE, new MapboxMapOptions() + .myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor()); + } } 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 deleted file mode 100644 index 9d0a1c0ad7..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ /dev/null @@ -1,868 +0,0 @@ -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; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; -import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.util.ArrayList; -import java.util.List; - -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; -import static org.mockito.Mockito.when; - -public class MapboxMapTest { - - private MapboxMap mMapboxMap; - - @InjectMocks - MapView mMapView = mock(MapView.class); - - @Mock - MapboxMap.OnMarkerClickListener mOnMarkerClickListener; - - @Mock - MapboxMap.OnCameraChangeListener mOnCameraChangeListener; - - @Mock - MapboxMap.InfoWindowAdapter mInfoWindowAdapter; - - @Mock - MapboxMap.OnScrollListener mScrollListener; - - @Mock - MapboxMap.OnFlingListener mFlingListener; - - @Mock - MapboxMap.OnFpsChangedListener mFpsChangedListener; - - @Mock - MapboxMap.OnInfoWindowClickListener mWindowClickListener; - - @Mock - MapboxMap.OnInfoWindowCloseListener mWindowCloseListener; - - @Mock - MapboxMap.OnInfoWindowLongClickListener mWindowLongClickListener; - - @Mock - MapboxMap.OnMyLocationChangeListener mLocationChangeListener; - - @Mock - MapboxMap.OnMyLocationTrackingModeChangeListener mMyLocationTrackingModeChangeListener; - - @Mock - MapboxMap.OnMyBearingTrackingModeChangeListener mMyBearingTrackingModeChangeListener; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - mMapboxMap = new MapboxMap(mMapView); - } - - @Test - public void testSanity() { - assertNotNull("mMapboxMap should not be null", mMapboxMap); - } - - @Test - public void testMock() { - assertNotNull("mMapView should be mocked", mMapView); - } - - @Test - public void testGetMapView() { - assertNotNull("MapView should be non null", mMapboxMap.getMapView()); - } - - // - // UiSettings - // - - @Test - public void testUiSettings() { - assertNotNull("UiSettings should not be null", mMapboxMap.getUiSettings()); - } - - // - // MinZoomLevel - // - - @Test - public void testMinZoom() { - double zoom = 10; - mMapboxMap.setMinZoom(zoom); - assertEquals("MinZoom should match", zoom, mMapboxMap.getMinZoom(), 0); - } - - @Test - public void testMaxZoom() { - double zoom = 10; - mMapboxMap.setMaxZoom(zoom); - assertEquals("MaxZoom should match", zoom, mMapboxMap.getMaxZoom(), 0); - } - - @Test - public void testInitialZoomLevels() { - assertEquals("MaxZoom should match", 0, mMapboxMap.getMaxZoom(), 0); - assertEquals("MinZoom should match", 0, mMapboxMap.getMinZoom(), 0); - } - - // - // TrackingSettings - // - - @Test - public void testTrackingSettings() { - assertNotNull("TrackingSettings should not be null", mMapboxMap.getTrackingSettings()); - } - - // - // Projection - // - - @Test - public void testProjection() { - assertNotNull("Projection should not be null", mMapboxMap.getProjection()); - } - - // - // InfoWindow - // - - @Test - public void testConcurrentInfoWindowEnabled() { - mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true); - assertTrue("ConcurrentWindows should be true", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); - } - - @Test - public void testConcurrentInfoWindowDisabled() { - mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false); - assertFalse("ConcurrentWindows should be false", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); - } - - @Test - public void testInfoWindowAdapter() { - mMapboxMap.setInfoWindowAdapter(mInfoWindowAdapter); - assertEquals("InfoWindowAdpter should be the same", mInfoWindowAdapter, mMapboxMap.getInfoWindowAdapter()); - } - - // - // Location - // - - @Test - public void testMyLocationEnabled() { - when(mMapView.isPermissionsAccepted()).thenReturn(true); - mMapboxMap.setMyLocationEnabled(true); - assertTrue("MyLocationEnabled should be true", mMapboxMap.isMyLocationEnabled()); - - } - - @Test - public void testMyLocationDisabled() { - when(mMapView.isPermissionsAccepted()).thenReturn(true); - mMapboxMap.setMyLocationEnabled(false); - assertFalse("MyLocationEnabled should be false", mMapboxMap.isMyLocationEnabled()); - } - - // - // padding - // - - @Test - public void testPadding() { - mMapboxMap.setOnCameraChangeListener(mOnCameraChangeListener); - 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(1)).onCameraChange(position); - } - - // - // setters/getters interfaces - // - - @Test - public void testScrollListener() { - mMapboxMap.setOnScrollListener(mScrollListener); - assertEquals("ScrollListener should match", mScrollListener, mMapboxMap.getOnScrollListener()); - } - - @Test - public void testFlingListener() { - mMapboxMap.setOnFlingListener(mFlingListener); - assertEquals("FlingListener should match", mFlingListener, mMapboxMap.getOnFlingListener()); - } - - @Test - public void testFpsListener() { - mMapboxMap.setOnFpsChangedListener(mFpsChangedListener); - assertEquals("FpsListener should match", mFpsChangedListener, mMapboxMap.getOnFpsChangedListener()); - } - - @Test - public void testInfoWindowClickListener() { - mMapboxMap.setOnInfoWindowClickListener(mWindowClickListener); - assertEquals("InfoWidowClickListener should match", mWindowClickListener, mMapboxMap.getOnInfoWindowClickListener()); - } - - @Test - public void testInfoWindowCloseListener() { - mMapboxMap.setOnInfoWindowCloseListener(mWindowCloseListener); - assertEquals("InfoWindowCloseListener should match", mWindowCloseListener, mMapboxMap.getOnInfoWindowCloseListener()); - } - - @Test - public void testInfoWindowLongClickListener() { - mMapboxMap.setOnInfoWindowLongClickListener(mWindowLongClickListener); - assertEquals("InfoWindowLongClickListener should match", mWindowLongClickListener, mMapboxMap.getOnInfoWindowLongClickListener()); - } - - @Test - public void testOnBearingTrackingModeChangeListener() { - mMapboxMap.setOnMyBearingTrackingModeChangeListener(mMyBearingTrackingModeChangeListener); - assertEquals("MyBearingTrackingChangeListerner should match", mMyBearingTrackingModeChangeListener, mMapboxMap.getOnMyBearingTrackingModeChangeListener()); - } - - @Test - public void testOnLocationTrackingModeChangeListener() { - mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener); - assertEquals("MyLocationTrackigChangeListener should match", mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener()); - } - - // - // CameraPosition - // - - @Test - public void testCameraPosition() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - // - // Camera - moveCamera - // - - @Test - public void testNewCameraPositionMoveCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position)); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - // - // Camera - animateCamera - // - - @Test - public void testNewCameraPositionAnimateCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position)); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - @Test - public void testNewCameraPositionAnimateCameraWithCallbackParameter() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), null); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - @Test - public void testNewCameraPositionAnimateCameraWithDurationParameter() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - @Test - public void testNewCameraPositionAnimateCameraWithDurationAndCallbackParameter() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0, null); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - // - // Camera - easeCamera - // - - @Test - public void testNewCameraPositionEaseCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position)); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - @Test - public void testNewCameraPositionEaseCameraWithCallbackParameter() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000, null); - assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); - } - - // - // Camera - LatLng - // - - @Test - public void testLatLngMoveCamera() { - mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(4, 5))); - assertEquals("LatLng should be same", new LatLng(4, 5), mMapboxMap.getCameraPosition().target); - } - - @Test - public void testLatLngAnimateCamera() { - mMapboxMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(4, 5))); - assertEquals("LatLng should be same", new LatLng(4, 5), mMapboxMap.getCameraPosition().target); - } - - @Test - public void testLatLngEaseCamera() { - mMapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(4, 5)), 1000); - assertEquals("LatLng should be same", new LatLng(4, 5), mMapboxMap.getCameraPosition().target); - } - - // - // Camera - LatLngZoom - // - - @Test - public void testLatLngZoomMoveCamera() { - mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(4, 5), 10)); - assertEquals("LatLng should be same", new LatLng(4, 5), mMapboxMap.getCameraPosition().target); - assertTrue("Zoomlevel should be same", 10 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testLatLngZoomAnimateCamera() { - mMapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(4, 5), 10)); - assertEquals("LatLng should be same", new LatLng(4, 5), mMapboxMap.getCameraPosition().target); - assertTrue("Zoomlevel should be same", 10 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testLatLngZoomEaseCamera() { - mMapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(4, 5), 10), 1000); - assertEquals("LatLng should be same", new LatLng(4, 5), mMapboxMap.getCameraPosition().target); - assertTrue("Zoomlevel should be same", 10 == mMapboxMap.getCameraPosition().zoom); - } - - // - // 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 - // - - @Test - public void testZoomInMoveCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.moveCamera(CameraUpdateFactory.zoomIn()); - assertTrue("Zoomlevel should be same", 4 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomOutMoveCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.moveCamera(CameraUpdateFactory.zoomOut()); - assertTrue("Zoomlevel should be same", 2 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomByMoveCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.moveCamera(CameraUpdateFactory.zoomBy(3)); - assertTrue("Zoomlevel should be same", 6 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomByPointMoveCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.moveCamera(CameraUpdateFactory.zoomBy(3, new Point(0, 0))); - assertTrue("Zoomlevel should be same", 6 == mMapboxMap.getCameraPosition().zoom); - // todo calculate and check LatLng - } - - @Test - public void testZoomToMoveCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.moveCamera(CameraUpdateFactory.zoomTo(12)); - assertTrue("Zoomlevel should be same", 12 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomInAnimateCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.animateCamera(CameraUpdateFactory.zoomIn()); - assertTrue("Zoomlevel should be same", 4 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomOutAnimateCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.animateCamera(CameraUpdateFactory.zoomOut()); - assertTrue("Zoomlevel should be same", 2 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomByAnimateCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(3)); - assertTrue("Zoomlevel should be same", 6 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomToAnimateCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12)); - assertTrue("Zoomlevel should be same", 12 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomByPointAnimateCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(1, new Point(0, 0))); - assertTrue("Zoomlevel should be same", 4 == mMapboxMap.getCameraPosition().zoom); - // todo calculate and check LatLng - } - - @Test - public void testZoomInEaseCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.easeCamera(CameraUpdateFactory.zoomIn(), 1000); - assertTrue("Zoomlevel should be same", 4 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomOutEaseCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.easeCamera(CameraUpdateFactory.zoomOut(), 1000); - assertTrue("Zoomlevel should be same", 2 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomByEaseCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.easeCamera(CameraUpdateFactory.zoomBy(3), 1000); - assertTrue("Zoomlevel should be same", 6 == mMapboxMap.getCameraPosition().zoom); - } - - @Test - public void testZoomByPointCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.easeCamera(CameraUpdateFactory.zoomBy(3, new Point(0, 0)), 1000); - assertTrue("Zoomlevel should be same", 6 == mMapboxMap.getCameraPosition().zoom); - // todo calculate and check LatLng - } - - @Test - public void testZoomToEaseCamera() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setCameraPosition(position); - mMapboxMap.easeCamera(CameraUpdateFactory.zoomTo(12), 1000); - assertTrue("Zoomlevel should be same", 12 == mMapboxMap.getCameraPosition().zoom); - } - - // - // OnCameraChangeListener - // - - @Test - public void testOnCameraChangeListener() { - CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); - mMapboxMap.setOnCameraChangeListener(mOnCameraChangeListener); - mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position)); - verify(mOnCameraChangeListener, times(1)).onCameraChange(position); - } - - // - // Annotations - // - - @Test - public void testAddMarker() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - assertTrue("Marker should be contained", mMapboxMap.getMarkers().contains(marker)); - } - - @Test(expected = InvalidMarkerPositionException.class) - public void testAddMarkerInvalidPosition(){ - new MarkerOptions().getMarker(); - } - - @Test - public void testAddMarkers() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b"); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - List<Marker> markers = mMapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 2", 2, mMapboxMap.getMarkers().size()); - assertTrue(mMapboxMap.getMarkers().contains(markers.get(0))); - assertTrue(mMapboxMap.getMarkers().contains(markers.get(1))); - } - - @Test - public void testAddMarkersEmpty() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - mMapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 0", 0, mMapboxMap.getMarkers().size()); - } - - @Test - public void testAddMarkersSingleMarker() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng()); - markerList.add(markerOptions); - List<Marker> markers = mMapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 1", 1, mMapboxMap.getMarkers().size()); - assertTrue(mMapboxMap.getMarkers().contains(markers.get(0))); - } - - @Test - public void testAddPolygon() { - PolygonOptions polygonOptions = new PolygonOptions().add(new LatLng()); - Polygon polygon = mMapboxMap.addPolygon(polygonOptions); - assertTrue("Polygon should be contained", mMapboxMap.getPolygons().contains(polygon)); - } - - @Test - public void testAddEmptyPolygon() { - PolygonOptions polygonOptions = new PolygonOptions(); - Polygon polygon = mMapboxMap.addPolygon(polygonOptions); - assertTrue("Polygon should be ignored", !mMapboxMap.getPolygons().contains(polygon)); - } - - @Test - public void testAddPolygons() { - List<PolygonOptions> polygonList = new ArrayList<>(); - PolygonOptions polygonOptions1 = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); - PolygonOptions polygonOptions2 = new PolygonOptions().fillColor(Color.WHITE).add(new LatLng()); - PolygonOptions polygonOptions3 = new PolygonOptions(); - polygonList.add(polygonOptions1); - polygonList.add(polygonOptions2); - polygonList.add(polygonOptions3); - mMapboxMap.addPolygons(polygonList); - assertEquals("Polygons size should be 2", 2, mMapboxMap.getPolygons().size()); - assertTrue(mMapboxMap.getPolygons().contains(polygonOptions1.getPolygon())); - assertTrue(mMapboxMap.getPolygons().contains(polygonOptions2.getPolygon())); - assertTrue("Polygon should be ignored", !mMapboxMap.getPolygons().contains(polygonOptions3.getPolygon())); - } - - @Test - public void addPolygonsEmpty() { - mMapboxMap.addPolygons(new ArrayList<PolygonOptions>()); - assertEquals("Polygons size should be 0", 0, mMapboxMap.getPolygons().size()); - } - - @Test - public void addPolygonsSingle() { - List<PolygonOptions> polygonList = new ArrayList<>(); - PolygonOptions polygonOptions = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); - polygonList.add(polygonOptions); - mMapboxMap.addPolygons(polygonList); - assertEquals("Polygons size should be 1", 1, mMapboxMap.getPolygons().size()); - assertTrue(mMapboxMap.getPolygons().contains(polygonOptions.getPolygon())); - } - - @Test - public void testAddPolyline() { - PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng()); - Polyline polyline = mMapboxMap.addPolyline(polylineOptions); - assertTrue("Polyline should be contained", mMapboxMap.getPolylines().contains(polyline)); - } - - @Test - public void testAddEmptyPolyline() { - PolylineOptions polylineOptions = new PolylineOptions(); - Polyline polyline = mMapboxMap.addPolyline(polylineOptions); - assertTrue("Polyline should be ignored", !mMapboxMap.getPolylines().contains(polyline)); - } - - @Test - public void testAddPolylines() { - List<PolylineOptions> polylineList = new ArrayList<>(); - PolylineOptions polygonOptions1 = new PolylineOptions().color(Color.BLACK).add(new LatLng()); - PolylineOptions polygonOptions2 = new PolylineOptions().color(Color.WHITE).add(new LatLng()); - PolylineOptions polygonOptions3 = new PolylineOptions(); - polylineList.add(polygonOptions1); - polylineList.add(polygonOptions2); - polylineList.add(polygonOptions3); - mMapboxMap.addPolylines(polylineList); - assertEquals("Polygons size should be 2", 2, mMapboxMap.getPolylines().size()); - assertTrue(mMapboxMap.getPolylines().contains(polygonOptions1.getPolyline())); - assertTrue(mMapboxMap.getPolylines().contains(polygonOptions2.getPolyline())); - assertTrue("Polyline should be ignored", !mMapboxMap.getPolylines().contains(polygonOptions3.getPolyline())); - } - - @Test - public void testAddPolylinesEmpty() { - mMapboxMap.addPolylines(new ArrayList<PolylineOptions>()); - assertEquals("Polygons size should be 0", 0, mMapboxMap.getPolylines().size()); - } - - @Test - public void testAddPolylinesSingle() { - List<PolylineOptions> polylineList = new ArrayList<>(); - PolylineOptions polygonOptions = new PolylineOptions().color(Color.BLACK).add(new LatLng()); - polylineList.add(polygonOptions); - mMapboxMap.addPolylines(polylineList); - assertEquals("Polygons size should be 1", 1, mMapboxMap.getPolylines().size()); - assertTrue(mMapboxMap.getPolylines().contains(polygonOptions.getPolyline())); - } - - @Test - public void testRemoveMarker() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - mMapboxMap.removeMarker(marker); - assertTrue("Markers should be empty", mMapboxMap.getMarkers().isEmpty()); - } - - @Test - public void testRemovePolygon() { - PolygonOptions polygonOptions = new PolygonOptions(); - Polygon polygon = mMapboxMap.addPolygon(polygonOptions); - mMapboxMap.removePolygon(polygon); - assertTrue("Polygons should be empty", mMapboxMap.getPolylines().isEmpty()); - } - - @Test - public void testRemovePolyline() { - PolylineOptions polylineOptions = new PolylineOptions(); - Polyline polyline = mMapboxMap.addPolyline(polylineOptions); - mMapboxMap.removePolyline(polyline); - assertTrue("Polylines should be empty", mMapboxMap.getPolylines().isEmpty()); - } - - @Test - public void testRemoveAnnotation() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - mMapboxMap.removeAnnotation(marker); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testRemoveAnnotationById() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - mMapboxMap.addMarker(markerOptions); - // id will always be 0 in unit tests - mMapboxMap.removeAnnotation(0); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testRemoveAnnotations() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - mMapboxMap.addMarkers(markerList); - mMapboxMap.removeAnnotations(); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testClear() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - mMapboxMap.addMarkers(markerList); - mMapboxMap.clear(); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testRemoveAnnotationsByList() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - List<Marker> markers = mMapboxMap.addMarkers(markerList); - Marker marker = mMapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c")); - mMapboxMap.removeAnnotations(markers); - assertTrue("Annotations should not be empty", mMapboxMap.getAnnotations().size() == 1); - assertTrue("Marker should be contained", mMapboxMap.getAnnotations().contains(marker)); - } - - @Test - public void testGetAnnotationById() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker initialMarker = mMapboxMap.addMarker(markerOptions); - Marker retrievedMarker = (Marker) mMapboxMap.getAnnotation(0); - assertEquals("Markers should match", initialMarker, retrievedMarker); - } - - @Test - public void testGetAnnotations() { - assertNotNull("Annotations should be non null", mMapboxMap.getAnnotations()); - } - - @Test - public void testGetMarkers() { - assertNotNull("Markers should be non null", mMapboxMap.getMarkers()); - } - - @Test - public void testGetPolygons() { - assertNotNull("Polygons should be non null", mMapboxMap.getPolygons()); - } - - @Test - public void testGetPolylines() { - assertNotNull("Polylines should be non null", mMapboxMap.getPolylines()); - } - - @Test - public void testGetSelectedMarkers() { - assertNotNull("Selected markers should be non null", mMapboxMap.getSelectedMarkers()); - } - - @Test - public void testSelectMarker() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); - mMapboxMap.selectMarker(marker); - assertTrue("Marker should be contained", mMapboxMap.getSelectedMarkers().contains(marker)); - } - - @Test - public void testDeselectMarker() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); - mMapboxMap.selectMarker(marker); - mMapboxMap.deselectMarker(marker); - assertTrue("Selected markers should be empty", mMapboxMap.getSelectedMarkers().isEmpty()); - } - - @Test - public void testDeselectMarkers() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker1 = mMapboxMap.addMarker(markerOptions); - Marker marker2 = mMapboxMap.addMarker(markerOptions); - when(mOnMarkerClickListener.onMarkerClick(marker1)).thenReturn(true); - when(mOnMarkerClickListener.onMarkerClick(marker2)).thenReturn(true); - mMapboxMap.selectMarker(marker1); - mMapboxMap.selectMarker(marker2); - mMapboxMap.deselectMarkers(); - assertTrue("Selected markers should be empty", mMapboxMap.getSelectedMarkers().isEmpty()); - } - - // - // OnMarkerClick interface - // - - @Test - public void testOnMarkerClick() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - Marker marker = new MarkerOptions().position(new LatLng()).getMarker(); - when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); - mMapboxMap.selectMarker(marker); - verify(mOnMarkerClickListener, times(1)).onMarkerClick(marker); - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectionTest.java deleted file mode 100644 index fac06de16b..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectionTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - -public class ProjectionTest { - - @InjectMocks - MapView mMapView = mock(MapView.class); - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testSanity() { - Projection projection = new Projection(mMapView); - assertNotNull("projection should not be null", projection); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java index 266bbadd95..57f3b942af 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java @@ -1,53 +1,70 @@ package com.mapbox.mapboxsdk.maps; -import com.mapbox.mapboxsdk.constants.MyBearingTracking; +import android.Manifest; +import android.content.Context; +import android.content.pm.PackageManager; + import com.mapbox.mapboxsdk.constants.MyLocationTracking; +import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; +import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TrackingSettingsTest { - @InjectMocks - MapView mMapView = mock(MapView.class); - - @Test - public void testSanity() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); - assertNotNull("trackingsettings should not be null", trackingSettings); - } - - @Test - public void testMyLocationTrackingMode() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - assertEquals("MyLocationTrackingMode should match", MyLocationTracking.TRACKING_FOLLOW, trackingSettings.getMyLocationTrackingMode()); - } - - @Test - public void testMyBearingTrackingMode() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); - trackingSettings.setMyBearingTrackingMode(MyBearingTracking.COMPASS); - assertEquals("MyLocationTrackingMode should match", MyBearingTracking.COMPASS, trackingSettings.getMyBearingTrackingMode()); - } - - @Test - public void testDismissTrackingModesOnGesture() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); - trackingSettings.setDismissTrackingOnGesture(false); - assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); - } - - @Test - public void testValidateGesturesForTrackingModes(){ - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); - trackingSettings.setDismissTrackingOnGesture(false); - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); - } + @InjectMocks + MyLocationView myLocationView = mock(MyLocationView.class); + + @InjectMocks + UiSettings uiSettings = mock(UiSettings.class); + + @InjectMocks + FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); + + private TrackingSettings trackingSettings; + + @Before + public void beforeTest() { + trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointChangeListener); + } + + @Test + public void testSanity() { + assertNotNull("trackingsettings should not be null", trackingSettings); + } + + @Test + public void testDismissTrackingModesOnGesture() { + trackingSettings.setDismissTrackingOnGesture(false); + assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); + } + + @Test + public void testValidateGesturesForTrackingModes() { + trackingSettings.setDismissTrackingOnGesture(false); + trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); + assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); + } + + @Test + public void testMyLocationEnabled() { + // setup mock context to provide accepted location permission + Context context = mock(Context.class); + when(myLocationView.getContext()).thenReturn(context); + when(context.checkPermission(eq(Manifest.permission.ACCESS_COARSE_LOCATION), anyInt(), + anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); + + assertFalse("Location should be disabled by default.", trackingSettings.isMyLocationEnabled()); + trackingSettings.setMyLocationEnabled(true); + assertTrue("Location should be enabled", trackingSettings.isMyLocationEnabled()); + } } 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 14fc84723d..1f532255d7 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 @@ -1,6 +1,11 @@ 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; @@ -15,293 +20,321 @@ 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() { - assertNotNull("uiSettings should not be null", uiSettings); - } - - @Test - public void testCompassEnabled() { - 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() { - uiSettings.setCompassGravity(Gravity.LEFT); - assertEquals("Compass gravity should be same", Gravity.LEFT, uiSettings.getCompassGravity()); - } - - @Test - public void testCompassMargins() { - 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(){ - assertTrue("Compass should fade when facing north by default.", uiSettings.isCompassFadeWhenFacingNorth()); - uiSettings.setCompassFadeFacingNorth(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() { - uiSettings.setLogoEnabled(false); - assertEquals("Logo should be disabled", false, uiSettings.isLogoEnabled()); - } - - @Test - public void testLogoGravity() { - uiSettings.setLogoGravity(Gravity.RIGHT); - assertEquals("Logo gravity should be same", Gravity.RIGHT, uiSettings.getLogoGravity()); - } - - @Test - public void testLogoMargins() { - 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() { - uiSettings.setAttributionEnabled(true); - assertEquals("Attribution should be enabled", true, uiSettings.isAttributionEnabled()); - } - - @Test - public void testAttributionDisabled() { - uiSettings.setAttributionEnabled(false); - assertEquals("Attribution should be disabled", false, uiSettings.isLogoEnabled()); - } - - @Test - public void testAttributionGravity() { - uiSettings.setAttributionGravity(Gravity.RIGHT); - assertEquals("Attribution gravity should be same", Gravity.RIGHT, uiSettings.getAttributionGravity()); - } - - @Test - public void testAttributionMargins() { - 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 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.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 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.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 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.setZoomControlsEnabled(true); - assertEquals("Zoom controls should be enabled", true, uiSettings.isZoomControlsEnabled()); - } - - @Test - public void testZoomControlsDisabled() { - uiSettings.setZoomControlsEnabled(false); - assertEquals("Zoom controls should be disabled", false, uiSettings.isZoomControlsEnabled()); - } - - @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 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.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 testInvalidate() { - 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); - } + @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); + } + + @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 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.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 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.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 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.setZoomControlsEnabled(true); + assertEquals("Zoom controls should be enabled", true, uiSettings.isZoomControlsEnabled()); + } + + @Test + public void testZoomControlsDisabled() { + uiSettings.setZoomControlsEnabled(false); + assertEquals("Zoom controls should be disabled", false, uiSettings.isZoomControlsEnabled()); + } + + @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 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.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()); + } }
\ 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 index fd70308931..c9ce19dc85 100644 --- 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 @@ -3,7 +3,9 @@ package com.mapbox.mapboxsdk.maps.widgets; import android.graphics.Color; import android.graphics.drawable.Drawable; -import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.FocalPointChangeListener; +import com.mapbox.mapboxsdk.maps.Projection; +import com.mapbox.mapboxsdk.maps.TrackingSettings; import org.junit.Before; import org.junit.Test; @@ -20,64 +22,85 @@ import static org.mockito.Mockito.when; 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); - Drawable.ConstantState constantState = mock(Drawable.ConstantState.class); - when(foregroundDrawable.getConstantState()).thenReturn(constantState); - when(constantState.newDrawable()).thenReturn(foregroundDrawable); - locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable); - assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable()); - assertEquals("foreground bearing should match", foregroundBearingDrawable, locationViewSettings.getForegroundBearingDrawable()); - } - - @Test - public void testBackgroundDrawable() { - Drawable backgroundDrawable = mock(Drawable.class); - int[] offset = new int[]{1, 2, 3, 4}; - locationViewSettings.setBackgroundDrawable(backgroundDrawable, offset); - assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable()); - assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset())); - } - - @Test - public void testForegroundTint() { - int color = Color.RED; - locationViewSettings.setForegroundTintColor(Color.RED); - assertEquals("color should match", color, locationViewSettings.getForegroundTintColor()); - } - - @Test - public void 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()); - } - + @InjectMocks + Projection projection = mock(Projection.class); + + @InjectMocks + MyLocationView myLocationView = mock(MyLocationView.class); + + @InjectMocks + TrackingSettings trackingSettings = mock(TrackingSettings.class); + + @InjectMocks + FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); + + private MyLocationViewSettings locationViewSettings; + + @Before + public void beforeTest() { + locationViewSettings = new MyLocationViewSettings(myLocationView, projection, focalPointChangeListener); + } + + @Test + public void testSanity() { + assertNotNull("should not be null", locationViewSettings); + } + + @Test + public void testForegroundDrawables() { + Drawable foregroundDrawable = mock(Drawable.class); + Drawable foregroundBearingDrawable = mock(Drawable.class); + Drawable.ConstantState constantState = mock(Drawable.ConstantState.class); + when(foregroundDrawable.getConstantState()).thenReturn(constantState); + when(constantState.newDrawable()).thenReturn(foregroundDrawable); + locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable); + assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable()); + assertEquals("foreground bearing should match", foregroundBearingDrawable, + locationViewSettings.getForegroundBearingDrawable()); + } + + @Test + public void testBackgroundDrawable() { + Drawable backgroundDrawable = mock(Drawable.class); + int[] offset = new int[] {1, 2, 3, 4}; + locationViewSettings.setBackgroundDrawable(backgroundDrawable, offset); + assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable()); + assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset())); + } + + @Test + public void testForegroundTint() { + int color = Color.RED; + locationViewSettings.setForegroundTintColor(Color.RED); + assertEquals("color should match", color, locationViewSettings.getForegroundTintColor()); + } + + @Test + public void testForegroundTransparentTint() { + int color = Color.TRANSPARENT; + locationViewSettings.setForegroundTintColor(Color.TRANSPARENT); + assertEquals("color should match", color, locationViewSettings.getForegroundTintColor()); + } + + @Test + public void testBackgroundTint() { + int color = Color.RED; + locationViewSettings.setBackgroundTintColor(Color.RED); + assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor()); + } + + @Test + public void testBackgroundTransparentTint() { + int color = Color.TRANSPARENT; + locationViewSettings.setBackgroundTintColor(Color.TRANSPARENT); + assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor()); + } + + @Test + public void testEnabled() { + assertFalse("initial state should be false", locationViewSettings.isEnabled()); + locationViewSettings.setEnabled(true); + assertTrue("state should be true", locationViewSettings.isEnabled()); + } } + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java index 3e312d3b0a..933bf05b39 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java @@ -2,89 +2,101 @@ package com.mapbox.mapboxsdk.style.layers; import org.junit.Test; -import static org.junit.Assert.*; -import static com.mapbox.mapboxsdk.style.layers.Filter.*; +import static com.mapbox.mapboxsdk.style.layers.Filter.all; +import static com.mapbox.mapboxsdk.style.layers.Filter.any; +import static com.mapbox.mapboxsdk.style.layers.Filter.eq; +import static com.mapbox.mapboxsdk.style.layers.Filter.gt; +import static com.mapbox.mapboxsdk.style.layers.Filter.gte; +import static com.mapbox.mapboxsdk.style.layers.Filter.has; +import static com.mapbox.mapboxsdk.style.layers.Filter.in; +import static com.mapbox.mapboxsdk.style.layers.Filter.lt; +import static com.mapbox.mapboxsdk.style.layers.Filter.lte; +import static com.mapbox.mapboxsdk.style.layers.Filter.neq; +import static com.mapbox.mapboxsdk.style.layers.Filter.none; +import static com.mapbox.mapboxsdk.style.layers.Filter.notHas; +import static com.mapbox.mapboxsdk.style.layers.Filter.notIn; +import static org.junit.Assert.assertArrayEquals; /** * Tests for Filter */ public class FilterTest { - @Test - public void testAll() { - assertArrayEquals(all().toArray(), new Object[]{"all"}); - assertArrayEquals( - all(eq("key", 2), neq("key", 3)).toArray(), - new Object[]{"all", new Object[]{"==", "key", 2}, new Object[]{"!=", "key", 3}} - ); - } - - @Test - public void testAny() { - assertArrayEquals(any().toArray(), new Object[]{"any"}); - assertArrayEquals( - any(eq("key", 2), neq("key", 3)).toArray(), - new Object[]{"any", new Object[]{"==", "key", 2}, new Object[]{"!=", "key", 3}} - ); - } - - @Test - public void testNone() { - assertArrayEquals(none().toArray(), new Object[]{"none"}); - assertArrayEquals( - none(eq("key", 2), neq("key", 3)).toArray(), - new Object[]{"none", new Object[]{"==", "key", 2}, new Object[]{"!=", "key", 3}} - ); - } - - @Test - public void testHas() { - assertArrayEquals(has("key").toArray(), new Object[]{"has", "key"}); - } - - @Test - public void testHasNot() { - assertArrayEquals(notHas("key").toArray(), new Object[]{"!has", "key"}); - } - - @Test - public void testEq() { - assertArrayEquals(eq("key", 1).toArray(), new Object[]{"==", "key", 1}); - - } - - @Test - public void testNeq() { - assertArrayEquals(neq("key", 1).toArray(), new Object[]{"!=", "key", 1}); - } - - @Test - public void testGt() { - assertArrayEquals(gt("key", 1).toArray(), new Object[]{">", "key", 1}); - } - - @Test - public void testGte() { - assertArrayEquals(gte("key", 1).toArray(), new Object[]{">=", "key", 1}); - } - - @Test - public void testLt() { - assertArrayEquals(lt("key", 1).toArray(), new Object[]{"<", "key", 1}); - } - - @Test - public void testLte() { - assertArrayEquals(lte("key", 1).toArray(), new Object[]{"<=", "key", 1}); - } - - @Test - public void testIn() { - assertArrayEquals(in("key", 1, 2, "Aap").toArray(), new Object[]{"in", "key", 1, 2, "Aap"}); - } - - @Test - public void testNotIn() { - assertArrayEquals(notIn("key", 1, 2, "Noot").toArray(), new Object[]{"!in", "key", 1, 2, "Noot"}); - } + @Test + public void testAll() { + assertArrayEquals(all().toArray(), new Object[] {"all"}); + assertArrayEquals( + all(eq("key", 2), neq("key", 3)).toArray(), + new Object[] {"all", new Object[] {"==", "key", 2}, new Object[] {"!=", "key", 3}} + ); + } + + @Test + public void testAny() { + assertArrayEquals(any().toArray(), new Object[] {"any"}); + assertArrayEquals( + any(eq("key", 2), neq("key", 3)).toArray(), + new Object[] {"any", new Object[] {"==", "key", 2}, new Object[] {"!=", "key", 3}} + ); + } + + @Test + public void testNone() { + assertArrayEquals(none().toArray(), new Object[] {"none"}); + assertArrayEquals( + none(eq("key", 2), neq("key", 3)).toArray(), + new Object[] {"none", new Object[] {"==", "key", 2}, new Object[] {"!=", "key", 3}} + ); + } + + @Test + public void testHas() { + assertArrayEquals(has("key").toArray(), new Object[] {"has", "key"}); + } + + @Test + public void testHasNot() { + assertArrayEquals(notHas("key").toArray(), new Object[] {"!has", "key"}); + } + + @Test + public void testEq() { + assertArrayEquals(eq("key", 1).toArray(), new Object[] {"==", "key", 1}); + + } + + @Test + public void testNeq() { + assertArrayEquals(neq("key", 1).toArray(), new Object[] {"!=", "key", 1}); + } + + @Test + public void testGt() { + assertArrayEquals(gt("key", 1).toArray(), new Object[] {">", "key", 1}); + } + + @Test + public void testGte() { + assertArrayEquals(gte("key", 1).toArray(), new Object[] {">=", "key", 1}); + } + + @Test + public void testLt() { + assertArrayEquals(lt("key", 1).toArray(), new Object[] {"<", "key", 1}); + } + + @Test + public void testLte() { + assertArrayEquals(lte("key", 1).toArray(), new Object[] {"<=", "key", 1}); + } + + @Test + public void testIn() { + assertArrayEquals(in("key", 1, 2, "Aap").toArray(), new Object[] {"in", "key", 1, 2, "Aap"}); + } + + @Test + public void testNotIn() { + assertArrayEquals(notIn("key", 1, 2, "Noot").toArray(), new Object[] {"!in", "key", 1, 2, "Noot"}); + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java index 1106009ea8..4e82ca2318 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java @@ -2,28 +2,29 @@ package com.mapbox.mapboxsdk.style.layers; import org.junit.Test; -import static com.mapbox.mapboxsdk.style.layers.Function.*; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; - -import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Function.stop; +import static com.mapbox.mapboxsdk.style.layers.Function.zoom; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineBlur; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotNull; /** * Tests Function */ public class FunctionTest { - @Test - public void testZoomFunction() { - Function zoomF = zoom( - stop(1f, lineBlur(1f)), - stop(10f, lineBlur(20f)) - ); + @Test + public void testZoomFunction() { + Function zoomF = zoom( + stop(1f, lineBlur(1f)), + stop(10f, lineBlur(20f)) + ); - assertNotNull(zoomF.toValueObject()); - assertArrayEquals( - new Object[]{new Object[]{1f, 1f}, new Object[]{10f, 20f}}, - (Object[]) zoomF.toValueObject().get("stops") - ); - } + assertNotNull(zoomF.toValueObject()); + assertArrayEquals( + new Object[] {new Object[] {1f, 1f}, new Object[] {10f, 20f}}, + (Object[]) zoomF.toValueObject().get("stops") + ); + } } 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 index 8be0d2c663..94a6dc2194 100644 --- 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 @@ -1,17 +1,20 @@ 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() { + @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"; + 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)); - } + 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 aa0a4edd13..dd4c7b25ee 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 @@ -13,7 +13,6 @@ 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; @@ -29,227 +28,227 @@ import static org.mockito.Mockito.when; public class MockParcel { - public static Parcelable obtain(@NonNull Parcelable object) { - return obtain(object, 0); + public static Parcelable obtain(@NonNull Parcelable object) { + return obtain(object, 0); + } + + 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 Parcelable obtain(@NonNull Parcelable object, int describeContentsValue) { - testDescribeContents(object, describeContentsValue); - testParcelableArray(object); - return testParcelable(object); + public static Parcel obtain(@NonNull Parcelable target) { + Parcel parcel = new ParcelMocker(target).getMockedParcel(); + target.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + return parcel; } - 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 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; } - 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 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(); } - 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 Parcel getMockedParcel() { + return mockedParcel; } - private static class ParcelMocker { + private void setupMock() { + setupWrites(); + setupReads(); + setupOthers(); + } - public static Parcel obtain(@NonNull Parcelable target) { - Parcel parcel = new ParcelMocker(target).getMockedParcel(); - target.writeToParcel(parcel, 0); - parcel.setDataPosition(0); - return parcel; + 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; } - - public static Parcel obtain(@NonNull Parcelable[] targets) { - if (targets.length == 0) { - throw new IllegalArgumentException("The passed argument may not be empty"); + }; + 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); } - Parcel parcel = new ParcelMocker(targets[0]).getMockedParcel(); - parcel.writeParcelableArray(targets, 0); - parcel.setDataPosition(0); - return parcel; + } 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 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 void setupReads() { + when(mockedParcel.readInt()).then(new Answer<Integer>() { + @Override + public Integer answer(InvocationOnMock invocation) throws Throwable { + return (Integer) objects.get(position++); } - - private Parcel getMockedParcel() { - return mockedParcel; + }); + when(mockedParcel.readByte()).thenAnswer(new Answer<Byte>() { + @Override + public Byte answer(InvocationOnMock invocation) throws Throwable { + return (Byte) objects.get(position++); } - - private void setupMock() { - setupWrites(); - setupReads(); - setupOthers(); + }); + when(mockedParcel.readLong()).thenAnswer(new Answer<Long>() { + @Override + public Long answer(InvocationOnMock invocation) throws Throwable { + return (Long) objects.get(position++); } - - 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)); + }); + 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; + } - 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; - } - }); + 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()); + 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()); } + } } |