diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com')
10 files changed, 929 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java new file mode 100644 index 0000000000..43492e1451 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java @@ -0,0 +1,170 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.geometry.BoundingBox; +import com.mapbox.mapboxsdk.geometry.CoordinateSpan; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class BoundingBoxTest { + + private BoundingBox mBoundingBox; + + @Before + public void setup() { + mBoundingBox = new BoundingBox(20.0, 10.0, 0.0, 0.0); + } + + @Test + public void testSanity() { + BoundingBox boundingBox = new BoundingBox(0.0, 0.0, 0.0, 0.0); + assertNotNull("boundingBox should not be null", boundingBox); + } + + @Test + public void testEqualityConstructors() { + BoundingBox cornerBoundingBox = new BoundingBox(new LatLng(20.0, 10.0), new LatLng(0.0, 0.0)); + BoundingBox cloneBoundingBox = new BoundingBox(mBoundingBox); + assertEquals("boundingBoxes should match", mBoundingBox, cornerBoundingBox); + assertEquals("boundingBoxes should match", mBoundingBox, cloneBoundingBox); + } + + @Test + public void testValidBox() { + assertTrue(mBoundingBox.isValid()); + } + + @Test + public void testInvalidLatitudeSpanBox() { + mBoundingBox = new BoundingBox(0.0, 10.0, 10.0, 0.0); + assertFalse(mBoundingBox.isValid()); + } + + @Test + public void testInvalidLongitudeSpanBox() { + mBoundingBox = new BoundingBox(10.0, 0.0, 0.0, 20.0); + assertFalse(mBoundingBox.isValid()); + } + + @Test + public void testCenterCoordinate() { + LatLng center = new LatLng(10.0, 5.0); + assertEquals("boundingBox center should match", center, mBoundingBox.getCenter()); + } + + @Test + public void testUnionSameBox() { + assertEquals(mBoundingBox, mBoundingBox.union(mBoundingBox)); + } + + @Test + public void testUnionInnerBox() { + BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0); + assertEquals(mBoundingBox.union(innerBox), mBoundingBox); + } + + @Test + public void testUnionOverlapBox() { + BoundingBox resultBox = new BoundingBox(22.0, 12.0, 0.0, 0.0); + BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0); + assertEquals(resultBox, mBoundingBox.union(overlapBox)); + } + + @Test + public void testUnionOuterBox() { + BoundingBox resultBox = new BoundingBox(40.0, 40.0, 0.0, 0.0); + BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0); + assertEquals(resultBox, mBoundingBox.union(outerBox)); + } + + @Test + public void testIntersectSameBox() { + assertEquals(mBoundingBox, mBoundingBox.intersect(mBoundingBox)); + } + + @Test + public void testIntersectInnerBox() { + BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0); + assertEquals(innerBox, mBoundingBox.intersect(innerBox)); + } + + @Test + public void testIntersectOuterBox() { + BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0); + assertEquals(mBoundingBox, mBoundingBox.intersect(outerBox)); + } + + @Test + public void testIntersectOverlapBox() { + BoundingBox resultBox = new BoundingBox(20.0, 10.0, 1.0, 1.0); + BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0); + assertEquals(resultBox, mBoundingBox.intersect(overlapBox)); + } + + @Test + public void testIntersectNoneBox() { + BoundingBox outsideBox = new BoundingBox(100.0, 100.0, 50.0, 50.0); + assertNull(mBoundingBox.intersect(outsideBox)); + } + + @Test + public void testContainsCoordinate() { + LatLng coordinate = new LatLng(1.0, 1.0); + assertTrue(mBoundingBox.contains(coordinate)); + } + + @Test + public void testContainsCoordinateOnBoundary() { + LatLng coordinate = new LatLng(20.0, 9.0); + assertFalse(mBoundingBox.contains(coordinate)); + } + + @Test + public void testContainsNoCoordinate() { + LatLng coordinate = new LatLng(100.0, 100.0); + assertFalse(mBoundingBox.contains(coordinate)); + } + + @Test + public void testSpan() { + CoordinateSpan span = new CoordinateSpan(20.0, 10.0); + assertTrue(mBoundingBox.getSpan().equals(span)); + } + + @Test + public void testLatitudeSpan() { + double height = 20.0; + assertTrue(mBoundingBox.getLatitudeSpan() == height); + } + + @Test + public void testLongitudeSpan() { + double width = 10.0; + assertTrue(mBoundingBox.getLongitudeSpan() == width); + } + + @Test + public void testEmptySpanEmptyNotEmptyBox() { + assertFalse(mBoundingBox.isEmpty()); + } + + @Test + public void testEmptySpanEmptyLatitude() { + mBoundingBox = new BoundingBox(1.0, 2.0, 0.0, 2.0); + assertTrue(mBoundingBox.isEmpty()); + } + + @Test + public void testEmptySpanEmptyLongitude() { + mBoundingBox = new BoundingBox(0.0, 3.0, 0.0, 1.0); + assertTrue(mBoundingBox.isEmpty()); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java new file mode 100644 index 0000000000..cf8ba3dc4d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java @@ -0,0 +1,60 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.geometry.CoordinateBounds; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class CoordinateBoundsTest { + + @Test + public void testSanity() { + CoordinateBounds coordinateBounds = new CoordinateBounds(null, null); + assertNotNull("coordinateBounds should not be null", coordinateBounds); + } + + @Test + public void testSouthWestConstructor() { + LatLng southWest = new LatLng(12, 12); + CoordinateBounds coordinateBounds = new CoordinateBounds(southWest, null); + assertEquals("southWest should match", southWest, coordinateBounds.getSouthWest()); + } + + @Test + public void testNorthEastConstructor() { + LatLng northEast = new LatLng(12, 12); + CoordinateBounds coordinateBounds = new CoordinateBounds(null, northEast); + assertEquals("northEast should match", northEast, coordinateBounds.getNorthEast()); + } + + @Test + public void testHashCode() { + LatLng northEast = new LatLng(60, 60); + LatLng southWest = new LatLng(43, 26); + CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest); + assertEquals("hash code should match", coordinateBounds.hashCode(), -1515487232); + } + + @Test + public void testToString() { + LatLng northEast = new LatLng(60, 60); + LatLng southWest = new LatLng(43, 26); + CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest); + assertEquals("string should match", + coordinateBounds.toString(), + "CoordinateBounds [mNorthEast[" + coordinateBounds.getNorthEast() + "], mSouthWest[]" + coordinateBounds.getSouthWest() + "]"); + } + + @Test + public void testEquals() { + LatLng northEast = new LatLng(60, 60); + LatLng southWest = new LatLng(43, 26); + CoordinateBounds firstBounds = new CoordinateBounds(northEast, southWest); + CoordinateBounds sameBounds = new CoordinateBounds(northEast, southWest); + assertTrue(firstBounds.equals(sameBounds)); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java new file mode 100644 index 0000000000..c37f48bf7c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java @@ -0,0 +1,56 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.geometry.CoordinateRegion; +import com.mapbox.mapboxsdk.geometry.CoordinateSpan; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class CoordinateRegionTest { + + @Test + public void testSanity() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, span); + assertNotNull("coordinateRegion should not be null", coordinateRegion); + } + + @Test + public void testCenterConstructor() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, span); + assertEquals("center should match", coordinateRegion.getCenter(), center); + } + + @Test + public void testSpanConstructor() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, span); + assertEquals("span should match", coordinateRegion.getSpan(), span); + } + + @Test + public void testCenterMethod() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(null, span); + coordinateRegion.setCenter(center); + assertEquals("center should match", coordinateRegion.getCenter(), center); + } + + @Test + public void testSpanMethod() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, null); + coordinateRegion.setSpan(span); + assertEquals("span should match", coordinateRegion.getSpan(), span); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateSpanTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateSpanTest.java new file mode 100644 index 0000000000..f30ff8df26 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateSpanTest.java @@ -0,0 +1,50 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.geometry.CoordinateSpan; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class CoordinateSpanTest { + + private static final double DELTA = 1e-15; + + @Test + public void testSanity() { + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); + assertNotNull("coordinateSpan should not be null", coordinateSpan); + } + + @Test + public void testLatitudeConstructor() { + double latitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(latitude, 0.0); + assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA); + } + + @Test + public void testLongitudeConstructor() { + double longitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, longitude); + assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA); + } + + @Test + public void testLatitudeMethod() { + double latitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); + coordinateSpan.setLatitudeSpan(latitude); + assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA); + } + + @Test + public void testLongitudeMethod() { + double longitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); + coordinateSpan.setLongitudeSpan(longitude); + assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java new file mode 100644 index 0000000000..71994ef64b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java @@ -0,0 +1,109 @@ +package com.mapbox.mapboxsdk.maps; + +import android.location.Location; + +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class LatLngTest { + + private static final double DELTA = 1e-15; + + @Test + public void testSanity() { + LatLng latLng = new LatLng(0.0, 0.0); + assertNotNull("latLng should not be null", latLng); + } + + @Test + public void 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 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); + } + + /* + * A sample test where Mockito is necessary + */ + + @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 [longitude=3.4, latitude=1.2, altitude=5.6]"); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java new file mode 100644 index 0000000000..92809fdde1 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -0,0 +1,235 @@ +package com.mapbox.mapboxsdk.maps; + +import android.util.Log; + +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.camera.CameraPosition; + +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.constants.Style; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.lang.reflect.Constructor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class MapboxMapTest { + + private MapboxMap mMapboxMap; + + @InjectMocks + MapView mMapView = mock(MapView.class); + + @Mock + MapboxMap.OnMarkerClickListener mOnMarkerClickListener; + + @Before + public void beforeTest() { + MockitoAnnotations.initMocks(this); + mMapboxMap = new MapboxMap(mMapView); + } + + @Test + public void testSanity() { + assertNotNull("mMapboxMap should not be null", mMapboxMap); + } + + @Test + public void testCompassEnabled() { + mMapboxMap.setCompassEnabled(true); + assertTrue("CompassEnabled should be true", mMapboxMap.isCompassEnabled()); + } + + @Test + public void testCompassDisabled() { + mMapboxMap.setCompassEnabled(false); + assertFalse("CompassbEnabled should be false", mMapboxMap.isCompassEnabled()); + } + + @Test + public void testScrollEnabled() { + mMapboxMap.setScrollEnabled(true); + assertTrue("ScrollEnabled should be true", mMapboxMap.isScrollEnabled()); + } + + @Test + public void testScrollDisabled() { + mMapboxMap.setScrollEnabled(false); + assertFalse("ScrollEnabled should be false", mMapboxMap.isScrollEnabled()); + } + + @Test + public void testRotateEnabled() { + mMapboxMap.setRotateEnabled(true); + assertTrue("RotateEnabled should be true", mMapboxMap.isRotateEnabled()); + } + + @Test + public void testRotateDisabled() { + mMapboxMap.setRotateEnabled(false); + assertFalse("RotateDisabled should be false", mMapboxMap.isRotateEnabled()); + } + + @Test + public void testZoomEnabled() { + mMapboxMap.setZoomEnabled(true); + assertTrue("ZoomEnabled should be true", mMapboxMap.isZoomEnabled()); + } + + @Test + public void testZoomDisabled() { + mMapboxMap.setZoomEnabled(false); + assertFalse("ZoomEnabled should be false", mMapboxMap.isZoomEnabled()); + } + + @Test + public void testZoomControlsEnabled() { + mMapboxMap.setZoomControlsEnabled(true); + assertTrue("ZoomControlsEnabled should be true", mMapboxMap.isZoomControlsEnabled()); + } + + @Test + public void testZoomControlsDisabled() { + mMapboxMap.setZoomControlsEnabled(false); + assertFalse("ZoomControlsEnabled should be false", mMapboxMap.isZoomControlsEnabled()); + } + + @Test + public void testTiltEnabled() { + mMapboxMap.setTiltEnabled(true); + assertTrue("TiltEnabled should be true", mMapboxMap.isTiltEnabled()); + } + + @Test + public void testTiltDisabled() { + mMapboxMap.setTiltEnabled(false); + assertFalse("TiltEnabled should be false", mMapboxMap.isTiltEnabled()); + } + + @Test + public void testConcurrentInfoWindowEnabled() { + mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true); + assertTrue("ConcurrentWindows should be true", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); + } + + @Test + public void testConcurrentInfoWindowDisabled() { + mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false); + assertFalse("ConcurrentWindows should be false", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); + } + + @Test + public void testMyLocationEnabled() { + try { + mMapboxMap.setMyLocationEnabled(true); + assertTrue("MyLocationEnabled should be true", mMapboxMap.isMyLocationEnabled()); + } catch (SecurityException e) { + assertTrue(false); + } + } + + @Test + public void testMyLocationDisabled() { + try { + mMapboxMap.setMyLocationEnabled(false); + assertFalse("MyLocationEnabled should be false", mMapboxMap.isMyLocationEnabled()); + } catch (SecurityException e) { + assertTrue(false); + } + } + + @Test + public void testStyleUrl() { + mMapboxMap.setStyleUrl("somestyle"); + assertEquals("StyleUrl should be same", "somestyle", mMapboxMap.getStyleUrl()); + } + + @Test + public void testStyle() { + mMapboxMap.setStyle(Style.MAPBOX_STREETS); + assertEquals("Style should be same", Style.MAPBOX_STREETS, mMapboxMap.getStyleUrl()); + } + + @Test + public void testCameraPosition() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.setCameraPosition(position); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testMoveCamera() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position)); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testAnimateCamera() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position)); + assertEquals("CameraPosition should be same", position , mMapboxMap.getCameraPosition()); + } + + @Test + public void testAnimateCameraWithCallbackParameter() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), null); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testAnimateCameraWithDurationParameter() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0); + assertEquals("CameraPosition should be same",position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testAnimateCameraWithDurationAndCallbackParameter() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0, null); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testEaseCamera() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testEaseCameraWithCallbackParameter() { + CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); + mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000, null); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); + } + + @Test + public void testOnMarkerClick() { + mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); + Marker marker = new MarkerOptions().getMarker(); + when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); + mMapboxMap.selectMarker(marker); + verify(mOnMarkerClickListener, times(1)).onMarkerClick(marker); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MarkerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MarkerTest.java new file mode 100644 index 0000000000..efe94e5396 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MarkerTest.java @@ -0,0 +1,76 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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(); + assertNotNull("marker should not be null", markerOptions.getMarker()); + } + + @Test + public void testPosition() { + Marker marker = new MarkerOptions().position(new LatLng(10, 12)).getMarker(); + assertEquals(marker.getPosition(), new LatLng(10, 12)); + } + + @Test + public void testTitle() { + Marker marker = new MarkerOptions().title("Mapbox").getMarker(); + assertEquals(marker.getTitle(), "Mapbox"); + } + + @Test + public void testSnippet() { + Marker marker = new MarkerOptions().snippet("Mapbox").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.getTitle(), "title"); + assertEquals(marker.getSnippet(), "snippet"); + assertEquals(marker.getPosition(), new LatLng(10, 12)); + } + + @Test + public void testIcon() { + // find a way to test Icon + } + + @Test + public void testHashCode() { + Marker marker = new MarkerOptions().position(new LatLng(10, 12)).getMarker(); + assertEquals("hash code should match", marker.hashCode(), -1946419200); + } + + @Test + public void testEquality() { + 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 testToString() { + Marker marker = new MarkerOptions().position(new LatLng(0, 0)).getMarker(); + assertEquals(marker.toString(), "Marker [position[" + "LatLng [longitude=0.0, latitude=0.0, altitude=0.0]" + "]]"); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolygonTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolygonTest.java new file mode 100644 index 0000000000..281277692f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolygonTest.java @@ -0,0 +1,79 @@ +package com.mapbox.mapboxsdk.maps; + +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; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class PolygonTest { + + @Test + public void testSanity() { + PolygonOptions polygonOptions = new PolygonOptions(); + assertNotNull("polygonOptions should not be null", polygonOptions); + } + + @Test + public void testPolygon() { + Polygon polygon = new PolygonOptions().getPolygon(); + assertNotNull("polyline should not be null", polygon); + } + + @Test + public void testAlpha() { + Polygon polygon = new PolygonOptions().alpha(0.5f).getPolygon(); + assertEquals(0.5f, polygon.getAlpha(), 0.0f); + } + + @Test + public void testStrokeColor() { + Polygon polygon = new PolygonOptions().strokeColor(1).getPolygon(); + assertEquals(1, polygon.getStrokeColor()); + } + + @Test + public void testFillColor() { + Polygon polygon = new PolygonOptions().fillColor(1).getPolygon(); + assertEquals(1, polygon.getFillColor()); + } + + @Test + public void testLatLng() { + Polygon polygon = new PolygonOptions().add(new LatLng(0, 0)).getPolygon(); + assertNotNull("points should not be null", polygon.getPoints()); + assertEquals(new LatLng(0, 0), polygon.getPoints().get(0)); + } + + @Test + public void testAddAllLatLng() { + List<LatLng> coordinates = new ArrayList<>(); + coordinates.add(new LatLng(0, 0)); + Polygon polygon = new PolygonOptions().addAll(coordinates).getPolygon(); + assertNotNull(polygon.getPoints()); + assertEquals(new LatLng(0, 0), polygon.getPoints().get(0)); + } + + @Test + public void testBuilder() { + PolylineOptions polylineOptions = new PolylineOptions(); + polylineOptions.width(1.0f); + polylineOptions.color(2); + polylineOptions.add(new LatLng(0, 0)); + + Polyline polyline = polylineOptions.getPolyline(); + assertEquals(1.0f, polyline.getWidth(), 0); + assertEquals(2, polyline.getColor()); + assertNotNull("Points should not be null", polyline.getPoints()); + assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolylineTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolylineTest.java new file mode 100644 index 0000000000..78af961e02 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolylineTest.java @@ -0,0 +1,77 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.annotations.Polyline; +import com.mapbox.mapboxsdk.annotations.PolylineOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class PolylineTest { + + @Test + public void testSanity() { + PolylineOptions polylineOptions = new PolylineOptions(); + assertNotNull("polylineOptions should not be null", polylineOptions); + } + + @Test + public void testPolyline() { + Polyline polyline = new PolylineOptions().getPolyline(); + assertNotNull("polyline should not be null", polyline); + } + + @Test + public void testAlpha() { + Polyline polyline = new PolylineOptions().alpha(0.2f).getPolyline(); + assertEquals(0.2f, polyline.getAlpha(), 0.0f); + } + + @Test + public void testWidth() { + Polyline polyline = new PolylineOptions().width(1).getPolyline(); + assertEquals(1.0f, polyline.getWidth(), 0); + } + + @Test + public void testColor() { + Polyline polyline = new PolylineOptions().color(1).getPolyline(); + assertEquals(1, polyline.getColor()); + } + + @Test + public void testAddLatLng() { + Polyline polyline = new PolylineOptions().add(new LatLng(0, 0)).getPolyline(); + assertNotNull("Points should not be null", polyline.getPoints()); + assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); + } + + @Test + public void testAddAllLatLng() { + List<LatLng> coordinates = new ArrayList<>(); + coordinates.add(new LatLng(0, 0)); + Polyline polyline = new PolylineOptions().addAll(coordinates).getPolyline(); + assertNotNull(polyline.getPoints()); + assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); + } + + @Test + public void testBuilder() { + PolylineOptions polylineOptions = new PolylineOptions(); + polylineOptions.width(1.0f); + polylineOptions.color(2); + polylineOptions.add(new LatLng(0, 0)); + + Polyline polyline = polylineOptions.getPolyline(); + assertEquals(1.0f, polyline.getWidth(), 0); + assertEquals(2, polyline.getColor()); + assertNotNull("Points should not be null", polyline.getPoints()); + assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectedMetersTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectedMetersTest.java new file mode 100644 index 0000000000..50485c4dc5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectedMetersTest.java @@ -0,0 +1,17 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.geometry.ProjectedMeters; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class ProjectedMetersTest { + + @Test + public void testSanity() { + ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0); + assertNotNull("projectedMeters should not be null", projectedMeters); + } + +} |