diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox')
22 files changed, 2235 insertions, 2212 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 eaeae78abb..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,261 +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; - - // 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); - } + @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 71931c1467..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.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); - } -} + 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 05d1f2beb1..e0415182de 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 @@ -21,169 +21,177 @@ import static org.junit.Assert.assertTrue; public class MapboxMapOptionsTest { - private static final double DELTA = 1e-15; - - @Test - public void testSanity() { - assertNotNull("should not be null", new MapboxMapOptions()); - } - - @Test - public void testDebugEnabled() { - assertFalse(new MapboxMapOptions().getDebugActive()); - assertTrue(new MapboxMapOptions().debugActive(true).getDebugActive()); - assertFalse(new MapboxMapOptions().debugActive(false).getDebugActive()); - } - - @Test - public void testCompassEnabled() { - assertTrue(new MapboxMapOptions().compassEnabled(true).getCompassEnabled()); - assertFalse(new MapboxMapOptions().compassEnabled(false).getCompassEnabled()); - } - - @Test - public void testCompassGravity() { - assertEquals(Gravity.TOP | Gravity.END, new MapboxMapOptions().getCompassGravity()); - assertEquals(Gravity.BOTTOM, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity()); - assertNotEquals(Gravity.START, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity()); - } - - @Test - public void testCompassMargins() { - assertTrue(Arrays.equals(new int[]{0, 1, 2, 3}, new MapboxMapOptions().compassMargins(new int[]{0, 1, 2, 3}).getCompassMargins())); - assertFalse(Arrays.equals(new int[]{0, 1, 2, 3}, new MapboxMapOptions().compassMargins(new int[]{0, 0, 0, 0}).getCompassMargins())); - } - - @Test - public void testLogoEnabled() { - assertTrue(new MapboxMapOptions().logoEnabled(true).getLogoEnabled()); - assertFalse(new MapboxMapOptions().logoEnabled(false).getLogoEnabled()); - } - - @Test - public void testLogoGravity() { - assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getLogoGravity()); - assertEquals(Gravity.BOTTOM, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity()); - assertNotEquals(Gravity.START, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity()); - } - - @Test - public void testLogoMargins() { - assertTrue(Arrays.equals(new int[]{0, 1, 2, 3}, new MapboxMapOptions().logoMargins(new int[]{0, 1, 2, 3}).getLogoMargins())); - assertFalse(Arrays.equals(new int[]{0, 1, 2, 3}, new MapboxMapOptions().logoMargins(new int[]{0, 0, 0, 0}).getLogoMargins())); - } - - @Test - public void testAttributionTintColor() { - assertEquals(-1, new MapboxMapOptions().getAttributionTintColor()); - assertEquals(Color.RED, new MapboxMapOptions().attributionTintColor(Color.RED).getAttributionTintColor()); - } - - @Test - public void testAttributionEnabled() { - assertTrue(new MapboxMapOptions().attributionEnabled(true).getAttributionEnabled()); - assertFalse(new MapboxMapOptions().attributionEnabled(false).getAttributionEnabled()); - } - - @Test - public void testAttributionGravity() { - assertEquals(Gravity.BOTTOM, 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()); - } - - @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()); + } + + @Test + public void testAccessToken() { + assertNull(new MapboxMapOptions().getAccessToken()); + assertEquals("test", new MapboxMapOptions().accessToken("test").getAccessToken()); + assertNotEquals("nottest", new MapboxMapOptions().accessToken("test").getStyle()); + } } 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 96c2c57084..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 @@ -4,7 +4,6 @@ import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; -import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; @@ -12,7 +11,6 @@ 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; @@ -23,49 +21,50 @@ import static org.mockito.Mockito.when; public class TrackingSettingsTest { - @InjectMocks - MyLocationView myLocationView = mock(MyLocationView.class); + @InjectMocks + MyLocationView myLocationView = mock(MyLocationView.class); - @InjectMocks - UiSettings uiSettings = mock(UiSettings.class); + @InjectMocks + UiSettings uiSettings = mock(UiSettings.class); - @InjectMocks - FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); + @InjectMocks + FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); - private TrackingSettings trackingSettings; + private TrackingSettings trackingSettings; - @Before - public void beforeTest() { - trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointChangeListener); - } + @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 testSanity() { + assertNotNull("trackingsettings should not be null", trackingSettings); + } - @Test - public void testValidateGesturesForTrackingModes() { - trackingSettings.setDismissTrackingOnGesture(false); - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); - } + @Test + public void testDismissTrackingModesOnGesture() { + trackingSettings.setDismissTrackingOnGesture(false); + 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); + @Test + public void testValidateGesturesForTrackingModes() { + trackingSettings.setDismissTrackingOnGesture(false); + trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); + assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); + } - assertFalse("Location should be disabled by default.", trackingSettings.isMyLocationEnabled()); - trackingSettings.setMyLocationEnabled(true); - assertTrue("Location should be enabled", trackingSettings.isMyLocationEnabled()); - } + @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 741929b814..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 @@ -20,321 +20,321 @@ import static org.mockito.Mockito.when; public class UiSettingsTest { - @InjectMocks - Projection projection = mock(Projection.class); - - @InjectMocks - FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); - - @InjectMocks - CompassView compassView = mock(CompassView.class); - - @InjectMocks - ImageView imageView = mock(ImageView.class); - - @InjectMocks - ImageView logoView = mock(ImageView.class); - - @InjectMocks - FrameLayout.LayoutParams layoutParams = mock(FrameLayout.LayoutParams.class); - - private UiSettings uiSettings; - - @Before - public void beforeTest() { - uiSettings = new UiSettings(projection, focalPointChangeListener, compassView, imageView, logoView); - } - - @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()); - } + @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 24f28567ba..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 @@ -22,84 +22,85 @@ import static org.mockito.Mockito.when; public class MyLocationViewSettingsTest { - @InjectMocks - Projection projection = mock(Projection.class); - - @InjectMocks - MyLocationView myLocationView = mock(MyLocationView.class); - - @InjectMocks - TrackingSettings trackingSettings = mock(TrackingSettings.class); - - @InjectMocks - FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); - - private MyLocationViewSettings locationViewSettings; - - @Before - public void beforeTest() { - locationViewSettings = new MyLocationViewSettings(myLocationView, projection, focalPointChangeListener); - } - - @Test - public void testSanity() { - assertNotNull("should not be null", locationViewSettings); - } - - @Test - public void testForegroundDrawables() { - Drawable foregroundDrawable = mock(Drawable.class); - Drawable foregroundBearingDrawable = mock(Drawable.class); - Drawable.ConstantState constantState = mock(Drawable.ConstantState.class); - when(foregroundDrawable.getConstantState()).thenReturn(constantState); - when(constantState.newDrawable()).thenReturn(foregroundDrawable); - locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable); - assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable()); - assertEquals("foreground bearing should match", foregroundBearingDrawable, locationViewSettings.getForegroundBearingDrawable()); - } - - @Test - public void testBackgroundDrawable() { - Drawable backgroundDrawable = mock(Drawable.class); - int[] offset = new int[]{1, 2, 3, 4}; - locationViewSettings.setBackgroundDrawable(backgroundDrawable, offset); - assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable()); - assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset())); - } - - @Test - public void testForegroundTint() { - int color = Color.RED; - locationViewSettings.setForegroundTintColor(Color.RED); - assertEquals("color should match", color, locationViewSettings.getForegroundTintColor()); - } - - @Test - public void testForegroundTransparentTint() { - int color = Color.TRANSPARENT; - locationViewSettings.setForegroundTintColor(Color.TRANSPARENT); - assertEquals("color should match", color, locationViewSettings.getForegroundTintColor()); - } - - @Test - public void testBackgroundTint() { - int color = Color.RED; - locationViewSettings.setBackgroundTintColor(Color.RED); - assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor()); - } - - @Test - public void testBackgroundTransparentTint() { - int color = Color.TRANSPARENT; - locationViewSettings.setBackgroundTintColor(Color.TRANSPARENT); - assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor()); - } - - @Test - public void testEnabled() { - assertFalse("initial state should be false", locationViewSettings.isEnabled()); - locationViewSettings.setEnabled(true); - assertTrue("state should be true", locationViewSettings.isEnabled()); - } + @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()); } + } } |