diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp')
24 files changed, 5603 insertions, 4125 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java index 5ead54eb7b..d4b0dbad72 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java @@ -22,6 +22,7 @@ import com.mapbox.mapboxsdk.testapp.utils.ViewUtils; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -44,6 +45,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToCameraPositionTarget() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -66,6 +68,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToCameraPositionTargetZoom() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -114,6 +117,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToBounds() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -142,6 +146,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToMoveBy() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -161,6 +166,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToZoomIn() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -175,6 +181,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToZoomOut() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -190,6 +197,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToZoomBy() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -205,6 +213,7 @@ public class CameraAnimateTest { } @Test + @Ignore public void testAnimateToZoomTo() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java index 22af72cebb..83e7d6084c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java @@ -22,6 +22,7 @@ import com.mapbox.mapboxsdk.testapp.utils.ViewUtils; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -44,6 +45,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToCameraPositionTarget() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -66,6 +68,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToCameraPositionTargetZoom() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -84,6 +87,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToCameraPosition() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -114,6 +118,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToBounds() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -142,6 +147,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToMoveBy() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -161,6 +167,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToZoomIn() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -175,6 +182,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToZoomOut() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -189,6 +197,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToZoomBy() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -204,6 +213,7 @@ public class CameraEaseTest { } @Test + @Ignore public void testEaseToZoomTo() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java index 3ca61f7e9d..2d01347d22 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java @@ -19,6 +19,7 @@ import com.mapbox.mapboxsdk.testapp.utils.ViewUtils; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -44,6 +45,7 @@ public class CameraInternalApiTest { } @Test + @Ignore public void testBearing() { ViewUtils.checkViewIsDisplayed(R.id.mapView); EspressoTestActivity activity = rule.getActivity(); @@ -59,6 +61,7 @@ public class CameraInternalApiTest { } @Test + @Ignore public void testTilt() { ViewUtils.checkViewIsDisplayed(R.id.mapView); EspressoTestActivity activity = rule.getActivity(); @@ -74,6 +77,7 @@ public class CameraInternalApiTest { } @Test + @Ignore public void testLatLng() { ViewUtils.checkViewIsDisplayed(R.id.mapView); EspressoTestActivity activity = rule.getActivity(); @@ -166,4 +170,4 @@ public class CameraInternalApiTest { MapViewUtils.setLatLng(mapboxMap, new LatLng(1.1, 2.2)); } } -}
\ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraMoveTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraMoveTest.java index b3a7fe0d11..becf9db7cb 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraMoveTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraMoveTest.java @@ -22,6 +22,7 @@ import com.mapbox.mapboxsdk.testapp.utils.ViewUtils; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -44,6 +45,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToCameraPositionTarget() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -66,6 +68,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToCameraPositionTargetZoom() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -84,6 +87,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToCameraPosition() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -114,6 +118,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToBounds() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -142,6 +147,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToMoveBy() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -161,6 +167,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToZoomIn() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -175,6 +182,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToZoomOut() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -190,6 +198,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToZoomBy() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -205,6 +214,7 @@ public class CameraMoveTest { } @Test + @Ignore public void testMoveToZoomTo() { ViewUtils.checkViewIsDisplayed(R.id.mapView); final MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesBoxCountTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesBoxCountTest.java index b4be73be7a..f49296a164 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesBoxCountTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesBoxCountTest.java @@ -58,4 +58,4 @@ public class QueryRenderedFeaturesBoxCountTest { Espresso.unregisterIdlingResources(idlingResource); } -}
\ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesHighlightTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesHighlightTest.java index b8cd46e612..0333aba191 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesHighlightTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesHighlightTest.java @@ -78,4 +78,4 @@ public class QueryRenderedFeaturesHighlightTest { }, Press.FINGER); } -}
\ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesPropertiesTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesPropertiesTest.java index 3b86397603..01eb9c8b44 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesPropertiesTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/feature/QueryRenderedFeaturesPropertiesTest.java @@ -75,4 +75,4 @@ public class QueryRenderedFeaturesPropertiesTest { }, Press.FINGER); } -}
\ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/maps/widgets/MyLocationViewTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/maps/widgets/MyLocationViewTest.java index ac10d11922..c8a983351b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/maps/widgets/MyLocationViewTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/maps/widgets/MyLocationViewTest.java @@ -16,7 +16,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.location.LocationServices; +import com.mapbox.mapboxsdk.location.LocationSource; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; import com.mapbox.mapboxsdk.testapp.R; @@ -123,7 +123,7 @@ public class MyLocationViewTest { mapboxMap.moveCamera( CameraUpdateFactory.newCameraPosition( new CameraPosition.Builder() - .target(new LatLng(LocationServices.getLocationServices(view.getContext()).getLastLocation())) + .target(new LatLng(LocationSource.getLocationEngine(view.getContext()).getLastLocation())) .build() ) ); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java deleted file mode 100644 index 68ed5cb05d..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for BackgroundLayer - */ -@RunWith(AndroidJUnit4.class) -public class BackgroundLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private BackgroundLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("visibility"); - assertNotNull(layer); - - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testBackgroundColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testBackgroundColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(backgroundColor(Color.RED)); - assertEquals(layer.getBackgroundColorAsInt(), Color.RED); - } - - @Test - public void testBackgroundPattern() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-pattern"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(backgroundPattern("pedestrian-polygon")); - assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon"); - } - - @Test - public void testBackgroundOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(backgroundOpacity(0.3f)); - assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java index ab53ae0487..510f477bce 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,16 +29,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for BackgroundLayer @@ -48,91 +55,147 @@ public class BackgroundLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); + mapboxMap = rule.getActivity().getMapboxMap(); + + Timber.i("Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); } @Test public void testSetVisibility() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("visibility"); + Timber.i("Visibility"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); - //Set + // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } @Test - public void testBackgroundColor() { + public void testBackgroundColorAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); Timber.i("background-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testBackgroundColorAsInt() { + public void testBackgroundColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("background-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + backgroundColor( + zoom( + exponential( + stop(2, backgroundColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getBackgroundColor()); + assertNotNull(layer.getBackgroundColor().getFunction()); + assertEquals(CameraFunction.class, layer.getBackgroundColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getBackgroundColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).size()); + } - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void testBackgroundColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("background-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(backgroundColor(Color.RED)); assertEquals(layer.getBackgroundColorAsInt(), Color.RED); } @Test - public void testBackgroundPattern() { + public void testBackgroundPatternAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); Timber.i("background-pattern"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(backgroundPattern("pedestrian-polygon")); assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon"); } @Test - public void testBackgroundOpacity() { + public void testBackgroundPatternAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("background-pattern"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + backgroundPattern( + zoom( + interval( + stop(2, backgroundPattern("pedestrian-polygon")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getBackgroundPattern()); + assertNotNull(layer.getBackgroundPattern().getFunction()); + assertEquals(CameraFunction.class, layer.getBackgroundPattern().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getBackgroundPattern().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getBackgroundPattern().getFunction().getStops()).size()); + } - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void testBackgroundOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("background-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(backgroundOpacity(0.3f)); assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); } + @Test + public void testBackgroundOpacityAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("background-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + backgroundOpacity( + zoom( + exponential( + stop(2, backgroundOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getBackgroundOpacity()); + assertNotNull(layer.getBackgroundOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getBackgroundOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getBackgroundOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java deleted file mode 100644 index 58fda51f07..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.CircleLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_PITCH_SCALE_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circlePitchScale; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for CircleLayer - */ -@RunWith(AndroidJUnit4.class) -public class CircleLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private CircleLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testCircleRadius() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-radius"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleRadius(0.3f)); - assertEquals((Float) layer.getCircleRadius().getValue(), (Float) 0.3f); - } - - @Test - public void testCircleColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getCircleColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testCircleColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleColor(Color.RED)); - assertEquals(layer.getCircleColorAsInt(), Color.RED); - } - - @Test - public void testCircleBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-blur"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleBlur(0.3f)); - assertEquals((Float) layer.getCircleBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testCircleOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleOpacity(0.3f)); - assertEquals((Float) layer.getCircleOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testCircleTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-translate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testCircleTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-translate-anchor"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getCircleTranslateAnchor().getValue(), (String) CIRCLE_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testCirclePitchScale() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-pitch-scale"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP)); - assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java index 782598a0b2..c48a6f1d68 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.CircleLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,25 +29,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_PITCH_SCALE_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circlePitchScale; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for CircleLayer @@ -57,12 +55,6 @@ public class CircleLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -70,284 +62,1087 @@ public class CircleLayerTest extends BaseStyleTest { layer = new CircleLayer("my-layer", "composite"); layer.setSourceLayer("composite"); mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference + // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); - //Set + // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } @Test - public void testCircleRadius() { + public void testCircleRadiusAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("circle-radius"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleRadius(0.3f)); assertEquals((Float) layer.getCircleRadius().getValue(), (Float) 0.3f); } @Test - public void testCircleColor() { + public void testCircleRadiusAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleRadius( + zoom( + exponential( + stop(2, circleRadius(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleRadius().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleRadius().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleRadiusAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + } + + @Test + public void testCircleRadiusAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleRadius(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + } + + @Test + public void testCircleRadiusAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleRadius(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue()); + } + + @Test + public void testCircleRadiusAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleRadius(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleRadius().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getCircleRadius().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testCircleColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getCircleColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testCircleColorAsInt() { + public void testCircleColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleColor( + zoom( + exponential( + stop(2, circleColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(circleColor(Color.RED)); - assertEquals(layer.getCircleColorAsInt(), Color.RED); + // Set + layer.setProperties( + circleColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleColor().getFunction().getStops().getClass()); } @Test - public void testCircleBlur() { + public void testCircleColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, circleColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", circleColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleColor(Color.RED)); + assertEquals(layer.getCircleColorAsInt(), Color.RED); + } + + @Test + public void testCircleBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-blur"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleBlur(0.3f)); assertEquals((Float) layer.getCircleBlur().getValue(), (Float) 0.3f); } @Test - public void testCircleOpacity() { + public void testCircleBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleBlur( + zoom( + exponential( + stop(2, circleBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleBlurAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + } + + @Test + public void testCircleBlurAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + } + + @Test + public void testCircleBlurAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleBlur(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue()); + } + + @Test + public void testCircleBlurAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleBlur(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleBlur().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getCircleBlur().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testCircleOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleOpacity(0.3f)); assertEquals((Float) layer.getCircleOpacity().getValue(), (Float) 0.3f); } @Test - public void testCircleTranslate() { + public void testCircleOpacityAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + zoom( + exponential( + stop(2, circleOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleOpacity().getFunction().getStops()).size()); + } + + @Test + public void testCircleOpacityAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleOpacity(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleOpacity(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue()); + } + + @Test + public void testCircleOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleOpacity(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleOpacity().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getCircleOpacity().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testCircleTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-translate"); assertNotNull(layer); - //Set and Get - layer.setProperties(circleTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(circleTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testCircleTranslateAnchor() { + public void testCircleTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleTranslate( + zoom( + exponential( + stop(2, circleTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleTranslate()); + assertNotNull(layer.getCircleTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-translate-anchor"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)); assertEquals((String) layer.getCircleTranslateAnchor().getValue(), (String) CIRCLE_TRANSLATE_ANCHOR_MAP); } @Test - public void testCirclePitchScale() { + public void testCircleTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleTranslateAnchor( + zoom( + interval( + stop(2, circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleTranslateAnchor()); + assertNotNull(layer.getCircleTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getCircleTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getCircleTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCirclePitchScaleAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-pitch-scale"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP)); assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP); } @Test - public void testCircleStrokeWidth() { + public void testCirclePitchScaleAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-pitch-scale"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circlePitchScale( + zoom( + interval( + stop(2, circlePitchScale(CIRCLE_PITCH_SCALE_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCirclePitchScale()); + assertNotNull(layer.getCirclePitchScale().getFunction()); + assertEquals(CameraFunction.class, layer.getCirclePitchScale().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getCirclePitchScale().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getCirclePitchScale().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-width"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleStrokeWidth(0.3f)); assertEquals((Float) layer.getCircleStrokeWidth().getValue(), (Float) 0.3f); } @Test - public void testCircleStrokeColor() { + public void testCircleStrokeWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleStrokeWidth( + zoom( + exponential( + stop(2, circleStrokeWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleStrokeWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeWidthAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeWidthAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleStrokeWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeWidthAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleStrokeWidth(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue()); + } + + @Test + public void testCircleStrokeWidthAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleStrokeWidth(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeWidth().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getCircleStrokeWidth().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testCircleStrokeColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleStrokeColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getCircleStrokeColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testCircleStrokeColorAsInt() { + public void testCircleStrokeColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleStrokeColor( + zoom( + exponential( + stop(2, circleStrokeColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleStrokeColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(circleStrokeColor(Color.RED)); - assertEquals(layer.getCircleStrokeColorAsInt(), Color.RED); + // Set + layer.setProperties( + circleStrokeColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); } @Test - public void testCircleStrokeOpacity() { + public void testCircleStrokeColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleStrokeColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, circleStrokeColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", circleStrokeColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleStrokeColor(Color.RED)); + assertEquals(layer.getCircleStrokeColorAsInt(), Color.RED); + } + + @Test + public void testCircleStrokeOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(circleStrokeOpacity(0.3f)); assertEquals((Float) layer.getCircleStrokeOpacity().getValue(), (Float) 0.3f); } + @Test + public void testCircleStrokeOpacityAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + zoom( + exponential( + stop(2, circleStrokeOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleStrokeOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeOpacity().getFunction().getStops()).size()); + } + + @Test + public void testCircleStrokeOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleStrokeOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleStrokeOpacity(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue()); + } + + @Test + public void testCircleStrokeOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleStrokeOpacity(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeOpacity().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getCircleStrokeOpacity().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java deleted file mode 100644 index c8668fa407..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java +++ /dev/null @@ -1,286 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.FILL_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillAntialias; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for FillLayer - */ -@RunWith(AndroidJUnit4.class) -public class FillLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private FillLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testFillAntialias() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-antialias"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillAntialias(true)); - assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true); - } - - @Test - public void testFillOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillOpacity(0.3f)); - assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testFillColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testFillColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillColor(Color.RED)); - assertEquals(layer.getFillColorAsInt(), Color.RED); - } - - @Test - public void testFillOutlineColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-outline-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testFillOutlineColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-outline-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillOutlineColor(Color.RED)); - assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); - } - - @Test - public void testFillTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-translate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testFillTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-translate-anchor"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testFillPattern() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("fill-pattern"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(fillPattern("pedestrian-polygon")); - assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java index 95360e1273..dd59b97525 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.FillLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,21 +29,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.FILL_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillAntialias; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for FillLayer @@ -53,12 +55,6 @@ public class FillLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -66,218 +62,551 @@ public class FillLayerTest extends BaseStyleTest { layer = new FillLayer("my-layer", "composite"); layer.setSourceLayer("composite"); mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference + // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); - //Set + // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } @Test - public void testFillAntialias() { + public void testFillAntialiasAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("fill-antialias"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(fillAntialias(true)); assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true); } @Test - public void testFillOpacity() { + public void testFillAntialiasAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-antialias"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillAntialias( + zoom( + interval( + stop(2, fillAntialias(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillAntialias()); + assertNotNull(layer.getFillAntialias().getFunction()); + assertEquals(CameraFunction.class, layer.getFillAntialias().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getFillAntialias().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getFillAntialias().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(fillOpacity(0.3f)); assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f); } @Test - public void testFillColor() { + public void testFillOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillOpacity( + zoom( + exponential( + stop(2, fillOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillOpacity()); + assertNotNull(layer.getFillOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getFillOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getFillOpacity()); + assertNotNull(layer.getFillOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testFillOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, fillOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillOpacity()); + assertNotNull(layer.getFillOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testFillOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, fillOpacity(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getFillOpacity()); + assertNotNull(layer.getFillOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue()); + } + + @Test + public void testFillOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, fillOpacity(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getFillOpacity()); + assertNotNull(layer.getFillOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getFillOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getFillOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getFillOpacity().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testFillColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(fillColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testFillColorAsInt() { + public void testFillColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillColor( + zoom( + exponential( + stop(2, fillColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillColor()); + assertNotNull(layer.getFillColor().getFunction()); + assertEquals(CameraFunction.class, layer.getFillColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getFillColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getFillColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getFillColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(fillColor(Color.RED)); - assertEquals(layer.getFillColorAsInt(), Color.RED); + // Set + layer.setProperties( + fillColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getFillColor()); + assertNotNull(layer.getFillColor().getFunction()); + assertEquals(SourceFunction.class, layer.getFillColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getFillColor().getFunction().getStops().getClass()); } @Test - public void testFillOutlineColor() { + public void testFillColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, fillColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillColor()); + assertNotNull(layer.getFillColor().getFunction()); + assertEquals(SourceFunction.class, layer.getFillColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getFillColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", fillColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillColor()); + assertNotNull(layer.getFillColor().getFunction()); + assertEquals(SourceFunction.class, layer.getFillColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getFillColor().getFunction().getStops().getClass()); + } + + @Test + public void testFillColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillColor(Color.RED)); + assertEquals(layer.getFillColorAsInt(), Color.RED); + } + + @Test + public void testFillOutlineColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-outline-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testFillOutlineColorAsInt() { + public void testFillOutlineColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillOutlineColor( + zoom( + exponential( + stop(2, fillOutlineColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillOutlineColor()); + assertNotNull(layer.getFillOutlineColor().getFunction()); + assertEquals(CameraFunction.class, layer.getFillOutlineColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getFillOutlineColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getFillOutlineColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillOutlineColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-outline-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(fillOutlineColor(Color.RED)); - assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); + // Set + layer.setProperties( + fillOutlineColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getFillOutlineColor()); + assertNotNull(layer.getFillOutlineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getFillOutlineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOutlineColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass()); } @Test - public void testFillTranslate() { + public void testFillOutlineColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillOutlineColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, fillOutlineColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillOutlineColor()); + assertNotNull(layer.getFillOutlineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getFillOutlineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOutlineColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillOutlineColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOutlineColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", fillOutlineColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillOutlineColor()); + assertNotNull(layer.getFillOutlineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getFillOutlineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOutlineColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass()); + } + + @Test + public void testFillOutlineColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillOutlineColor(Color.RED)); + assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); + } + + @Test + public void testFillTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-translate"); assertNotNull(layer); - //Set and Get - layer.setProperties(fillTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(fillTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testFillTranslateAnchor() { + public void testFillTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillTranslate( + zoom( + exponential( + stop(2, fillTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillTranslate()); + assertNotNull(layer.getFillTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getFillTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getFillTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getFillTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getFillTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-translate-anchor"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP)); assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP); } @Test - public void testFillPattern() { + public void testFillTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + fillTranslateAnchor( + zoom( + interval( + stop(2, fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillTranslateAnchor()); + assertNotNull(layer.getFillTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getFillTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getFillTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getFillTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testFillPatternAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-pattern"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(fillPattern("pedestrian-polygon")); assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); } + @Test + public void testFillPatternAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-pattern"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillPattern( + zoom( + interval( + stop(2, fillPattern("pedestrian-polygon")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillPattern()); + assertNotNull(layer.getFillPattern().getFunction()); + assertEquals(CameraFunction.class, layer.getFillPattern().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getFillPattern().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getFillPattern().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java deleted file mode 100644 index 47a38a11ab..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java +++ /dev/null @@ -1,427 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.LineLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_CAP_BUTT; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_JOIN_BEVEL; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineDasharray; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineGapWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineMiterLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.linePattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineRoundLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for LineLayer - */ -@RunWith(AndroidJUnit4.class) -public class LineLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private LineLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testLineCap() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-cap"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineCap(LINE_CAP_BUTT)); - assertEquals((String) layer.getLineCap().getValue(), (String) LINE_CAP_BUTT); - } - - @Test - public void testLineJoin() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-join"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineJoin(LINE_JOIN_BEVEL)); - assertEquals((String) layer.getLineJoin().getValue(), (String) LINE_JOIN_BEVEL); - } - - @Test - public void testLineMiterLimit() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-miter-limit"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineMiterLimit(0.3f)); - assertEquals((Float) layer.getLineMiterLimit().getValue(), (Float) 0.3f); - } - - @Test - public void testLineRoundLimit() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-round-limit"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineRoundLimit(0.3f)); - assertEquals((Float) layer.getLineRoundLimit().getValue(), (Float) 0.3f); - } - - @Test - public void testLineOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineOpacity(0.3f)); - assertEquals((Float) layer.getLineOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testLineColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getLineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testLineColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineColor(Color.RED)); - assertEquals(layer.getLineColorAsInt(), Color.RED); - } - - @Test - public void testLineTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-translate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testLineTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-translate-anchor"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getLineTranslateAnchor().getValue(), (String) LINE_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testLineWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-width"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineWidth(0.3f)); - assertEquals((Float) layer.getLineWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testLineGapWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-gap-width"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineGapWidth(0.3f)); - assertEquals((Float) layer.getLineGapWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testLineOffset() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-offset"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineOffset(0.3f)); - assertEquals((Float) layer.getLineOffset().getValue(), (Float) 0.3f); - } - - @Test - public void testLineBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-blur"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineBlur(0.3f)); - assertEquals((Float) layer.getLineBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testLineDasharray() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-dasharray"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(lineDasharray(new Float[] {})); - assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); - } - - @Test - public void testLinePattern() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-pattern"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(linePattern("pedestrian-polygon")); - assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java index ad091c78b3..740393ad36 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,30 +29,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_CAP_BUTT; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_JOIN_BEVEL; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineDasharray; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineGapWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineMiterLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.linePattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineRoundLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for LineLayer @@ -62,12 +55,6 @@ public class LineLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -75,350 +62,1044 @@ public class LineLayerTest extends BaseStyleTest { layer = new LineLayer("my-layer", "composite"); layer.setSourceLayer("composite"); mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference + // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); - //Set + // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } @Test - public void testLineCap() { + public void testLineCapAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("line-cap"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineCap(LINE_CAP_BUTT)); assertEquals((String) layer.getLineCap().getValue(), (String) LINE_CAP_BUTT); } @Test - public void testLineJoin() { + public void testLineCapAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-cap"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineCap( + zoom( + interval( + stop(2, lineCap(LINE_CAP_BUTT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineCap()); + assertNotNull(layer.getLineCap().getFunction()); + assertEquals(CameraFunction.class, layer.getLineCap().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineCap().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineCap().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineJoinAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-join"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineJoin(LINE_JOIN_BEVEL)); assertEquals((String) layer.getLineJoin().getValue(), (String) LINE_JOIN_BEVEL); } @Test - public void testLineMiterLimit() { + public void testLineJoinAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-join"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineJoin( + zoom( + interval( + stop(2, lineJoin(LINE_JOIN_BEVEL)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineJoin()); + assertNotNull(layer.getLineJoin().getFunction()); + assertEquals(CameraFunction.class, layer.getLineJoin().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineJoin().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineJoin().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineMiterLimitAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-miter-limit"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineMiterLimit(0.3f)); assertEquals((Float) layer.getLineMiterLimit().getValue(), (Float) 0.3f); } @Test - public void testLineRoundLimit() { + public void testLineMiterLimitAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-miter-limit"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineMiterLimit( + zoom( + exponential( + stop(2, lineMiterLimit(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineMiterLimit()); + assertNotNull(layer.getLineMiterLimit().getFunction()); + assertEquals(CameraFunction.class, layer.getLineMiterLimit().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineMiterLimit().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineMiterLimit().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineMiterLimit().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineRoundLimitAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-round-limit"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineRoundLimit(0.3f)); assertEquals((Float) layer.getLineRoundLimit().getValue(), (Float) 0.3f); } @Test - public void testLineOpacity() { + public void testLineRoundLimitAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-round-limit"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineRoundLimit( + zoom( + exponential( + stop(2, lineRoundLimit(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineRoundLimit()); + assertNotNull(layer.getLineRoundLimit().getFunction()); + assertEquals(CameraFunction.class, layer.getLineRoundLimit().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineRoundLimit().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineRoundLimit().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineRoundLimit().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineOpacity(0.3f)); assertEquals((Float) layer.getLineOpacity().getValue(), (Float) 0.3f); } @Test - public void testLineColor() { + public void testLineOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineOpacity( + zoom( + exponential( + stop(2, lineOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testLineOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testLineOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineOpacity(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue()); + } + + @Test + public void testLineOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineOpacity(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineOpacity().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getLineOpacity().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testLineColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getLineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testLineColorAsInt() { + public void testLineColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineColor( + zoom( + exponential( + stop(2, lineColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(CameraFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(lineColor(Color.RED)); - assertEquals(layer.getLineColorAsInt(), Color.RED); + // Set + layer.setProperties( + lineColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineColor().getFunction().getStops().getClass()); } @Test - public void testLineTranslate() { + public void testLineColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, lineColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", lineColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineColor().getFunction().getStops().getClass()); + } + + @Test + public void testLineColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineColor(Color.RED)); + assertEquals(layer.getLineColorAsInt(), Color.RED); + } + + @Test + public void testLineTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-translate"); assertNotNull(layer); - //Set and Get - layer.setProperties(lineTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(lineTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testLineTranslateAnchor() { + public void testLineTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineTranslate( + zoom( + exponential( + stop(2, lineTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineTranslate()); + assertNotNull(layer.getLineTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getLineTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-translate-anchor"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)); assertEquals((String) layer.getLineTranslateAnchor().getValue(), (String) LINE_TRANSLATE_ANCHOR_MAP); } @Test - public void testLineWidth() { + public void testLineTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineTranslateAnchor( + zoom( + interval( + stop(2, lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineTranslateAnchor()); + assertNotNull(layer.getLineTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getLineTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-width"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineWidth(0.3f)); assertEquals((Float) layer.getLineWidth().getValue(), (Float) 0.3f); } @Test - public void testLineGapWidth() { + public void testLineWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineWidth( + zoom( + exponential( + stop(2, lineWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineWidth()); + assertNotNull(layer.getLineWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineGapWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-gap-width"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineGapWidth(0.3f)); assertEquals((Float) layer.getLineGapWidth().getValue(), (Float) 0.3f); } @Test - public void testLineOffset() { + public void testLineGapWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineGapWidth( + zoom( + exponential( + stop(2, lineGapWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineGapWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineGapWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineGapWidthAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + } + + @Test + public void testLineGapWidthAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineGapWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + } + + @Test + public void testLineGapWidthAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineGapWidth(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue()); + } + + @Test + public void testLineGapWidthAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineGapWidth(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineGapWidth().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getLineGapWidth().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testLineOffsetAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-offset"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineOffset(0.3f)); assertEquals((Float) layer.getLineOffset().getValue(), (Float) 0.3f); } @Test - public void testLineBlur() { + public void testLineOffsetAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineOffset( + zoom( + exponential( + stop(2, lineOffset(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineOffsetAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + } + + @Test + public void testLineOffsetAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineOffset(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + } + + @Test + public void testLineOffsetAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineOffset(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue()); + } + + @Test + public void testLineOffsetAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineOffset(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getLineOffset().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testLineBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-blur"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(lineBlur(0.3f)); assertEquals((Float) layer.getLineBlur().getValue(), (Float) 0.3f); } @Test - public void testLineDasharray() { + public void testLineBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineBlur( + zoom( + exponential( + stop(2, lineBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineBlurAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + } + + @Test + public void testLineBlurAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + } + + @Test + public void testLineBlurAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineBlur(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue()); + } + + @Test + public void testLineBlurAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineBlur(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getLineBlur().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getLineBlur().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testLineDasharrayAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-dasharray"); assertNotNull(layer); - //Set and Get - layer.setProperties(lineDasharray(new Float[] {})); - assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); + // Set and Get + layer.setProperties(lineDasharray(new Float[]{})); + assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[]{}); } @Test - public void testLinePattern() { + public void testLineDasharrayAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-dasharray"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineDasharray( + zoom( + interval( + stop(2, lineDasharray(new Float[]{})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineDasharray()); + assertNotNull(layer.getLineDasharray().getFunction()); + assertEquals(CameraFunction.class, layer.getLineDasharray().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineDasharray().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineDasharray().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLinePatternAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-pattern"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(linePattern("pedestrian-polygon")); assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); } + @Test + public void testLinePatternAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-pattern"); + assertNotNull(layer); + + // Set + layer.setProperties( + linePattern( + zoom( + interval( + stop(2, linePattern("pedestrian-polygon")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLinePattern()); + assertNotNull(layer.getLinePattern().getFunction()); + assertEquals(CameraFunction.class, layer.getLinePattern().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLinePattern().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLinePattern().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java deleted file mode 100644 index eb67b48f7a..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.RasterLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMax; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterContrast; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterFadeDuration; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterHueRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterSaturation; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for RasterLayer - */ -@RunWith(AndroidJUnit4.class) -public class RasterLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private RasterLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testRasterOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterOpacity(0.3f)); - assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterHueRotate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-hue-rotate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterHueRotate(0.3f)); - assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterBrightnessMin() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-brightness-min"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterBrightnessMin(0.3f)); - assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterBrightnessMax() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-brightness-max"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterBrightnessMax(0.3f)); - assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterSaturation() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-saturation"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterSaturation(0.3f)); - assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterContrast() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-contrast"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterContrast(0.3f)); - assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterFadeDuration() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("raster-fade-duration"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(rasterFadeDuration(0.3f)); - assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java index 169d747b9c..eb2155f545 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java @@ -1,11 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.RasterLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -17,20 +29,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMax; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterContrast; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterFadeDuration; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterHueRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterSaturation; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for RasterLayer @@ -51,12 +55,6 @@ public class RasterLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -64,174 +62,284 @@ public class RasterLayerTest extends BaseStyleTest { layer = new RasterLayer("my-layer", "composite"); layer.setSourceLayer("composite"); mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference + // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); - //Set + // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } @Test - public void testRasterOpacity() { + public void testRasterOpacityAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("raster-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterOpacity(0.3f)); assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f); } @Test - public void testRasterHueRotate() { + public void testRasterOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + rasterOpacity( + zoom( + exponential( + stop(2, rasterOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterOpacity()); + assertNotNull(layer.getRasterOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testRasterHueRotateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-hue-rotate"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterHueRotate(0.3f)); assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f); } @Test - public void testRasterBrightnessMin() { + public void testRasterHueRotateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-hue-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + rasterHueRotate( + zoom( + exponential( + stop(2, rasterHueRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterHueRotate()); + assertNotNull(layer.getRasterHueRotate().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterHueRotate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterHueRotate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testRasterBrightnessMinAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-brightness-min"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterBrightnessMin(0.3f)); assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f); } @Test - public void testRasterBrightnessMax() { + public void testRasterBrightnessMinAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-brightness-min"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + rasterBrightnessMin( + zoom( + exponential( + stop(2, rasterBrightnessMin(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterBrightnessMin()); + assertNotNull(layer.getRasterBrightnessMin().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterBrightnessMin().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterBrightnessMin().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testRasterBrightnessMaxAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-brightness-max"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterBrightnessMax(0.3f)); assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f); } @Test - public void testRasterSaturation() { + public void testRasterBrightnessMaxAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-brightness-max"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + rasterBrightnessMax( + zoom( + exponential( + stop(2, rasterBrightnessMax(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterBrightnessMax()); + assertNotNull(layer.getRasterBrightnessMax().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterBrightnessMax().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterBrightnessMax().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testRasterSaturationAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-saturation"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterSaturation(0.3f)); assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f); } @Test - public void testRasterContrast() { + public void testRasterSaturationAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-saturation"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + rasterSaturation( + zoom( + exponential( + stop(2, rasterSaturation(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterSaturation()); + assertNotNull(layer.getRasterSaturation().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterSaturation().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterSaturation().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testRasterContrastAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-contrast"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterContrast(0.3f)); assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f); } @Test - public void testRasterFadeDuration() { + public void testRasterContrastAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-contrast"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + rasterContrast( + zoom( + exponential( + stop(2, rasterContrast(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterContrast()); + assertNotNull(layer.getRasterContrast().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterContrast().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterContrast().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new RasterLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testRasterFadeDurationAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-fade-duration"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(rasterFadeDuration(0.3f)); assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); } + @Test + public void testRasterFadeDurationAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-fade-duration"); + assertNotNull(layer); + + // Set + layer.setProperties( + rasterFadeDuration( + zoom( + exponential( + stop(2, rasterFadeDuration(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getRasterFadeDuration()); + assertNotNull(layer.getRasterFadeDuration().getFunction()); + assertEquals(CameraFunction.class, layer.getRasterFadeDuration().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getRasterFadeDuration().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleBackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleBackgroundLayerTest.java index 762ae4f846..c95c959644 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleBackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleBackgroundLayerTest.java @@ -44,10 +44,10 @@ public class RuntimeStyleBackgroundLayerTest BackgroundLayer layer = mapboxMap.getLayerAs("background"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), Property.VISIBLE); - //Set + // Set layer.setProperties(PropertyFactory.visibility(Property.NONE)); assertEquals(layer.getVisibility().getValue(), Property.NONE); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java index eec00bdde9..bf90949ffd 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java @@ -1,6 +1,7 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; +import android.graphics.PointF; import android.support.test.espresso.Espresso; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; @@ -10,12 +11,12 @@ import android.view.View; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException; +import com.mapbox.mapboxsdk.style.layers.CircleLayer; import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException; +import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.layers.Property; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; -import com.mapbox.mapboxsdk.style.sources.NoSuchSourceException; import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.mapboxsdk.style.sources.VectorSource; import com.mapbox.mapboxsdk.testapp.R; @@ -32,12 +33,18 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import java.util.List; + +import timber.log.Timber; + import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static junit.framework.Assert.fail; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Basic smoke tests for Layer and Source @@ -57,139 +64,255 @@ public class RuntimeStyleTests { } @Test + public void testListLayers() { + ViewUtils.checkViewIsDisplayed(R.id.mapView); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); + + List<Layer> layers = mapboxMap.getLayers(); + assertNotNull(layers); + assertTrue(layers.size() > 0); + for (Layer layer : layers) { + assertNotNull(layer); + } + } + + }); + } + + @Test public void testGetAddRemoveLayer() { ViewUtils.checkViewIsDisplayed(R.id.mapView); onView(withId(R.id.mapView)).perform(new AddRemoveLayerAction()); } @Test + public void testAddLayerAbove() { + ViewUtils.checkViewIsDisplayed(R.id.mapView); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + @Override + public void perform(UiController uiController, View view) { + MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); + + List<Layer> layers = mapboxMap.getLayers(); + Source source = mapboxMap.getSources().get(0); + + // Test inserting with invalid above-id + try { + mapboxMap.addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man"); + fail("Should have thrown exception"); + } catch (CannotAddLayerException ex) { + // Yeah + assertNotNull(ex.getMessage()); + } + + // Insert as last + CircleLayer last = new CircleLayer("this is the last one", source.getId()); + mapboxMap.addLayerAbove(last, layers.get(layers.size() - 1).getId()); + layers = mapboxMap.getLayers(); + assertEquals(last.getId(), layers.get(layers.size() - 1).getId()); + + // Insert + CircleLayer second = new CircleLayer("this is the second one", source.getId()); + mapboxMap.addLayerAbove(second, layers.get(0).getId()); + layers = mapboxMap.getLayers(); + assertEquals(second.getId(), layers.get(1).getId()); + } + }); + } + + @Test + public void testRemoveLayerAt() { + ViewUtils.checkViewIsDisplayed(R.id.mapView); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); + + // Remove by index + Layer firstLayer = mapboxMap.getLayers().get(0); + Layer removed = mapboxMap.removeLayerAt(0); + assertNotNull(removed); + assertNotNull(removed.getId()); + assertEquals(firstLayer.getId(), removed.getId()); + + // Test remove by index bounds checks + Timber.i("Remove layer at index > size"); + assertNull(mapboxMap.removeLayerAt(Integer.MAX_VALUE)); + } + }); + } + + public void testAddLayerAt() { + ViewUtils.checkViewIsDisplayed(R.id.mapView); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + @Override + public void perform(UiController uiController, View view) { + MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); + + List<Layer> layers = mapboxMap.getLayers(); + Source source = mapboxMap.getSources().get(0); + + // Test inserting out of range + try { + mapboxMap.addLayerAt(new CircleLayer("invalid-id-layer-test", source.getId()), layers.size()); + fail("Should have thrown exception"); + } catch (CannotAddLayerException ex) { + // Yeah + assertNotNull(ex.getMessage()); + } + + // Insert at current last position + CircleLayer last = new CircleLayer("this is the last one", source.getId()); + mapboxMap.addLayerAt(last, layers.size() - 1); + layers = mapboxMap.getLayers(); + assertEquals(last.getId(), layers.get(layers.size() - 2).getId()); + + // Insert at start + CircleLayer second = new CircleLayer("this is the first one", source.getId()); + mapboxMap.addLayerAt(second, 0); + layers = mapboxMap.getLayers(); + assertEquals(second.getId(), layers.get(0).getId()); + } + }); + } + + + @Test + public void testListSources() { + ViewUtils.checkViewIsDisplayed(R.id.mapView); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); + + List<Source> sources = mapboxMap.getSources(); + assertNotNull(sources); + assertTrue(sources.size() > 0); + for (Source source : sources) { + assertNotNull(source); + } + } + + }); + } + + @Test public void testAddRemoveSource() { ViewUtils.checkViewIsDisplayed(R.id.mapView); MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2")); - try { - mapboxMap.removeSource("my-source"); - } catch (NoSuchSourceException noSuchSourceException) { - // it's ok.. - } + mapboxMap.removeSource("my-source"); onView(withId(R.id.mapView)).perform(new AddRemoveSourceAction()); } - private class AddRemoveLayerAction implements ViewAction { + /** + * https://github.com/mapbox/mapbox-gl-native/issues/7973 + */ + @Test + public void testQueryRenderedFeaturesInputHandling() { + ViewUtils.checkViewIsDisplayed(R.id.mapView); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); + String[] layerIds = new String[600]; + for (int i = 0; i < layerIds.length; i++) { + layerIds[i] = "layer-" + i; + } + mapboxMap.queryRenderedFeatures(new PointF(100, 100), layerIds); + } - @Override - public Matcher<View> getConstraints() { - return isDisplayed(); - } + }); + } - @Override - public String getDescription() { - return getClass().getSimpleName(); - } + private class AddRemoveLayerAction extends BaseViewAction { @Override public void perform(UiController uiController, View view) { MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); - //Get initial + // Get initial assertNotNull(mapboxMap.getLayer("building")); - //Remove - try { - mapboxMap.removeLayer("building"); - } catch (NoSuchLayerException noSuchSourceException) { - fail("Definitively exists: " + noSuchSourceException.getMessage()); - } + // Remove + Layer building = mapboxMap.removeLayer("building"); + assertNotNull(building); assertNull(mapboxMap.getLayer("building")); - //Add + // Add FillLayer layer = new FillLayer("building", "composite"); layer.setSourceLayer("building"); mapboxMap.addLayer(layer); assertNotNull(mapboxMap.getLayer("building")); - //Assure the reference still works + // Assure the reference still works layer.setProperties(PropertyFactory.visibility(Property.VISIBLE)); - //Remove, preserving the reference - try { - mapboxMap.removeLayer(layer); - } catch (NoSuchLayerException noSuchSourceException) { - fail("Definitively exists: " + noSuchSourceException.getMessage()); - } + // Remove, preserving the reference + mapboxMap.removeLayer(layer); - //Property setters should still work + // Property setters should still work layer.setProperties(PropertyFactory.fillColor(Color.RED)); - //Re-add the reference... + // Re-add the reference... mapboxMap.addLayer(layer); - //Ensure it's there + // Ensure it's there Assert.assertNotNull(mapboxMap.getLayer(layer.getId())); - //Test adding a duplicate layer + // Test adding a duplicate layer try { mapboxMap.addLayer(new FillLayer("building", "composite")); fail("Should not have been allowed to add a layer with a duplicate id"); } catch (CannotAddLayerException cannotAddLayerException) { - //OK + // OK } } } - private class AddRemoveSourceAction implements ViewAction { - - @Override - public Matcher<View> getConstraints() { - return isDisplayed(); - } - - @Override - public String getDescription() { - return getClass().getSimpleName(); - } + private class AddRemoveSourceAction extends BaseViewAction { @Override public void perform(UiController uiController, View view) { MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); - //Add initial source + // Add initial source mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2")); - //Remove - try { - mapboxMap.removeSource("my-source"); - } catch (NoSuchSourceException noSuchSourceException) { - fail("Definitively exists: " + noSuchSourceException.getMessage()); - } + // Remove + Source mySource = mapboxMap.removeSource("my-source"); + assertNotNull(mySource); assertNull(mapboxMap.getLayer("my-source")); - //Add + // Add Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); mapboxMap.addSource(source); - //Remove, preserving the reference - try { - mapboxMap.removeSource(source); - } catch (NoSuchSourceException noSuchSourceException) { - fail("Definitively exists: " + noSuchSourceException.getMessage()); - } + // Remove, preserving the reference + mapboxMap.removeSource(source); - //Re-add the reference... + // Re-add the reference... mapboxMap.addSource(source); - //Ensure it's there + // Ensure it's there Assert.assertNotNull(mapboxMap.getSource(source.getId())); - //Test adding a duplicate source + // Test adding a duplicate source try { Source source2 = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); mapboxMap.addSource(source2); fail("Should not have been allowed to add a source with a duplicate id"); } catch (CannotAddSourceException cannotAddSourceException) { - //OK + // OK } } } @@ -198,4 +321,18 @@ public class RuntimeStyleTests { public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); } + + public abstract class BaseViewAction implements ViewAction { + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTimingTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTimingTests.java index 57b0fe72ff..400c5fbc3c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTimingTests.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTimingTests.java @@ -35,7 +35,7 @@ public class RuntimeStyleTimingTests extends BaseStyleTest { @Test public void testGetAddRemoveLayer() { checkViewIsDisplayed(R.id.mapView); - //We're good if it didn't crash + // We're good if it didn't crash } @After diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java deleted file mode 100644 index 5b59d4ceae..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java +++ /dev/null @@ -1,1283 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.SymbolLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TEXT_FIT_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.SYMBOL_PLACEMENT_POINT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_CENTER; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_LEFT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_PITCH_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSFORM_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFitPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolAvoidEdges; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolPlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textFont; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textJustify; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLetterSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLineHeight; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxAngle; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPitchAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTransform; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for SymbolLayer - */ -@RunWith(AndroidJUnit4.class) -public class SymbolLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private SymbolLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testSymbolPlacement() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("symbol-placement"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT)); - assertEquals((String) layer.getSymbolPlacement().getValue(), (String) SYMBOL_PLACEMENT_POINT); - } - - @Test - public void testSymbolSpacing() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("symbol-spacing"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(symbolSpacing(0.3f)); - assertEquals((Float) layer.getSymbolSpacing().getValue(), (Float) 0.3f); - } - - @Test - public void testSymbolAvoidEdges() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("symbol-avoid-edges"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(symbolAvoidEdges(true)); - assertEquals((Boolean) layer.getSymbolAvoidEdges().getValue(), (Boolean) true); - } - - @Test - public void testIconAllowOverlap() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-allow-overlap"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconAllowOverlap(true)); - assertEquals((Boolean) layer.getIconAllowOverlap().getValue(), (Boolean) true); - } - - @Test - public void testIconIgnorePlacement() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-ignore-placement"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconIgnorePlacement(true)); - assertEquals((Boolean) layer.getIconIgnorePlacement().getValue(), (Boolean) true); - } - - @Test - public void testIconOptional() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-optional"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconOptional(true)); - assertEquals((Boolean) layer.getIconOptional().getValue(), (Boolean) true); - } - - @Test - public void testIconRotationAlignment() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-rotation-alignment"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); - assertEquals((String) layer.getIconRotationAlignment().getValue(), (String) ICON_ROTATION_ALIGNMENT_MAP); - } - - @Test - public void testIconSize() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-size"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconSize(0.3f)); - assertEquals((Float) layer.getIconSize().getValue(), (Float) 0.3f); - } - - @Test - public void testIconTextFit() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-text-fit"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconTextFit(ICON_TEXT_FIT_NONE)); - assertEquals((String) layer.getIconTextFit().getValue(), (String) ICON_TEXT_FIT_NONE); - } - - @Test - public void testIconTextFitPadding() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-text-fit-padding"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconTextFitPadding(new Float[] {0f, 0f, 0f, 0f})); - assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); - } - - @Test - public void testIconImage() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-image"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconImage("undefined")); - assertEquals((String) layer.getIconImage().getValue(), (String) "undefined"); - } - - @Test - public void testIconRotate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-rotate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconRotate(0.3f)); - assertEquals((Float) layer.getIconRotate().getValue(), (Float) 0.3f); - } - - @Test - public void testIconPadding() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-padding"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconPadding(0.3f)); - assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); - } - - @Test - public void testIconKeepUpright() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-keep-upright"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconKeepUpright(true)); - assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); - } - - @Test - public void testIconOffset() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-offset"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testTextPitchAlignment() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-pitch-alignment"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)); - assertEquals((String) layer.getTextPitchAlignment().getValue(), (String) TEXT_PITCH_ALIGNMENT_MAP); - } - - @Test - public void testTextRotationAlignment() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-rotation-alignment"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)); - assertEquals((String) layer.getTextRotationAlignment().getValue(), (String) TEXT_ROTATION_ALIGNMENT_MAP); - } - - @Test - public void testTextField() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-field"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textField("")); - assertEquals((String) layer.getTextField().getValue(), (String) ""); - } - - @Test - public void testTextFont() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-font"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textFont(new String[] {"Open Sans Regular", "Arial Unicode MS Regular"})); - assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[] {"Open Sans Regular", - "Arial Unicode MS Regular"}); - } - - @Test - public void testTextSize() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-size"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textSize(0.3f)); - assertEquals((Float) layer.getTextSize().getValue(), (Float) 0.3f); - } - - @Test - public void testTextMaxWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-max-width"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textMaxWidth(0.3f)); - assertEquals((Float) layer.getTextMaxWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testTextLineHeight() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-line-height"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textLineHeight(0.3f)); - assertEquals((Float) layer.getTextLineHeight().getValue(), (Float) 0.3f); - } - - @Test - public void testTextLetterSpacing() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-letter-spacing"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textLetterSpacing(0.3f)); - assertEquals((Float) layer.getTextLetterSpacing().getValue(), (Float) 0.3f); - } - - @Test - public void testTextJustify() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-justify"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textJustify(TEXT_JUSTIFY_LEFT)); - assertEquals((String) layer.getTextJustify().getValue(), (String) TEXT_JUSTIFY_LEFT); - } - - @Test - public void testTextAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-anchor"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textAnchor(TEXT_ANCHOR_CENTER)); - assertEquals((String) layer.getTextAnchor().getValue(), (String) TEXT_ANCHOR_CENTER); - } - - @Test - public void testTextMaxAngle() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-max-angle"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textMaxAngle(0.3f)); - assertEquals((Float) layer.getTextMaxAngle().getValue(), (Float) 0.3f); - } - - @Test - public void testTextRotate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-rotate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textRotate(0.3f)); - assertEquals((Float) layer.getTextRotate().getValue(), (Float) 0.3f); - } - - @Test - public void testTextPadding() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-padding"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textPadding(0.3f)); - assertEquals((Float) layer.getTextPadding().getValue(), (Float) 0.3f); - } - - @Test - public void testTextKeepUpright() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-keep-upright"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textKeepUpright(true)); - assertEquals((Boolean) layer.getTextKeepUpright().getValue(), (Boolean) true); - } - - @Test - public void testTextTransform() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-transform"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textTransform(TEXT_TRANSFORM_NONE)); - assertEquals((String) layer.getTextTransform().getValue(), (String) TEXT_TRANSFORM_NONE); - } - - @Test - public void testTextOffset() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-offset"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testTextAllowOverlap() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-allow-overlap"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textAllowOverlap(true)); - assertEquals((Boolean) layer.getTextAllowOverlap().getValue(), (Boolean) true); - } - - @Test - public void testTextIgnorePlacement() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-ignore-placement"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textIgnorePlacement(true)); - assertEquals((Boolean) layer.getTextIgnorePlacement().getValue(), (Boolean) true); - } - - @Test - public void testTextOptional() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-optional"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textOptional(true)); - assertEquals((Boolean) layer.getTextOptional().getValue(), (Boolean) true); - } - - @Test - public void testIconOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconOpacity(0.3f)); - assertEquals((Float) layer.getIconOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testIconColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getIconColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testIconColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconColor(Color.RED)); - assertEquals(layer.getIconColorAsInt(), Color.RED); - } - - @Test - public void testIconHaloColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconHaloColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getIconHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testIconHaloColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconHaloColor(Color.RED)); - assertEquals(layer.getIconHaloColorAsInt(), Color.RED); - } - - @Test - public void testIconHaloWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-width"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconHaloWidth(0.3f)); - assertEquals((Float) layer.getIconHaloWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testIconHaloBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-blur"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconHaloBlur(0.3f)); - assertEquals((Float) layer.getIconHaloBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testIconTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-translate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testIconTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-translate-anchor"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getIconTranslateAnchor().getValue(), (String) ICON_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testTextOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-opacity"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textOpacity(0.3f)); - assertEquals((Float) layer.getTextOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testTextColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getTextColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testTextColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textColor(Color.RED)); - assertEquals(layer.getTextColorAsInt(), Color.RED); - } - - @Test - public void testTextHaloColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textHaloColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getTextHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testTextHaloColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-color"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textHaloColor(Color.RED)); - assertEquals(layer.getTextHaloColorAsInt(), Color.RED); - } - - @Test - public void testTextHaloWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-width"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textHaloWidth(0.3f)); - assertEquals((Float) layer.getTextHaloWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testTextHaloBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-blur"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textHaloBlur(0.3f)); - assertEquals((Float) layer.getTextHaloBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testTextTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-translate"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testTextTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-translate-anchor"); - assertNotNull(layer); - - //Set and Get - layer.setProperties(textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index f4c50a2ffb..3b3bc9c8b5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,71 +29,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TEXT_FIT_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.SYMBOL_PLACEMENT_POINT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_CENTER; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_LEFT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_PITCH_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSFORM_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFitPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolAvoidEdges; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolPlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textFont; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textJustify; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLetterSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLineHeight; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxAngle; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPitchAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTransform; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for SymbolLayer @@ -103,12 +55,6 @@ public class SymbolLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -116,1165 +62,2984 @@ public class SymbolLayerTest extends BaseStyleTest { layer = new SymbolLayer("my-layer", "composite"); layer.setSourceLayer("composite"); mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference + // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); - //Get initial + // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); - //Set + // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } @Test - public void testSymbolPlacement() { + public void testSymbolPlacementAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("symbol-placement"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT)); assertEquals((String) layer.getSymbolPlacement().getValue(), (String) SYMBOL_PLACEMENT_POINT); } @Test - public void testSymbolSpacing() { + public void testSymbolPlacementAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("symbol-placement"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + symbolPlacement( + zoom( + interval( + stop(2, symbolPlacement(SYMBOL_PLACEMENT_POINT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getSymbolPlacement()); + assertNotNull(layer.getSymbolPlacement().getFunction()); + assertEquals(CameraFunction.class, layer.getSymbolPlacement().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getSymbolPlacement().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getSymbolPlacement().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testSymbolSpacingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("symbol-spacing"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(symbolSpacing(0.3f)); assertEquals((Float) layer.getSymbolSpacing().getValue(), (Float) 0.3f); } @Test - public void testSymbolAvoidEdges() { + public void testSymbolSpacingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("symbol-spacing"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + symbolSpacing( + zoom( + exponential( + stop(2, symbolSpacing(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getSymbolSpacing()); + assertNotNull(layer.getSymbolSpacing().getFunction()); + assertEquals(CameraFunction.class, layer.getSymbolSpacing().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getSymbolSpacing().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getSymbolSpacing().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getSymbolSpacing().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testSymbolAvoidEdgesAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("symbol-avoid-edges"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(symbolAvoidEdges(true)); assertEquals((Boolean) layer.getSymbolAvoidEdges().getValue(), (Boolean) true); } @Test - public void testIconAllowOverlap() { + public void testSymbolAvoidEdgesAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("symbol-avoid-edges"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + symbolAvoidEdges( + zoom( + interval( + stop(2, symbolAvoidEdges(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getSymbolAvoidEdges()); + assertNotNull(layer.getSymbolAvoidEdges().getFunction()); + assertEquals(CameraFunction.class, layer.getSymbolAvoidEdges().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getSymbolAvoidEdges().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getSymbolAvoidEdges().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconAllowOverlapAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-allow-overlap"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconAllowOverlap(true)); assertEquals((Boolean) layer.getIconAllowOverlap().getValue(), (Boolean) true); } @Test - public void testIconIgnorePlacement() { + public void testIconAllowOverlapAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-allow-overlap"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconAllowOverlap( + zoom( + interval( + stop(2, iconAllowOverlap(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconAllowOverlap()); + assertNotNull(layer.getIconAllowOverlap().getFunction()); + assertEquals(CameraFunction.class, layer.getIconAllowOverlap().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconAllowOverlap().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconAllowOverlap().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconIgnorePlacementAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-ignore-placement"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconIgnorePlacement(true)); assertEquals((Boolean) layer.getIconIgnorePlacement().getValue(), (Boolean) true); } @Test - public void testIconOptional() { + public void testIconIgnorePlacementAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-ignore-placement"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconIgnorePlacement( + zoom( + interval( + stop(2, iconIgnorePlacement(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconIgnorePlacement()); + assertNotNull(layer.getIconIgnorePlacement().getFunction()); + assertEquals(CameraFunction.class, layer.getIconIgnorePlacement().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconIgnorePlacement().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconIgnorePlacement().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconOptionalAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-optional"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconOptional(true)); assertEquals((Boolean) layer.getIconOptional().getValue(), (Boolean) true); } @Test - public void testIconRotationAlignment() { + public void testIconOptionalAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-optional"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconOptional( + zoom( + interval( + stop(2, iconOptional(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOptional()); + assertNotNull(layer.getIconOptional().getFunction()); + assertEquals(CameraFunction.class, layer.getIconOptional().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconOptional().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconOptional().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconRotationAlignmentAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-rotation-alignment"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); assertEquals((String) layer.getIconRotationAlignment().getValue(), (String) ICON_ROTATION_ALIGNMENT_MAP); } @Test - public void testIconSize() { + public void testIconRotationAlignmentAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotation-alignment"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconRotationAlignment( + zoom( + interval( + stop(2, iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotationAlignment()); + assertNotNull(layer.getIconRotationAlignment().getFunction()); + assertEquals(CameraFunction.class, layer.getIconRotationAlignment().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconRotationAlignment().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconRotationAlignment().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconSizeAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-size"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconSize(0.3f)); assertEquals((Float) layer.getIconSize().getValue(), (Float) 0.3f); } @Test - public void testIconTextFit() { + public void testIconSizeAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-size"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconSize( + zoom( + exponential( + stop(2, iconSize(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconSize()); + assertNotNull(layer.getIconSize().getFunction()); + assertEquals(CameraFunction.class, layer.getIconSize().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconSize().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconSize().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconSize().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTextFitAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-text-fit"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconTextFit(ICON_TEXT_FIT_NONE)); assertEquals((String) layer.getIconTextFit().getValue(), (String) ICON_TEXT_FIT_NONE); } @Test - public void testIconTextFitPadding() { + public void testIconTextFitAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-text-fit"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTextFit( + zoom( + interval( + stop(2, iconTextFit(ICON_TEXT_FIT_NONE)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTextFit()); + assertNotNull(layer.getIconTextFit().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTextFit().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconTextFit().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconTextFit().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTextFitPaddingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-text-fit-padding"); assertNotNull(layer); - //Set and Get - layer.setProperties(iconTextFitPadding(new Float[] {0f, 0f, 0f, 0f})); - assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); + // Set and Get + layer.setProperties(iconTextFitPadding(new Float[]{0f,0f,0f,0f})); + assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[]{0f,0f,0f,0f}); } @Test - public void testIconImage() { + public void testIconTextFitPaddingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-text-fit-padding"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTextFitPadding( + zoom( + exponential( + stop(2, iconTextFitPadding(new Float[]{0f,0f,0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTextFitPadding()); + assertNotNull(layer.getIconTextFitPadding().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTextFitPadding().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconTextFitPadding().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconTextFitPadding().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconTextFitPadding().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconImageAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-image"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconImage("undefined")); assertEquals((String) layer.getIconImage().getValue(), (String) "undefined"); } @Test - public void testIconRotate() { + public void testIconImageAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-image"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconImage( + zoom( + interval( + stop(2, iconImage("undefined")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconImage()); + assertNotNull(layer.getIconImage().getFunction()); + assertEquals(CameraFunction.class, layer.getIconImage().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconImage().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconImage().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconRotateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-rotate"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconRotate(0.3f)); assertEquals((Float) layer.getIconRotate().getValue(), (Float) 0.3f); } @Test - public void testIconPadding() { + public void testIconRotateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconRotate( + zoom( + exponential( + stop(2, iconRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(CameraFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconRotate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconRotate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconRotateAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconRotate(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + } + + @Test + public void testIconRotateAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconRotate( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, iconRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + } + + @Test + public void testIconRotateAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconRotate( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, iconRotate(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue()); + } + + @Test + public void testIconRotateAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconRotate( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, iconRotate(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(CompositeFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getIconRotate().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getIconRotate().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testIconPaddingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-padding"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconPadding(0.3f)); assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); } @Test - public void testIconKeepUpright() { + public void testIconPaddingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-padding"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconPadding( + zoom( + exponential( + stop(2, iconPadding(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconPadding()); + assertNotNull(layer.getIconPadding().getFunction()); + assertEquals(CameraFunction.class, layer.getIconPadding().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconPadding().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconPadding().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconPadding().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconKeepUprightAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-keep-upright"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconKeepUpright(true)); assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); } @Test - public void testIconOffset() { + public void testIconKeepUprightAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-keep-upright"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconKeepUpright( + zoom( + interval( + stop(2, iconKeepUpright(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconKeepUpright()); + assertNotNull(layer.getIconKeepUpright().getFunction()); + assertEquals(CameraFunction.class, layer.getIconKeepUpright().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconKeepUpright().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconKeepUpright().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconOffsetAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-offset"); assertNotNull(layer); - //Set and Get - layer.setProperties(iconOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(iconOffset(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testTextPitchAlignment() { + public void testIconOffsetAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconOffset( + zoom( + exponential( + stop(2, iconOffset(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOffset()); + assertNotNull(layer.getIconOffset().getFunction()); + assertEquals(CameraFunction.class, layer.getIconOffset().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconOffset().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconOffset().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconOffset().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconOffsetAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOffset(property("FeaturePropertyA", Stops.<Float[]>identity())) + ); + + // Verify + assertNotNull(layer.getIconOffset()); + assertNotNull(layer.getIconOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOffset().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconOffset().getFunction().getStops().getClass()); + } + + @Test + public void testIconOffsetAsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOffset( + property( + "FeaturePropertyA", + interval( + stop(1, iconOffset(new Float[]{0f,0f})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOffset()); + assertNotNull(layer.getIconOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOffset().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getIconOffset().getFunction().getStops().getClass()); + } + + @Test + public void testTextPitchAlignmentAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-pitch-alignment"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)); assertEquals((String) layer.getTextPitchAlignment().getValue(), (String) TEXT_PITCH_ALIGNMENT_MAP); } @Test - public void testTextRotationAlignment() { + public void testTextPitchAlignmentAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-pitch-alignment"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textPitchAlignment( + zoom( + interval( + stop(2, textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextPitchAlignment()); + assertNotNull(layer.getTextPitchAlignment().getFunction()); + assertEquals(CameraFunction.class, layer.getTextPitchAlignment().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextPitchAlignment().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextPitchAlignment().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextRotationAlignmentAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-rotation-alignment"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)); assertEquals((String) layer.getTextRotationAlignment().getValue(), (String) TEXT_ROTATION_ALIGNMENT_MAP); } @Test - public void testTextField() { + public void testTextRotationAlignmentAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotation-alignment"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textRotationAlignment( + zoom( + interval( + stop(2, textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextRotationAlignment()); + assertNotNull(layer.getTextRotationAlignment().getFunction()); + assertEquals(CameraFunction.class, layer.getTextRotationAlignment().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextRotationAlignment().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextRotationAlignment().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextFieldAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-field"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textField("")); assertEquals((String) layer.getTextField().getValue(), (String) ""); } @Test - public void testTextFont() { + public void testTextFieldAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-field"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textField( + zoom( + interval( + stop(2, textField("")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextField()); + assertNotNull(layer.getTextField().getFunction()); + assertEquals(CameraFunction.class, layer.getTextField().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextField().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextField().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextFieldAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-field"); + assertNotNull(layer); + + // Set + layer.setProperties( + textField(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getTextField()); + assertNotNull(layer.getTextField().getFunction()); + assertEquals(SourceFunction.class, layer.getTextField().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextField().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextField().getFunction().getStops().getClass()); + } + + @Test + public void testTextFieldAsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-field"); + assertNotNull(layer); + + // Set + layer.setProperties( + textField( + property( + "FeaturePropertyA", + interval( + stop(1, textField("")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextField()); + assertNotNull(layer.getTextField().getFunction()); + assertEquals(SourceFunction.class, layer.getTextField().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextField().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getTextField().getFunction().getStops().getClass()); + } + + @Test + public void testTextFontAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-font"); assertNotNull(layer); - //Set and Get - layer.setProperties(textFont(new String[] {"Open Sans Regular", "Arial Unicode MS Regular"})); - assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[] {"Open Sans Regular", - "Arial Unicode MS Regular"}); + // Set and Get + layer.setProperties(textFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"})); + assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[]{"Open Sans Regular", "Arial Unicode MS Regular"}); } @Test - public void testTextSize() { + public void testTextFontAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-font"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textFont( + zoom( + interval( + stop(2, textFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextFont()); + assertNotNull(layer.getTextFont().getFunction()); + assertEquals(CameraFunction.class, layer.getTextFont().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextFont().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextFont().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextSizeAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-size"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textSize(0.3f)); assertEquals((Float) layer.getTextSize().getValue(), (Float) 0.3f); } @Test - public void testTextMaxWidth() { + public void testTextSizeAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-size"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textSize( + zoom( + exponential( + stop(2, textSize(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextSize()); + assertNotNull(layer.getTextSize().getFunction()); + assertEquals(CameraFunction.class, layer.getTextSize().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextSize().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextSize().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextSize().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextMaxWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-max-width"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textMaxWidth(0.3f)); assertEquals((Float) layer.getTextMaxWidth().getValue(), (Float) 0.3f); } @Test - public void testTextLineHeight() { + public void testTextMaxWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-max-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textMaxWidth( + zoom( + exponential( + stop(2, textMaxWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextMaxWidth()); + assertNotNull(layer.getTextMaxWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getTextMaxWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextMaxWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextMaxWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextMaxWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextLineHeightAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-line-height"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textLineHeight(0.3f)); assertEquals((Float) layer.getTextLineHeight().getValue(), (Float) 0.3f); } @Test - public void testTextLetterSpacing() { + public void testTextLineHeightAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-line-height"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textLineHeight( + zoom( + exponential( + stop(2, textLineHeight(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextLineHeight()); + assertNotNull(layer.getTextLineHeight().getFunction()); + assertEquals(CameraFunction.class, layer.getTextLineHeight().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextLineHeight().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextLineHeight().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextLineHeight().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextLetterSpacingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-letter-spacing"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textLetterSpacing(0.3f)); assertEquals((Float) layer.getTextLetterSpacing().getValue(), (Float) 0.3f); } @Test - public void testTextJustify() { + public void testTextLetterSpacingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-letter-spacing"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textLetterSpacing( + zoom( + exponential( + stop(2, textLetterSpacing(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextLetterSpacing()); + assertNotNull(layer.getTextLetterSpacing().getFunction()); + assertEquals(CameraFunction.class, layer.getTextLetterSpacing().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextLetterSpacing().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextLetterSpacing().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextLetterSpacing().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextJustifyAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-justify"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textJustify(TEXT_JUSTIFY_LEFT)); assertEquals((String) layer.getTextJustify().getValue(), (String) TEXT_JUSTIFY_LEFT); } @Test - public void testTextAnchor() { + public void testTextJustifyAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-justify"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textJustify( + zoom( + interval( + stop(2, textJustify(TEXT_JUSTIFY_LEFT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextJustify()); + assertNotNull(layer.getTextJustify().getFunction()); + assertEquals(CameraFunction.class, layer.getTextJustify().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextJustify().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextJustify().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-anchor"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textAnchor(TEXT_ANCHOR_CENTER)); assertEquals((String) layer.getTextAnchor().getValue(), (String) TEXT_ANCHOR_CENTER); } @Test - public void testTextMaxAngle() { + public void testTextAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textAnchor( + zoom( + interval( + stop(2, textAnchor(TEXT_ANCHOR_CENTER)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextAnchor()); + assertNotNull(layer.getTextAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextMaxAngleAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-max-angle"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textMaxAngle(0.3f)); assertEquals((Float) layer.getTextMaxAngle().getValue(), (Float) 0.3f); } @Test - public void testTextRotate() { + public void testTextMaxAngleAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-max-angle"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textMaxAngle( + zoom( + exponential( + stop(2, textMaxAngle(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextMaxAngle()); + assertNotNull(layer.getTextMaxAngle().getFunction()); + assertEquals(CameraFunction.class, layer.getTextMaxAngle().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextMaxAngle().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextMaxAngle().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextMaxAngle().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextRotateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-rotate"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textRotate(0.3f)); assertEquals((Float) layer.getTextRotate().getValue(), (Float) 0.3f); } @Test - public void testTextPadding() { + public void testTextRotateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textRotate( + zoom( + exponential( + stop(2, textRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextRotate()); + assertNotNull(layer.getTextRotate().getFunction()); + assertEquals(CameraFunction.class, layer.getTextRotate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextRotate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextPaddingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-padding"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textPadding(0.3f)); assertEquals((Float) layer.getTextPadding().getValue(), (Float) 0.3f); } @Test - public void testTextKeepUpright() { + public void testTextPaddingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-padding"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textPadding( + zoom( + exponential( + stop(2, textPadding(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextPadding()); + assertNotNull(layer.getTextPadding().getFunction()); + assertEquals(CameraFunction.class, layer.getTextPadding().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextPadding().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextPadding().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextPadding().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextKeepUprightAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-keep-upright"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textKeepUpright(true)); assertEquals((Boolean) layer.getTextKeepUpright().getValue(), (Boolean) true); } @Test - public void testTextTransform() { + public void testTextKeepUprightAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-keep-upright"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textKeepUpright( + zoom( + interval( + stop(2, textKeepUpright(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextKeepUpright()); + assertNotNull(layer.getTextKeepUpright().getFunction()); + assertEquals(CameraFunction.class, layer.getTextKeepUpright().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextKeepUpright().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextKeepUpright().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextTransformAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-transform"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textTransform(TEXT_TRANSFORM_NONE)); assertEquals((String) layer.getTextTransform().getValue(), (String) TEXT_TRANSFORM_NONE); } @Test - public void testTextOffset() { + public void testTextTransformAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-transform"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textTransform( + zoom( + interval( + stop(2, textTransform(TEXT_TRANSFORM_NONE)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTransform()); + assertNotNull(layer.getTextTransform().getFunction()); + assertEquals(CameraFunction.class, layer.getTextTransform().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextTransform().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextTransform().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextTransformAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-transform"); + assertNotNull(layer); + + // Set + layer.setProperties( + textTransform(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getTextTransform()); + assertNotNull(layer.getTextTransform().getFunction()); + assertEquals(SourceFunction.class, layer.getTextTransform().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextTransform().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextTransform().getFunction().getStops().getClass()); + } + + @Test + public void testTextTransformAsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-transform"); + assertNotNull(layer); + + // Set + layer.setProperties( + textTransform( + property( + "FeaturePropertyA", + interval( + stop(1, textTransform(TEXT_TRANSFORM_NONE)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTransform()); + assertNotNull(layer.getTextTransform().getFunction()); + assertEquals(SourceFunction.class, layer.getTextTransform().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextTransform().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getTextTransform().getFunction().getStops().getClass()); + } + + @Test + public void testTextOffsetAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-offset"); assertNotNull(layer); - //Set and Get - layer.setProperties(textOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(textOffset(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testTextAllowOverlap() { + public void testTextOffsetAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-offset"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textOffset( + zoom( + exponential( + stop(2, textOffset(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOffset()); + assertNotNull(layer.getTextOffset().getFunction()); + assertEquals(CameraFunction.class, layer.getTextOffset().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextOffset().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextOffset().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextOffset().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextAllowOverlapAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-allow-overlap"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textAllowOverlap(true)); assertEquals((Boolean) layer.getTextAllowOverlap().getValue(), (Boolean) true); } @Test - public void testTextIgnorePlacement() { + public void testTextAllowOverlapAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-allow-overlap"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textAllowOverlap( + zoom( + interval( + stop(2, textAllowOverlap(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextAllowOverlap()); + assertNotNull(layer.getTextAllowOverlap().getFunction()); + assertEquals(CameraFunction.class, layer.getTextAllowOverlap().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextAllowOverlap().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextAllowOverlap().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextIgnorePlacementAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-ignore-placement"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textIgnorePlacement(true)); assertEquals((Boolean) layer.getTextIgnorePlacement().getValue(), (Boolean) true); } @Test - public void testTextOptional() { + public void testTextIgnorePlacementAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-ignore-placement"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textIgnorePlacement( + zoom( + interval( + stop(2, textIgnorePlacement(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextIgnorePlacement()); + assertNotNull(layer.getTextIgnorePlacement().getFunction()); + assertEquals(CameraFunction.class, layer.getTextIgnorePlacement().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextIgnorePlacement().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextIgnorePlacement().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextOptionalAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-optional"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textOptional(true)); assertEquals((Boolean) layer.getTextOptional().getValue(), (Boolean) true); } @Test - public void testIconOpacity() { + public void testTextOptionalAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-optional"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textOptional( + zoom( + interval( + stop(2, textOptional(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOptional()); + assertNotNull(layer.getTextOptional().getFunction()); + assertEquals(CameraFunction.class, layer.getTextOptional().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextOptional().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextOptional().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconOpacity(0.3f)); assertEquals((Float) layer.getIconOpacity().getValue(), (Float) 0.3f); } @Test - public void testIconColor() { + public void testIconOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconOpacity( + zoom( + exponential( + stop(2, iconOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOpacity()); + assertNotNull(layer.getIconOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getIconOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOpacity(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getIconOpacity()); + assertNotNull(layer.getIconOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testIconOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, iconOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOpacity()); + assertNotNull(layer.getIconOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testIconOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, iconOpacity(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconOpacity()); + assertNotNull(layer.getIconOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue()); + } + + @Test + public void testIconOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, iconOpacity(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconOpacity()); + assertNotNull(layer.getIconOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getIconOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getIconOpacity().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getIconOpacity().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testIconColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getIconColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testIconColorAsInt() { + public void testIconColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconColor( + zoom( + exponential( + stop(2, iconColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconColor()); + assertNotNull(layer.getIconColor().getFunction()); + assertEquals(CameraFunction.class, layer.getIconColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(iconColor(Color.RED)); - assertEquals(layer.getIconColorAsInt(), Color.RED); + // Set + layer.setProperties( + iconColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getIconColor()); + assertNotNull(layer.getIconColor().getFunction()); + assertEquals(SourceFunction.class, layer.getIconColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconColor().getFunction().getStops().getClass()); } @Test - public void testIconHaloColor() { + public void testIconColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, iconColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconColor()); + assertNotNull(layer.getIconColor().getFunction()); + assertEquals(SourceFunction.class, layer.getIconColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", iconColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconColor()); + assertNotNull(layer.getIconColor().getFunction()); + assertEquals(SourceFunction.class, layer.getIconColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconColor().getFunction().getStops().getClass()); + } + + @Test + public void testIconColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconColor(Color.RED)); + assertEquals(layer.getIconColorAsInt(), Color.RED); + } + + @Test + public void testIconHaloColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-halo-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconHaloColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getIconHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testIconHaloColorAsInt() { + public void testIconHaloColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloColor( + zoom( + exponential( + stop(2, iconHaloColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloColor()); + assertNotNull(layer.getIconHaloColor().getFunction()); + assertEquals(CameraFunction.class, layer.getIconHaloColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconHaloColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconHaloColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconHaloColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconHaloColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-halo-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(iconHaloColor(Color.RED)); - assertEquals(layer.getIconHaloColorAsInt(), Color.RED); + // Set + layer.setProperties( + iconHaloColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getIconHaloColor()); + assertNotNull(layer.getIconHaloColor().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconHaloColor().getFunction().getStops().getClass()); } @Test - public void testIconHaloWidth() { + public void testIconHaloColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, iconHaloColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloColor()); + assertNotNull(layer.getIconHaloColor().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconHaloColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconHaloColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", iconHaloColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloColor()); + assertNotNull(layer.getIconHaloColor().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconHaloColor().getFunction().getStops().getClass()); + } + + @Test + public void testIconHaloColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconHaloColor(Color.RED)); + assertEquals(layer.getIconHaloColorAsInt(), Color.RED); + } + + @Test + public void testIconHaloWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-halo-width"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconHaloWidth(0.3f)); assertEquals((Float) layer.getIconHaloWidth().getValue(), (Float) 0.3f); } @Test - public void testIconHaloBlur() { + public void testIconHaloWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloWidth( + zoom( + exponential( + stop(2, iconHaloWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloWidth()); + assertNotNull(layer.getIconHaloWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getIconHaloWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconHaloWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconHaloWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconHaloWidthAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloWidth(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getIconHaloWidth()); + assertNotNull(layer.getIconHaloWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloWidth().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); + } + + @Test + public void testIconHaloWidthAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloWidth( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, iconHaloWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloWidth()); + assertNotNull(layer.getIconHaloWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); + } + + @Test + public void testIconHaloWidthAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloWidth( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, iconHaloWidth(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloWidth()); + assertNotNull(layer.getIconHaloWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloWidth().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue()); + } + + @Test + public void testIconHaloWidthAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloWidth( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, iconHaloWidth(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloWidth()); + assertNotNull(layer.getIconHaloWidth().getFunction()); + assertEquals(CompositeFunction.class, layer.getIconHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconHaloWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getIconHaloWidth().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getIconHaloWidth().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testIconHaloBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-halo-blur"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconHaloBlur(0.3f)); assertEquals((Float) layer.getIconHaloBlur().getValue(), (Float) 0.3f); } @Test - public void testIconTranslate() { + public void testIconHaloBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloBlur( + zoom( + exponential( + stop(2, iconHaloBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloBlur()); + assertNotNull(layer.getIconHaloBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getIconHaloBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconHaloBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconHaloBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconHaloBlurAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloBlur(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getIconHaloBlur()); + assertNotNull(layer.getIconHaloBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloBlur().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); + } + + @Test + public void testIconHaloBlurAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloBlur( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, iconHaloBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloBlur()); + assertNotNull(layer.getIconHaloBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); + } + + @Test + public void testIconHaloBlurAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloBlur( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, iconHaloBlur(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloBlur()); + assertNotNull(layer.getIconHaloBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getIconHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloBlur().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue()); + } + + @Test + public void testIconHaloBlurAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconHaloBlur( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, iconHaloBlur(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloBlur()); + assertNotNull(layer.getIconHaloBlur().getFunction()); + assertEquals(CompositeFunction.class, layer.getIconHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconHaloBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getIconHaloBlur().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getIconHaloBlur().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testIconTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-translate"); assertNotNull(layer); - //Set and Get - layer.setProperties(iconTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(iconTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testIconTranslateAnchor() { + public void testIconTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTranslate( + zoom( + exponential( + stop(2, iconTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTranslate()); + assertNotNull(layer.getIconTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-translate-anchor"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)); assertEquals((String) layer.getIconTranslateAnchor().getValue(), (String) ICON_TRANSLATE_ANCHOR_MAP); } @Test - public void testTextOpacity() { + public void testIconTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTranslateAnchor( + zoom( + interval( + stop(2, iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTranslateAnchor()); + assertNotNull(layer.getIconTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-opacity"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textOpacity(0.3f)); assertEquals((Float) layer.getTextOpacity().getValue(), (Float) 0.3f); } @Test - public void testTextColor() { + public void testTextOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textOpacity( + zoom( + exponential( + stop(2, textOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOpacity()); + assertNotNull(layer.getTextOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getTextOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOpacity(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getTextOpacity()); + assertNotNull(layer.getTextOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testTextOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, textOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOpacity()); + assertNotNull(layer.getTextOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testTextOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, textOpacity(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getTextOpacity()); + assertNotNull(layer.getTextOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue()); + } + + @Test + public void testTextOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, textOpacity(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getTextOpacity()); + assertNotNull(layer.getTextOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getTextOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getTextOpacity().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextOpacity().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testTextColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getTextColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testTextColorAsInt() { + public void testTextColorAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + textColor( + zoom( + exponential( + stop(2, textColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextColor()); + assertNotNull(layer.getTextColor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextColor().getFunction().getStops()).size()); + } + + @Test + public void testTextColorAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getTextColor()); + assertNotNull(layer.getTextColor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextColorAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(textColor(Color.RED)); - assertEquals(layer.getTextColorAsInt(), Color.RED); + // Set + layer.setProperties( + textColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, textColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextColor()); + assertNotNull(layer.getTextColor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextColor().getFunction().getStops().getClass()); } @Test - public void testTextHaloColor() { + public void testTextColorAsCategoricalSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", textColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextColor()); + assertNotNull(layer.getTextColor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getTextColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(textColor(Color.RED)); + assertEquals(layer.getTextColorAsInt(), Color.RED); + } + + @Test + public void testTextHaloColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-halo-color"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textHaloColor("rgba(0, 0, 0, 1)")); assertEquals((String) layer.getTextHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } @Test - public void testTextHaloColorAsInt() { + public void testTextHaloColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloColor( + zoom( + exponential( + stop(2, textHaloColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloColor()); + assertNotNull(layer.getTextHaloColor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextHaloColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextHaloColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextHaloColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextHaloColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextHaloColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-halo-color"); assertNotNull(layer); - //Set and Get - layer.setProperties(textHaloColor(Color.RED)); - assertEquals(layer.getTextHaloColorAsInt(), Color.RED); + // Set + layer.setProperties( + textHaloColor(property("FeaturePropertyA", Stops.<String>identity())) + ); + + // Verify + assertNotNull(layer.getTextHaloColor()); + assertNotNull(layer.getTextHaloColor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextHaloColor().getFunction().getStops().getClass()); } @Test - public void testTextHaloWidth() { + public void testTextHaloColorAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, textHaloColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloColor()); + assertNotNull(layer.getTextHaloColor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextHaloColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextHaloColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", textHaloColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloColor()); + assertNotNull(layer.getTextHaloColor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getTextHaloColor().getFunction().getStops().getClass()); + } + + @Test + public void testTextHaloColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-color"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(textHaloColor(Color.RED)); + assertEquals(layer.getTextHaloColorAsInt(), Color.RED); + } + + @Test + public void testTextHaloWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-halo-width"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textHaloWidth(0.3f)); assertEquals((Float) layer.getTextHaloWidth().getValue(), (Float) 0.3f); } @Test - public void testTextHaloBlur() { + public void testTextHaloWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloWidth( + zoom( + exponential( + stop(2, textHaloWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloWidth()); + assertNotNull(layer.getTextHaloWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getTextHaloWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextHaloWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextHaloWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextHaloWidthAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloWidth(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getTextHaloWidth()); + assertNotNull(layer.getTextHaloWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloWidth().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); + } + + @Test + public void testTextHaloWidthAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloWidth( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, textHaloWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloWidth()); + assertNotNull(layer.getTextHaloWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); + } + + @Test + public void testTextHaloWidthAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloWidth( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, textHaloWidth(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloWidth()); + assertNotNull(layer.getTextHaloWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloWidth().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue()); + } + + @Test + public void testTextHaloWidthAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloWidth( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, textHaloWidth(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloWidth()); + assertNotNull(layer.getTextHaloWidth().getFunction()); + assertEquals(CompositeFunction.class, layer.getTextHaloWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextHaloWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getTextHaloWidth().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextHaloWidth().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testTextHaloBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-halo-blur"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textHaloBlur(0.3f)); assertEquals((Float) layer.getTextHaloBlur().getValue(), (Float) 0.3f); } @Test - public void testTextTranslate() { + public void testTextHaloBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloBlur( + zoom( + exponential( + stop(2, textHaloBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloBlur()); + assertNotNull(layer.getTextHaloBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getTextHaloBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextHaloBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextHaloBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextHaloBlurAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloBlur(property("FeaturePropertyA", Stops.<Float>identity())) + ); + + // Verify + assertNotNull(layer.getTextHaloBlur()); + assertNotNull(layer.getTextHaloBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloBlur().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); + } + + @Test + public void testTextHaloBlurAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloBlur( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, textHaloBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloBlur()); + assertNotNull(layer.getTextHaloBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); + } + + @Test + public void testTextHaloBlurAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloBlur( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, textHaloBlur(0.3f)) + ) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloBlur()); + assertNotNull(layer.getTextHaloBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getTextHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloBlur().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); + assertEquals(0.3f, ((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue()); + } + + @Test + public void testTextHaloBlurAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + textHaloBlur( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, textHaloBlur(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(0.3f) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloBlur()); + assertNotNull(layer.getTextHaloBlur().getFunction()); + assertEquals(CompositeFunction.class, layer.getTextHaloBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextHaloBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getTextHaloBlur().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = + (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextHaloBlur().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + + @Test + public void testTextTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-translate"); assertNotNull(layer); - //Set and Get - layer.setProperties(textTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + // Set and Get + layer.setProperties(textTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testTextTranslateAnchor() { + public void testTextTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textTranslate( + zoom( + exponential( + stop(2, textTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTranslate()); + assertNotNull(layer.getTextTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getTextTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-translate-anchor"); assertNotNull(layer); - //Set and Get + // Set and Get layer.setProperties(textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)); assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); } + @Test + public void testTextTranslateAnchorAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-translate-anchor"); + assertNotNull(layer); + + // Set + layer.setProperties( + textTranslateAnchor( + zoom( + interval( + stop(2, textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTranslateAnchor()); + assertNotNull(layer.getTextTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextTranslateAnchor().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs index 3b81b0805b..f1d68caa24 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs @@ -3,6 +3,7 @@ const properties = locals.properties; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; @@ -12,6 +13,15 @@ import android.support.test.runner.AndroidJUnit4; import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -23,6 +33,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; @@ -33,112 +46,308 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; @RunWith(AndroidJUnit4.class) public class <%- camelize(type) %>LayerTest extends BaseStyleTest { - @Rule - public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); + @Rule + public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); + + private <%- camelize(type) %>Layer layer; - private <%- camelize(type) %>Layer layer; + private OnMapReadyIdlingResource idlingResource; - private OnMapReadyIdlingResource idlingResource; + private MapboxMap mapboxMap; - private MapboxMap mapboxMap; + @Before + public void setup() { + idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); + Espresso.registerIdlingResources(idlingResource); + mapboxMap = rule.getActivity().getMapboxMap(); - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); +<% if (type === 'background') { -%> + Timber.i("Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); +<% } else { -%> + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new <%- camelize(type) %>Layer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); } +<% } -%> + } - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); -<% if (type === 'background') { -%> - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + } + +<% for (const property of properties) { -%> + @Test + public void test<%- camelize(property.name) %>AsConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)); + assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>); + } +<% if (supportsZoomFunction(property)) { -%> + + @Test + public void test<%- camelize(property.name) %>AsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + zoom( +<% if (property.function == 'piecewise-constant') { -%> + interval( + stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ) <% } else { -%> - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new <%- camelize(type) %>Layer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + exponential( + stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ).withBase(0.5f) <% } -%> - Timber.i("visibility"); - assertNotNull(layer); + ) + ) + ); - //Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(CameraFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); +<% if (property.function == 'piecewise-constant') { -%> + assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size()); +<% } else { -%> + assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size()); +<% } -%> + } +<% } -%> +<% if (supportsPropertyFunction(property)) { -%> - //Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + @Test + public void test<%- camelize(property.name) %>AsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); -<% for (const property of properties) { -%> - @Test - public void test<%- camelize(property.name) %>() { - checkViewIsDisplayed(R.id.mapView); + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>(property("FeaturePropertyA", Stops.<<%- propertyType(property) %>>identity())) + ); - mapboxMap = rule.getActivity().getMapboxMap(); + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + } +<% if (property.function == 'piecewise-constant') { -%> -<% if (type === 'background') { -%> - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void test<%- camelize(property.name) %>AsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + property( + "FeaturePropertyA", + interval( +<% if (property.type == 'color') { -%> + stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) +<% } else {-%> + stop(1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ) +<% } -%> + ) + ) + ); + + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + } +<% } else if (property.type === 'array') { -%> + + @Test + public void test<%- camelize(property.name) %>AsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + property( + "FeaturePropertyA", + interval( +<% if (property.type == 'color') { -%> + stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) +<% } else {-%> + stop(1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) +<% } -%> + ) + ) + ) + ); + + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + } <% } else { -%> - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new <%- camelize(type) %>Layer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + + @Test + public void test<%- camelize(property.name) %>AsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + property( + "FeaturePropertyA", + exponential( +<% if (property.type == 'color') { -%> + stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) +<% } else {-%> + stop(<%- defaultValueJava(property) %>, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) <% } -%> - Timber.i("<%- property.name %>"); - assertNotNull(layer); + ).withBase(0.5f) + ) + ) + ); - //Set and Get - layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)); - assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>); - } + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + } + + @Test + public void test<%- camelize(property.name) %>AsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + property( + "FeaturePropertyA", + categorical( <% if (property.type == 'color') { -%> + stop("valueA", <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) + ) + ) +<% } else {-%> + stop(1.0f, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ) + ).withDefaultValue(<%- defaultValueJava(property) %>) +<% } -%> + ) + ); - @Test - public void test<%- camelize(property.name) %>AsInt() { - checkViewIsDisplayed(R.id.mapView); + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); +<% if (property.type !== 'color') { -%> + assertEquals(<%- defaultValueJava(property) %>, ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue()); +<% } -%> + } +<% if (property.type !== 'color') { -%> - mapboxMap = rule.getActivity().getMapboxMap(); + @Test + public void test<%- camelize(property.name) %>AsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); -<% if (type === 'background') { -%> - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, <%- camelizeWithLeadingLowercase(property.name) %>(0.9f)) + ).withBase(0.5f) +<% if (property.type == 'number') { -%> + ).withDefaultValue(<%- defaultValueJava(property) %>) <% } else { -%> - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new <%- camelize(type) %>Layer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - //Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + ) <% } -%> - Timber.i("<%- property.name %>"); - assertNotNull(layer); + ) + ); - //Set and Get - layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); - assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); - } + // Verify + assertNotNull(layer.get<%- camelize(property.name) %>()); + assertNotNull(layer.get<%- camelize(property.name) %>().getFunction()); + assertEquals(CompositeFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size()); + + ExponentialStops<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>> stops = + (ExponentialStops<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>>) layer.get<%- camelize(property.name) %>().getFunction().getStops(); + Stop<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } +<% } -%> +<% } -%> +<% } -%> +<% if (property.type == 'color') { -%> + + @Test + public void test<%- camelize(property.name) %>AsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); + assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); + } <% } -%> <% } -%> - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } + @After + public void unregisterIntentServiceIdlingResource() { + Espresso.unregisterIdlingResources(idlingResource); + } } |