diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox')
11 files changed, 307 insertions, 464 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java index d9e3ae427d..6ee5c157b9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java @@ -5,7 +5,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; -import com.mapbox.android.core.location.LocationEngine; import org.junit.Before; import org.junit.Test; @@ -25,13 +24,11 @@ public class MapboxTest { private Context context; private Context appContext; - private LocationEngine locationSource; @Before public void before() { context = mock(Context.class); appContext = mock(Context.class); - locationSource = mock(LocationEngine.class); when(context.getApplicationContext()).thenReturn(appContext); } @@ -83,7 +80,7 @@ public class MapboxTest { } private void injectMapboxSingleton(String accessToken) { - Mapbox mapbox = new Mapbox(appContext, accessToken, locationSource); + Mapbox mapbox = new Mapbox(appContext, accessToken); try { Field field = Mapbox.class.getDeclaredField("INSTANCE"); field.setAccessible(true); diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java index f03bbdb11c..e072f07fb9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java @@ -111,6 +111,14 @@ public class LatLngBoundsTest { } @Test + public void zeroLongitudeSpan() { + latLngBounds = LatLngBounds.from(10, 10, -10, 10); + LatLngSpan latLngSpan = latLngBounds.getSpan(); + assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 0), + latLngSpan); + } + + @Test public void nearDateLineCenter1() { latLngBounds = LatLngBounds.from(10, -175, -10, 165); LatLng center = latLngBounds.getCenter(); @@ -145,6 +153,19 @@ public class LatLngBoundsTest { assertEquals("Center should match", new LatLng(0, 90), center); } + @Test + public void centerForBoundsWithSameLongitude() { + latLngBounds = LatLngBounds.from(10, 10, -10, 10); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(0, 10), center); + } + + @Test + public void centerForBoundsWithSameLatitude() { + latLngBounds = LatLngBounds.from(10, 10, 10, -10); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(10, 0), center); + } @Test public void center() { @@ -197,6 +218,27 @@ public class LatLngBoundsTest { } @Test + public void includesOrderDoesNotMatter() { + LatLngBounds sameLongitudeFirst = new LatLngBounds.Builder() + .include(new LatLng(50, 10)) // southWest + .include(new LatLng(60, 10)) + .include(new LatLng(60, 20)) // northEast + .include(new LatLng(50, 20)) + .include(new LatLng(50, 10)) // southWest again + .build(); + + LatLngBounds sameLatitudeFirst = new LatLngBounds.Builder() + .include(new LatLng(50, 20)) + .include(new LatLng(50, 10)) // southWest + .include(new LatLng(60, 10)) + .include(new LatLng(60, 20)) // northEast + .include(new LatLng(50, 20)) + .build(); + + assertEquals(sameLatitudeFirst, sameLongitudeFirst); + } + + @Test public void includesOverDateline1() { LatLngBounds latLngBounds = new LatLngBounds.Builder() @@ -338,6 +380,27 @@ public class LatLngBoundsTest { } @Test + public void unionOverDateLine() { + LatLngBounds latLngBounds1 = new LatLngBounds.Builder() + .include(new LatLng(10, 170)) + .include(new LatLng(0, 160)) + .build(); + + LatLngBounds latLngBounds2 = new LatLngBounds.Builder() + .include(new LatLng(0, -170)) + .include(new LatLng(-10, -160)) + .build(); + + assertEquals("outer union should match", + latLngBounds1.union(latLngBounds2), + new LatLngBounds.Builder() + .include(new LatLng(10, 160)) + .include(new LatLng(-10, -160)) + .build()); + } + + + @Test public void northWest() { double minLat = 5; double minLon = 6; @@ -496,4 +559,11 @@ public class LatLngBoundsTest { exception.expectMessage("longitude must not be infinite"); LatLngBounds.from(20, 20, 0, Double.POSITIVE_INFINITY); } + + @Test + public void testConstructorCheckLatSouthGreaterLatNorth() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("LatSouth cannot be less than latNorth"); + LatLngBounds.from(0, 20, 20, 0); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java index 65bdff41ab..9dd0ca9285 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java @@ -119,13 +119,6 @@ public class MapboxMapOptionsTest { } @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()); @@ -176,18 +169,6 @@ public class MapboxMapOptionsTest { } @Test - public void testMyLocationForegroundTint() { - assertEquals(Color.BLUE, new MapboxMapOptions() - .myLocationForegroundTintColor(Color.BLUE).getMyLocationForegroundTintColor()); - } - - @Test - public void testMyLocationBackgroundTint() { - assertEquals(Color.BLUE, new MapboxMapOptions() - .myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor()); - } - - @Test public void testPrefetchesTiles() { // Default value assertTrue(new MapboxMapOptions().getPrefetchesTiles()); diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java index d61947f00e..9a323a1d75 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.maps; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; import org.junit.After; import org.junit.Before; @@ -20,8 +19,6 @@ public class MapboxMapTest { mapboxMap = new MapboxMap(mock(NativeMapView.class), mock(Transform.class), mock(UiSettings.class), - mock(TrackingSettings.class), - mock(MyLocationViewSettings.class), mock(Projection.class), mock(MapboxMap.OnGesturesManagerInteractionListener.class), mock(AnnotationManager.class), diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java deleted file mode 100644 index de5f364a5b..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.Manifest; -import android.content.Context; -import android.content.pm.PackageManager; -import android.graphics.PointF; - -import com.mapbox.mapboxsdk.constants.MyLocationTracking; -import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class TrackingSettingsTest { - - @InjectMocks - MyLocationView myLocationView = mock(MyLocationView.class); - - @InjectMocks - UiSettings uiSettings = mock(UiSettings.class); - - @InjectMocks - FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); - - @InjectMocks - TrackingSettings.CameraZoomInvalidator zoomInvalidator = mock(TrackingSettings.CameraZoomInvalidator.class); - - private TrackingSettings trackingSettings; - - @Before - public void beforeTest() { - trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointChangeListener, zoomInvalidator); - } - - @Test - public void testSanity() { - assertNotNull("trackingsettings should not be null", trackingSettings); - } - - @Test - public void testDismissTrackingModesOnGesture() { - trackingSettings.setDismissAllTrackingOnGesture(false); - assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isAllDismissTrackingOnGesture()); - } - - @Test - public void testValidateGesturesForTrackingModes() { - trackingSettings.setDismissAllTrackingOnGesture(false); - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isAllDismissTrackingOnGesture()); - } - - @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()); - } - - @Test - public void testCameraZoomTo2forTracking() { - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - verify(zoomInvalidator, atLeast(1)).zoomTo(2.0); - } - - @Test - public void testFocalPointChangeForTracking() { - final float centerX = 32.3f; - final float centerY = 46.3f; - final PointF pointF = new PointF(centerX, centerY); - when(myLocationView.getCenter()).thenReturn(pointF); - - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - verify(focalPointChangeListener, atLeast(1)).onFocalPointChanged(pointF); - } - - @Test - public void testFocalPointChangeForNonTracking() { - trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE); - verify(focalPointChangeListener, atLeast(1)).onFocalPointChanged(null); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java index fbe00b4dce..cfce56e6e9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java @@ -181,13 +181,6 @@ public class UiSettingsTest { } @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()); @@ -196,14 +189,6 @@ public class UiSettingsTest { } @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()); @@ -216,13 +201,6 @@ public class UiSettingsTest { } @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()); @@ -231,14 +209,6 @@ public class UiSettingsTest { } @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()); @@ -251,13 +221,6 @@ public class UiSettingsTest { } @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()); @@ -266,14 +229,6 @@ public class UiSettingsTest { } @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()); @@ -298,13 +253,6 @@ public class UiSettingsTest { } @Test - public void testDoubleTapGestureChange() { - assertEquals("Default state should be true", true, uiSettings.isDoubleTapGestureChangeAllowed()); - uiSettings.setDoubleTapGestureChangeAllowed(false); - assertEquals("State should have been changed", false, uiSettings.isDoubleTapGestureChangeAllowed()); - } - - @Test public void testDoubleTapGestureChangeAllowed() { uiSettings.setDoubleTapGesturesEnabled(false); assertEquals("DoubleTap gesture should be false", false, uiSettings.isDoubleTapGesturesEnabled()); @@ -313,14 +261,6 @@ public class UiSettingsTest { } @Test - public void testDoubleTapGestureChangeDisallowed() { - assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled()); - uiSettings.setDoubleTapGestureChangeAllowed(false); - uiSettings.setDoubleTapGesturesEnabled(false); - assertEquals("DoubleTap gesture change should be ignored", true, uiSettings.isDoubleTapGesturesEnabled()); - } - - @Test public void testScrollGesturesEnabled() { uiSettings.setScrollGesturesEnabled(true); assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled()); @@ -333,13 +273,6 @@ public class UiSettingsTest { } @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()); @@ -348,11 +281,82 @@ public class UiSettingsTest { } @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()); + public void testScaleVelocityAnimationEnabled() { + uiSettings.setScaleVelocityAnimationEnabled(true); + assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled()); + } + + @Test + public void testScaleVelocityAnimationDisabled() { + uiSettings.setScaleVelocityAnimationEnabled(false); + assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled()); + } + + @Test + public void testRotateVelocityAnimationEnabled() { + uiSettings.setRotateVelocityAnimationEnabled(true); + assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled()); + } + + @Test + public void testRotateVelocityAnimationDisabled() { + uiSettings.setRotateVelocityAnimationEnabled(false); + assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled()); + } + + @Test + public void testFlingVelocityAnimationEnabled() { + uiSettings.setFlingVelocityAnimationEnabled(true); + assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testFlingVelocityAnimationDisabled() { + uiSettings.setFlingVelocityAnimationEnabled(false); + assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testAllVelocityAnimationsEnabled() { + uiSettings.setAllVelocityAnimationsEnabled(true); + assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled()); + assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled()); + assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testAllVelocityAnimationsDisabled() { + uiSettings.setAllVelocityAnimationsEnabled(false); + assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled()); + assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled()); + assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testIncreaseRotateThresholdWhenScalingEnabled() { + uiSettings.setIncreaseRotateThresholdWhenScaling(true); + assertEquals("Rotate threshold increase should be enabled", true, + uiSettings.isIncreaseRotateThresholdWhenScaling()); + } + + @Test + public void testIncreaseRotateThresholdWhenScalingDisabled() { + uiSettings.setIncreaseRotateThresholdWhenScaling(false); + assertEquals("Rotate threshold increase should be disabled", false, + uiSettings.isIncreaseRotateThresholdWhenScaling()); + } + + @Test + public void testIncreaseScaleThresholdWhenRotatingEnabled() { + uiSettings.setIncreaseScaleThresholdWhenRotating(true); + assertEquals("Scale threshold increase should be enabled", true, uiSettings.isIncreaseScaleThresholdWhenRotating()); + } + + @Test + public void testIncreaseScaleThresholdWhenRotatingDisabled() { + uiSettings.setIncreaseScaleThresholdWhenRotating(false); + assertEquals("Scale threshold increase should be disabled", false, + uiSettings.isIncreaseScaleThresholdWhenRotating()); } @Test diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java deleted file mode 100644 index c9ce19dc85..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.mapbox.mapboxsdk.maps.widgets; - -import android.graphics.Color; -import android.graphics.drawable.Drawable; - -import com.mapbox.mapboxsdk.maps.FocalPointChangeListener; -import com.mapbox.mapboxsdk.maps.Projection; -import com.mapbox.mapboxsdk.maps.TrackingSettings; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; - -import java.util.Arrays; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static org.mockito.Mockito.mock; -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()); - } -} - diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java index c0b7832727..45833e8556 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -2,12 +2,11 @@ package com.mapbox.mapboxsdk.style.expressions; import android.graphics.Color; -import com.mapbox.mapboxsdk.style.layers.PropertyFactory; - import org.junit.Test; import java.util.Arrays; +import static com.mapbox.mapboxsdk.style.expressions.Expression.abs; import static com.mapbox.mapboxsdk.style.expressions.Expression.acos; import static com.mapbox.mapboxsdk.style.expressions.Expression.all; import static com.mapbox.mapboxsdk.style.expressions.Expression.any; @@ -16,6 +15,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.asin; import static com.mapbox.mapboxsdk.style.expressions.Expression.at; import static com.mapbox.mapboxsdk.style.expressions.Expression.atan; import static com.mapbox.mapboxsdk.style.expressions.Expression.bool; +import static com.mapbox.mapboxsdk.style.expressions.Expression.ceil; import static com.mapbox.mapboxsdk.style.expressions.Expression.coalesce; import static com.mapbox.mapboxsdk.style.expressions.Expression.color; import static com.mapbox.mapboxsdk.style.expressions.Expression.concat; @@ -26,6 +26,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase; import static com.mapbox.mapboxsdk.style.expressions.Expression.e; import static com.mapbox.mapboxsdk.style.expressions.Expression.eq; import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.floor; import static com.mapbox.mapboxsdk.style.expressions.Expression.geometryType; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.expressions.Expression.gt; @@ -58,6 +59,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.product; import static com.mapbox.mapboxsdk.style.expressions.Expression.properties; import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; +import static com.mapbox.mapboxsdk.style.expressions.Expression.round; import static com.mapbox.mapboxsdk.style.expressions.Expression.sin; import static com.mapbox.mapboxsdk.style.expressions.Expression.sqrt; import static com.mapbox.mapboxsdk.style.expressions.Expression.step; @@ -75,6 +77,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.typeOf; import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase; import static com.mapbox.mapboxsdk.style.expressions.Expression.var; import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; @@ -113,7 +116,7 @@ public class ExpressionTest { @Test public void testToRgba() throws Exception { - Object[] expected = new Object[] {"to-rgba", PropertyFactory.colorToRgbaString(Color.RED)}; + Object[] expected = new Object[] {"to-rgba", new Object[] {"to-color", "rgba(255, 0, 0, 255)"}}; Object[] actual = toRgba(color(Color.RED)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -128,7 +131,7 @@ public class ExpressionTest { @Test public void testEqLiteral() throws Exception { Object[] expected = new Object[] {"==", 1, 1}; - Object[] actual = eq(1, 1).toArray(); + Object[] actual = eq(literal(1), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -142,7 +145,7 @@ public class ExpressionTest { @Test public void testNeqLiteral() throws Exception { Object[] expected = new Object[] {"!=", 0, 1}; - Object[] actual = neq(0, 1).toArray(); + Object[] actual = neq(literal(0), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -156,7 +159,7 @@ public class ExpressionTest { @Test public void testGtLiteral() throws Exception { Object[] expected = new Object[] {">", 0, 1}; - Object[] actual = gt(0, 1).toArray(); + Object[] actual = gt(literal(0), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -170,7 +173,7 @@ public class ExpressionTest { @Test public void testLtLiteral() throws Exception { Object[] expected = new Object[] {"<", 1, 0}; - Object[] actual = lt(1, 0).toArray(); + Object[] actual = lt(literal(1), 0).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -184,7 +187,7 @@ public class ExpressionTest { @Test public void testGteLiteral() throws Exception { Object[] expected = new Object[] {">=", 1, 1}; - Object[] actual = gte(1, 1).toArray(); + Object[] actual = gte(literal(1), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -198,7 +201,7 @@ public class ExpressionTest { @Test public void testLteLiteral() throws Exception { Object[] expected = new Object[] {"<=", 1, 1}; - Object[] actual = lte(1, 1).toArray(); + Object[] actual = lte(literal(1), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -264,12 +267,46 @@ public class ExpressionTest { @Test public void testMatch() throws Exception { - Object[] labelZero = new Object[] {"a", "output"}; - Object[] labelOne = new Object[] {"b", "output2"}; - Object[] labelTwo = new Object[] {"c", "output3"}; + String input = "input"; + String[] labels = new String[] {"a", "b", "c"}; + String[] outputs = new String[] {"1", "2", "3"}; + String defaultOutput = "0"; + + Object[] expected = new Object[] {"match", input, + labels[0], outputs[0], + labels[1], outputs[1], + labels[2], outputs[2], + defaultOutput}; + + Object[] actual = match(literal(input), + literal(labels[0]), literal(outputs[0]), + literal(labels[1]), literal(outputs[1]), + literal(labels[2]), literal(outputs[2]), + literal(defaultOutput) + ).toArray(); + + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMatchWithStops() throws Exception { + String input = "input"; + String[] labels = new String[] {"a", "b", "c"}; + String[] outputs = new String[] {"1", "2", "3"}; + String defaultOutput = "0"; + + Object[] expected = new Object[] {"match", input, + labels[0], outputs[0], + labels[1], outputs[1], + labels[2], outputs[2], + defaultOutput}; + + Object[] actual = match(literal(input), literal(defaultOutput), + stop(labels[0], outputs[0]), + stop(labels[1], outputs[1]), + stop(labels[2], outputs[2])) + .toArray(); - Object[] expected = new Object[] {"match", labelZero, labelOne, labelTwo}; - Object[] actual = match(literal(labelZero), literal(labelOne), literal(labelTwo)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -331,14 +368,14 @@ public class ExpressionTest { @Test public void testAt() throws Exception { - Object[] expected = new Object[] {"at", 3, new Object[] {"one", "two"}}; + Object[] expected = new Object[] {"at", 3, new Object[] {"literal", new Object[] {"one", "two"}}}; Object[] actual = at(literal(3), literal(new Object[] {"one", "two"})).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAtLiteral() throws Exception { - Object[] expected = new Object[] {"at", 3, new Object[] {"one", "two"}}; + Object[] expected = new Object[] {"at", 3, new Object[] {"literal", new Object[] {"one", "two"}}}; Object[] actual = at(3, literal(new Object[] {"one", "two"})).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -921,12 +958,13 @@ public class ExpressionTest { @Test public void testLinear() throws Exception { - Object[] stopZero = new Object[] {0, 1}; - Object[] stopOne = new Object[] {1, 2}; - Object[] stopTwo = new Object[] {2, 3}; - Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12, stopZero, stopOne, stopTwo}; - Object[] actual = interpolate(linear(), literal(12), - literal(stopZero), literal(stopOne), literal(stopTwo)).toArray(); + Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12, 0, 1, 1, 2, 2, 3}; + Object[] actual = interpolate( + linear(), literal(12), + literal(0), literal(1), + literal(1), literal(2), + literal(2), literal(3)) + .toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -1030,4 +1068,101 @@ public class ExpressionTest { get(literal("x")), literal(0), literal(100), literal(100), literal(200)).toString(); assertEquals("toString should match", expected, actual); } + + @Test + public void testLiteralArray() throws Exception { + Object[] array = new Object[] {1, "text"}; + Object[] expected = new Object[] {"literal", array}; + Object[] actual = literal(array).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLiteralArrayString() throws Exception { + Object[] array = new Object[] {1, "text"}; + String expected = "[\"literal\"], [1, \"text\"]]"; + String actual = literal(array).toString(); + assertEquals("literal array should match", expected, actual); + } + + @Test + public void testLiteralPrimitiveArrayConversion() throws Exception { + float[] array = new float[] {0.2f, 0.5f}; + Object[] expected = new Object[] {"literal", new Object[] {0.2f, 0.5f}}; + Object[] actual = literal(array).toArray(); + assertEquals("primitive array should be converted", expected, actual); + } + + @Test + public void testColorConversion() { + Expression greenColor = color(0xFF00FF00); + Object[] expected = new Object[] {"to-color", "rgba(0, 255, 0, 255)"}; + assertTrue("expression should match", Arrays.deepEquals(expected, greenColor.toArray())); + } + + @Test(expected = IllegalArgumentException.class) + public void testThrowIllegalArgumentExceptionForPropertyValueLiteral() { + Expression expression = interpolate(exponential(1f), zoom(), + stop(17f, lineOpacity(1f)), + stop(16.5f, lineOpacity(0.5f)), + stop(16f, lineOpacity(0f)) + ); + expression.toArray(); + } + + @Test + public void testRound() { + Object[] expected = new Object[] {"round", 2.2f}; + Object[] actual = round(2.2f).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testRoundLiteral() { + Object[] expected = new Object[] {"round", 2.2f}; + Object[] actual = round(literal(2.2f)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAbs() { + Object[] expected = new Object[] {"abs", -2.2f}; + Object[] actual = abs(-2.2f).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAbsLiteral() { + Object[] expected = new Object[] {"abs", -2.2f}; + Object[] actual = abs(literal(-2.2f)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCeil() { + Object[] expected = new Object[] {"ceil", 2.2f}; + Object[] actual = ceil(2.2f).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCeilLiteral() { + Object[] expected = new Object[] {"ceil", 2.2f}; + Object[] actual = ceil(literal(2.2f)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testFloor() { + Object[] expected = new Object[] {"floor", 2.2f}; + Object[] actual = floor(2.2f).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testFloorLiteral() { + Object[] expected = new Object[] {"floor", 2.2f}; + Object[] actual = floor(literal(2.2f)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java deleted file mode 100644 index 933bf05b39..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/layers/FilterTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.mapbox.mapboxsdk.style.layers; - -import org.junit.Test; - -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"}); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java deleted file mode 100644 index bac1154d62..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.mapbox.mapboxsdk.style.layers; - -import com.mapbox.mapboxsdk.style.functions.Function; - -import org.junit.Test; - -import static com.mapbox.mapboxsdk.style.functions.Function.zoom; -import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; -import static com.mapbox.mapboxsdk.style.functions.stops.Stops.interval; -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<Float, Float> zoomF = zoom(interval( - 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") - ); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java index 94a6dc2194..519124e1eb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/telemetry/HttpTransportTest.java @@ -1,8 +1,8 @@ package com.mapbox.mapboxsdk.telemetry; -import org.junit.Test; +import com.mapbox.android.telemetry.TelemetryUtils; -import okhttp3.internal.Util; +import org.junit.Test; import static junit.framework.Assert.assertEquals; @@ -15,6 +15,6 @@ public class HttpTransportTest { final String asciiVersion = "Sveriges Fj?ll/1.0/1 MapboxEventsAndroid/4.0.0-SNAPSHOT"; assertEquals("asciiVersion and swedishUserAgent should match", asciiVersion, - Util.toHumanReadableAscii(swedishUserAgent)); + TelemetryUtils.toHumanReadableAscii(swedishUserAgent)); } } |