diff options
author | Tobrun <tobrun@mapbox.com> | 2018-03-08 16:27:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-08 16:27:02 +0100 |
commit | 6179110b6bfe8ee0880a055a31c12a88f9bd9b20 (patch) | |
tree | 0614f3075eab65c36c9a668117a2d51d612657f3 /platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk | |
parent | dfdfbc09902cdb592d217d3e264f736ce5217926 (diff) | |
download | qtlocation-mapboxgl-6179110b6bfe8ee0880a055a31c12a88f9bd9b20.tar.gz |
[android] - add expression conversion, add getters (#11352)
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk')
13 files changed, 1911 insertions, 10618 deletions
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 0e4cf6a8ca..2d16291832 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 @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,11 +38,8 @@ public class BackgroundLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - layer = mapboxMap.getLayerAs("background"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + layer = mapboxMap.getLayerAs("background"); }); } @@ -64,18 +48,15 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -84,16 +65,13 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setBackgroundColorTransition(options); - assertEquals(layer.getBackgroundColorTransition(), options); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBackgroundColorTransition(options); + assertEquals(layer.getBackgroundColorTransition(), options); }); } @@ -102,47 +80,12 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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 testBackgroundColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("background-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)"); }); } @@ -151,15 +94,12 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Set and Get - layer.setProperties(backgroundColor(Color.RED)); - assertEquals(layer.getBackgroundColorAsInt(), Color.RED); - } + // Set and Get + layer.setProperties(backgroundColor(Color.RED)); + assertEquals(layer.getBackgroundColorAsInt(), Color.RED); }); } @@ -168,16 +108,13 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-patternTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setBackgroundPatternTransition(options); - assertEquals(layer.getBackgroundPatternTransition(), options); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBackgroundPatternTransition(options); + assertEquals(layer.getBackgroundPatternTransition(), options); }); } @@ -186,46 +123,12 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(backgroundPattern("pedestrian-polygon")); - assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon"); - } - }); - } - - @Test - public void testBackgroundPatternAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("background-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - backgroundPattern( - zoom( - interval( - stop(2, backgroundPattern("pedestrian-polygon")) - ) - ) - ) - ); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // 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()); - } + // Set and Get + layer.setProperties(backgroundPattern("pedestrian-polygon")); + assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon"); }); } @@ -234,16 +137,13 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setBackgroundOpacityTransition(options); - assertEquals(layer.getBackgroundOpacityTransition(), options); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBackgroundOpacityTransition(options); + assertEquals(layer.getBackgroundOpacityTransition(), options); }); } @@ -252,48 +152,12 @@ public class BackgroundLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("background-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(backgroundOpacity(0.3f)); - assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); - } - }); - } - - @Test - public void testBackgroundOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("background-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - backgroundOpacity( - zoom( - exponential( - stop(2, backgroundOpacity(0.3f)) - ).withBase(0.5f) - ) - ) - ); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // 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()); - } + // Set and Get + layer.setProperties(backgroundOpacity(0.3f)); + assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); }); } - -} +}
\ No newline at end of file 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 559e446307..0460a59534 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 @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.CircleLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class CircleLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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"); } }); } @@ -71,18 +55,15 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,19 +72,16 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); - - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } @@ -112,216 +90,58 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-radiusTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleRadiusTransition(options); - assertEquals(layer.getCircleRadiusTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleRadiusAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleRadius(0.3f)); - assertEquals((Float) layer.getCircleRadius().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleRadiusTransition(options); + assertEquals(layer.getCircleRadiusTransition(), options); }); } @Test - public void testCircleRadiusAsCameraFunction() { + public void testCircleRadiusAsConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleRadiusAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(circleRadius(0.3f)); + assertEquals((Float) layer.getCircleRadius().getValue(), (Float) 0.3f); }); } @Test - public void testCircleRadiusAsExponentialSourceFunction() { + public void testCircleRadiusAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("circle-radius-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleRadiusAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleRadius( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, circleRadius(0.3f)) - ) - ).withDefaultValue(circleRadius(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()); - assertNotNull(((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleRadius(expression)); + assertEquals(layer.getCircleRadius().getExpression(), expression); }); - } - @Test - public void testCircleRadiusAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleRadius( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, circleRadius(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(circleRadius(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 testCircleColorTransition() { validateTestSetup(); setupLayer(); Timber.i("circle-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleColorTransition(options); - assertEquals(layer.getCircleColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleColorTransition(options); + assertEquals(layer.getCircleColorTransition(), options); }); } @@ -330,157 +150,42 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getCircleColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testCircleColorAsIdentitySourceFunction() { + public void testCircleColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("circle-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(circleColor(expression)); + assertEquals(layer.getCircleColor().getExpression(), expression); }); } - @Test - public void testCircleColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", circleColor(Color.RED)) - ) - ).withDefaultValue(circleColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getCircleColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getCircleColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testCircleColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleColor(Color.RED)); - assertEquals(layer.getCircleColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleColor(Color.RED)); + assertEquals(layer.getCircleColorAsInt(), Color.RED); }); } @@ -489,416 +194,103 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-blurTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleBlurTransition(options); - assertEquals(layer.getCircleBlurTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleBlurAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleBlur(0.3f)); - assertEquals((Float) layer.getCircleBlur().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleBlurTransition(options); + assertEquals(layer.getCircleBlurTransition(), options); }); } @Test - public void testCircleBlurAsCameraFunction() { + public void testCircleBlurAsConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleBlurAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(circleBlur(0.3f)); + assertEquals((Float) layer.getCircleBlur().getValue(), (Float) 0.3f); }); } @Test - public void testCircleBlurAsExponentialSourceFunction() { + public void testCircleBlurAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("circle-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleBlurAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleBlur( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, circleBlur(0.3f)) - ) - ).withDefaultValue(circleBlur(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()); - assertNotNull(((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleBlur(expression)); + assertEquals(layer.getCircleBlur().getExpression(), expression); }); - } - @Test - public void testCircleBlurAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleBlur( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, circleBlur(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(circleBlur(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 testCircleOpacityTransition() { validateTestSetup(); setupLayer(); Timber.i("circle-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleOpacityTransition(options); - assertEquals(layer.getCircleOpacityTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleOpacityAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleOpacity(0.3f)); - assertEquals((Float) layer.getCircleOpacity().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleOpacityTransition(options); + assertEquals(layer.getCircleOpacityTransition(), options); }); } @Test - public void testCircleOpacityAsCameraFunction() { + public void testCircleOpacityAsConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleOpacityAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(circleOpacity(0.3f)); + assertEquals((Float) layer.getCircleOpacity().getValue(), (Float) 0.3f); }); } @Test - public void testCircleOpacityAsExponentialSourceFunction() { + public void testCircleOpacityAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("circle-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleOpacityAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleOpacity( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, circleOpacity(0.3f)) - ) - ).withDefaultValue(circleOpacity(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()); - assertNotNull(((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleOpacity(expression)); + assertEquals(layer.getCircleOpacity().getExpression(), expression); }); - } - @Test - public void testCircleOpacityAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleOpacity( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, circleOpacity(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(circleOpacity(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 testCircleTranslateTransition() { validateTestSetup(); setupLayer(); Timber.i("circle-translateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleTranslateTransition(options); - assertEquals(layer.getCircleTranslateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleTranslateTransition(options); + assertEquals(layer.getCircleTranslateTransition(), options); }); } @@ -907,47 +299,12 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleTranslateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(circleTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -956,46 +313,12 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getCircleTranslateAnchor().getValue(), (String) CIRCLE_TRANSLATE_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleTranslateAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getCircleTranslateAnchor().getValue(), (String) CIRCLE_TRANSLATE_ANCHOR_MAP); }); } @@ -1004,46 +327,12 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-pitch-scale"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP)); - assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCirclePitchScaleAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-pitch-scale"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP)); + assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP); }); } @@ -1052,46 +341,12 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-pitch-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP)); - assertEquals((String) layer.getCirclePitchAlignment().getValue(), (String) CIRCLE_PITCH_ALIGNMENT_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCirclePitchAlignmentAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-pitch-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circlePitchAlignment( - zoom( - interval( - stop(2, circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getCirclePitchAlignment()); - assertNotNull(layer.getCirclePitchAlignment().getFunction()); - assertEquals(CameraFunction.class, layer.getCirclePitchAlignment().getFunction().getClass()); - assertEquals(IntervalStops.class, layer.getCirclePitchAlignment().getFunction().getStops().getClass()); - assertEquals(1, ((IntervalStops) layer.getCirclePitchAlignment().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP)); + assertEquals((String) layer.getCirclePitchAlignment().getValue(), (String) CIRCLE_PITCH_ALIGNMENT_MAP); }); } @@ -1100,216 +355,58 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-widthTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleStrokeWidthTransition(options); - assertEquals(layer.getCircleStrokeWidthTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeWidthAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleStrokeWidth(0.3f)); - assertEquals((Float) layer.getCircleStrokeWidth().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleStrokeWidthTransition(options); + assertEquals(layer.getCircleStrokeWidthTransition(), options); }); } @Test - public void testCircleStrokeWidthAsCameraFunction() { + public void testCircleStrokeWidthAsConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeWidthAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(circleStrokeWidth(0.3f)); + assertEquals((Float) layer.getCircleStrokeWidth().getValue(), (Float) 0.3f); }); } @Test - public void testCircleStrokeWidthAsExponentialSourceFunction() { + public void testCircleStrokeWidthAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-stroke-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("circle-stroke-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeWidthAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleStrokeWidth( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, circleStrokeWidth(0.3f)) - ) - ).withDefaultValue(circleStrokeWidth(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()); - assertNotNull(((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleStrokeWidth(expression)); + assertEquals(layer.getCircleStrokeWidth().getExpression(), expression); }); - } - @Test - public void testCircleStrokeWidthAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleStrokeWidth( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, circleStrokeWidth(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(circleStrokeWidth(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 testCircleStrokeColorTransition() { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleStrokeColorTransition(options); - assertEquals(layer.getCircleStrokeColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleStrokeColorTransition(options); + assertEquals(layer.getCircleStrokeColorTransition(), options); }); } @@ -1318,157 +415,42 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleStrokeColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getCircleStrokeColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testCircleStrokeColorAsIdentitySourceFunction() { + public void testCircleStrokeColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-stroke-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("circle-stroke-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(circleStrokeColor(expression)); + assertEquals(layer.getCircleStrokeColor().getExpression(), expression); }); } - @Test - public void testCircleStrokeColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleStrokeColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", circleStrokeColor(Color.RED)) - ) - ).withDefaultValue(circleStrokeColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getCircleStrokeColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleStrokeColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testCircleStrokeColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleStrokeColor(Color.RED)); - assertEquals(layer.getCircleStrokeColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleStrokeColor(Color.RED)); + assertEquals(layer.getCircleStrokeColorAsInt(), Color.RED); }); } @@ -1477,199 +459,43 @@ public class CircleLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setCircleStrokeOpacityTransition(options); - assertEquals(layer.getCircleStrokeOpacityTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeOpacityAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleStrokeOpacity(0.3f)); - assertEquals((Float) layer.getCircleStrokeOpacity().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleStrokeOpacityTransition(options); + assertEquals(layer.getCircleStrokeOpacityTransition(), options); }); } @Test - public void testCircleStrokeOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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() { + public void testCircleStrokeOpacityAsConstant() { validateTestSetup(); setupLayer(); Timber.i("circle-stroke-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeOpacityAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(circleStrokeOpacity(0.3f)); + assertEquals((Float) layer.getCircleStrokeOpacity().getValue(), (Float) 0.3f); }); } @Test - public void testCircleStrokeOpacityAsCategoricalSourceFunction() { + public void testCircleStrokeOpacityAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("circle-stroke-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleStrokeOpacity( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, circleStrokeOpacity(0.3f)) - ) - ).withDefaultValue(circleStrokeOpacity(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()); - assertNotNull(((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue().getValue()); - } - }); - - } + Timber.i("circle-stroke-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testCircleStrokeOpacityAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("circle-stroke-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - circleStrokeOpacity( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, circleStrokeOpacity(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(circleStrokeOpacity(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); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleStrokeOpacity(expression)); + assertEquals(layer.getCircleStrokeOpacity().getExpression(), expression); }); } -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java new file mode 100644 index 0000000000..c4ff79b053 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java @@ -0,0 +1,207 @@ +package com.mapbox.mapboxsdk.testapp.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.FillLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.style.sources.Source; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; + +import timber.log.Timber; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; +import static com.mapbox.mapboxsdk.style.expressions.Expression.match; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; +import static com.mapbox.mapboxsdk.style.expressions.Expression.step; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.string; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toColor; +import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; +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.fillOutlineColor; +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +@RunWith(AndroidJUnit4.class) +public class ExpressionTest extends BaseActivityTest { + + private FillLayer layer; + + @Test + public void testConstantExpressionConversion() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create color expression + Expression inputExpression = rgba(255.0f, 0.0f, 0.0f, 1.0f); + + // set color expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get color value + int color = layer.getFillColor().getColorInt(); + + // compare + assertEquals("input expression should match", Color.RED, color); + }); + } + + @Test + public void testGetExpressionWrapping() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create get expression + Expression inputExpression = get("fill"); + + // set get expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get actual expression + Expression actualExpression = layer.getFillColor().getExpression(); + + // create wrapped expected expression + Expression expectedExpression = toColor(get("fill")); + + // compare + assertEquals("input expression should match", expectedExpression, actualExpression); + }); + } + + @Test + public void testCameraFunction() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create camera function expression + Expression inputExpression = interpolate( + exponential(0.5f), zoom(), + stop(1.0f, rgba(255.0f, 0.0f, 0.0f, 1.0f)), + stop(5.0f, rgba(0.0f, 0.0f, 255.0f, 1.0f)), + stop(10.0f, rgba(0.0f, 255.0f, 0.0f, 1.0f)) + ); + + // set camera function expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get camera function expression + Expression outputExpression = layer.getFillColor().getExpression(); + + // compare + assertEquals("input expression should match", inputExpression, outputExpression); + }); + } + + @Test + public void testSourceFunction() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create camera function expression + Expression inputExpression = toColor(get("fill")); + + // set camera function expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get camera function expression + Expression outputExpression = layer.getFillColor().getExpression(); + + // compare + assertEquals("input expression should match", inputExpression, outputExpression); + }); + } + + @Test + public void testCompositeFunction() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create camera function expression + Expression inputExpression = step(zoom(), + rgba(255.0f, 255.0f, 255.0f, 1.0f), + stop(7.0f, match( + string(get("name")), + literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f), + rgba(255.0f, 255.0f, 255.0f, 1.0f) + )), + stop(8.0f, match( + string(get("name")), + literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f), + rgba(255.0f, 255.0f, 255.0f, 1.0f) + )) + ); + + // set camera function expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get camera function expression + Expression outputExpression = layer.getFillColor().getExpression(); + + // compare + assertEquals("input expression should match", inputExpression, outputExpression); + }); + } + + private void setupStyle() { + invoke(mapboxMap, (uiController, mapboxMap) -> { + // Add a source + Source source; + try { + source = new GeoJsonSource("amsterdam-parks-source", + ResourceUtils.readRawResource(rule.getActivity(), R.raw.amsterdam)); + mapboxMap.addSource(source); + } catch (IOException ioException) { + return; + } + + // Add a fill layer + mapboxMap.addLayer(layer = new FillLayer("amsterdam-parks-layer", source.getId()) + .withProperties( + fillColor(rgba(0.0f, 0.0f, 0.0f, 0.5f)), + fillOutlineColor(rgb(0, 0, 255)), + fillAntialias(true) + ) + ); + }); + } + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillExtrusionLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillExtrusionLayerTest.java index 66c6093537..dd8929e2f4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillExtrusionLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillExtrusionLayerTest.java @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class FillExtrusionLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new FillExtrusionLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new FillExtrusionLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); } }); } @@ -71,18 +55,15 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,19 +72,16 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); - - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } @@ -112,16 +90,13 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillExtrusionOpacityTransition(options); - assertEquals(layer.getFillExtrusionOpacityTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionOpacityTransition(options); + assertEquals(layer.getFillExtrusionOpacityTransition(), options); }); } @@ -130,47 +105,12 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionOpacity(0.3f)); - assertEquals((Float) layer.getFillExtrusionOpacity().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionOpacity( - zoom( - exponential( - stop(2, fillExtrusionOpacity(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionOpacity()); - assertNotNull(layer.getFillExtrusionOpacity().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionOpacity().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionOpacity().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getFillExtrusionOpacity().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionOpacity().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(fillExtrusionOpacity(0.3f)); + assertEquals((Float) layer.getFillExtrusionOpacity().getValue(), (Float) 0.3f); }); } @@ -179,16 +119,13 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillExtrusionColorTransition(options); - assertEquals(layer.getFillExtrusionColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionColorTransition(options); + assertEquals(layer.getFillExtrusionColorTransition(), options); }); } @@ -197,157 +134,42 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getFillExtrusionColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionColor( - zoom( - exponential( - stop(2, fillExtrusionColor("rgba(0, 0, 0, 1)")) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionColor()); - assertNotNull(layer.getFillExtrusionColor().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionColor().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionColor().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getFillExtrusionColor().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionColor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(fillExtrusionColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getFillExtrusionColor().getValue(), (String) "rgba(0, 0, 0, 1)"); }); } @Test - public void testFillExtrusionColorAsIdentitySourceFunction() { + public void testFillExtrusionColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("fill-extrusion-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionColor(property("FeaturePropertyA", Stops.<String>identity())) - ); - - // Verify - assertNotNull(layer.getFillExtrusionColor()); - assertNotNull(layer.getFillExtrusionColor().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionColor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionColor().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getFillExtrusionColor().getFunction().getStops().getClass()); - } - }); - } + Timber.i("fill-extrusion-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionColor( - property( - "FeaturePropertyA", - exponential( - stop(Color.RED, fillExtrusionColor(Color.RED)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionColor()); - assertNotNull(layer.getFillExtrusionColor().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionColor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionColor().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionColor().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(fillExtrusionColor(expression)); + assertEquals(layer.getFillExtrusionColor().getExpression(), expression); }); } - @Test - public void testFillExtrusionColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", fillExtrusionColor(Color.RED)) - ) - ).withDefaultValue(fillExtrusionColor(Color.GREEN)) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionColor()); - assertNotNull(layer.getFillExtrusionColor().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionColor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionColor().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getFillExtrusionColor().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getFillExtrusionColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getFillExtrusionColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getFillExtrusionColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testFillExtrusionColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionColor(Color.RED)); - assertEquals(layer.getFillExtrusionColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionColor(Color.RED)); + assertEquals(layer.getFillExtrusionColorAsInt(), Color.RED); }); } @@ -356,16 +178,13 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-translateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillExtrusionTranslateTransition(options); - assertEquals(layer.getFillExtrusionTranslateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionTranslateTransition(options); + assertEquals(layer.getFillExtrusionTranslateTransition(), options); }); } @@ -374,47 +193,12 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getFillExtrusionTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionTranslateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionTranslate( - zoom( - exponential( - stop(2, fillExtrusionTranslate(new Float[] {0f, 0f})) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionTranslate()); - assertNotNull(layer.getFillExtrusionTranslate().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionTranslate().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionTranslate().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getFillExtrusionTranslate().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionTranslate().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(fillExtrusionTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getFillExtrusionTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -423,46 +207,12 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionTranslateAnchor(FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getFillExtrusionTranslateAnchor().getValue(), (String) FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionTranslateAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionTranslateAnchor( - zoom( - interval( - stop(2, fillExtrusionTranslateAnchor(FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionTranslateAnchor()); - assertNotNull(layer.getFillExtrusionTranslateAnchor().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionTranslateAnchor().getFunction().getClass()); - assertEquals(IntervalStops.class, layer.getFillExtrusionTranslateAnchor().getFunction().getStops().getClass()); - assertEquals(1, ((IntervalStops) layer.getFillExtrusionTranslateAnchor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(fillExtrusionTranslateAnchor(FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getFillExtrusionTranslateAnchor().getValue(), (String) FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP); }); } @@ -471,16 +221,13 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-patternTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillExtrusionPatternTransition(options); - assertEquals(layer.getFillExtrusionPatternTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionPatternTransition(options); + assertEquals(layer.getFillExtrusionPatternTransition(), options); }); } @@ -489,46 +236,12 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionPattern("pedestrian-polygon")); - assertEquals((String) layer.getFillExtrusionPattern().getValue(), (String) "pedestrian-polygon"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionPatternAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionPattern( - zoom( - interval( - stop(2, fillExtrusionPattern("pedestrian-polygon")) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionPattern()); - assertNotNull(layer.getFillExtrusionPattern().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionPattern().getFunction().getClass()); - assertEquals(IntervalStops.class, layer.getFillExtrusionPattern().getFunction().getStops().getClass()); - assertEquals(1, ((IntervalStops) layer.getFillExtrusionPattern().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(fillExtrusionPattern("pedestrian-polygon")); + assertEquals((String) layer.getFillExtrusionPattern().getValue(), (String) "pedestrian-polygon"); }); } @@ -537,216 +250,58 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-heightTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillExtrusionHeightTransition(options); - assertEquals(layer.getFillExtrusionHeightTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionHeightAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionHeight(0.3f)); - assertEquals((Float) layer.getFillExtrusionHeight().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionHeightTransition(options); + assertEquals(layer.getFillExtrusionHeightTransition(), options); }); } @Test - public void testFillExtrusionHeightAsCameraFunction() { + public void testFillExtrusionHeightAsConstant() { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionHeight( - zoom( - exponential( - stop(2, fillExtrusionHeight(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionHeight()); - assertNotNull(layer.getFillExtrusionHeight().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionHeight().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionHeight().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getFillExtrusionHeight().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionHeight().getFunction().getStops()).size()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionHeightAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionHeight(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getFillExtrusionHeight()); - assertNotNull(layer.getFillExtrusionHeight().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionHeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionHeight().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getFillExtrusionHeight().getFunction().getStops().getClass()); - } + // Set and Get + layer.setProperties(fillExtrusionHeight(0.3f)); + assertEquals((Float) layer.getFillExtrusionHeight().getValue(), (Float) 0.3f); }); } @Test - public void testFillExtrusionHeightAsExponentialSourceFunction() { + public void testFillExtrusionHeightAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("fill-extrusion-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionHeight( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, fillExtrusionHeight(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionHeight()); - assertNotNull(layer.getFillExtrusionHeight().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionHeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionHeight().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionHeight().getFunction().getStops().getClass()); - } - }); - } + Timber.i("fill-extrusion-height-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionHeightAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionHeight( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, fillExtrusionHeight(0.3f)) - ) - ).withDefaultValue(fillExtrusionHeight(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionHeight()); - assertNotNull(layer.getFillExtrusionHeight().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionHeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionHeight().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getFillExtrusionHeight().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getFillExtrusionHeight().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getFillExtrusionHeight().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getFillExtrusionHeight().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(fillExtrusionHeight(expression)); + assertEquals(layer.getFillExtrusionHeight().getExpression(), expression); }); - } - @Test - public void testFillExtrusionHeightAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionHeight( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, fillExtrusionHeight(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(fillExtrusionHeight(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionHeight()); - assertNotNull(layer.getFillExtrusionHeight().getFunction()); - assertEquals(CompositeFunction.class, layer.getFillExtrusionHeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getFillExtrusionHeight().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionHeight().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionHeight().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getFillExtrusionHeight().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 testFillExtrusionBaseTransition() { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-baseTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillExtrusionBaseTransition(options); - assertEquals(layer.getFillExtrusionBaseTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionBaseTransition(options); + assertEquals(layer.getFillExtrusionBaseTransition(), options); }); } @@ -755,181 +310,28 @@ public class FillExtrusionLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-extrusion-base"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillExtrusionBase(0.3f)); - assertEquals((Float) layer.getFillExtrusionBase().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionBaseAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-base"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionBase( - zoom( - exponential( - stop(2, fillExtrusionBase(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionBase()); - assertNotNull(layer.getFillExtrusionBase().getFunction()); - assertEquals(CameraFunction.class, layer.getFillExtrusionBase().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionBase().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getFillExtrusionBase().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionBase().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(fillExtrusionBase(0.3f)); + assertEquals((Float) layer.getFillExtrusionBase().getValue(), (Float) 0.3f); }); } @Test - public void testFillExtrusionBaseAsIdentitySourceFunction() { + public void testFillExtrusionBaseAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("fill-extrusion-base"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionBase(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getFillExtrusionBase()); - assertNotNull(layer.getFillExtrusionBase().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionBase().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionBase().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getFillExtrusionBase().getFunction().getStops().getClass()); - } - }); - } + Timber.i("fill-extrusion-base-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillExtrusionBaseAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-base"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionBase( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, fillExtrusionBase(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionBase()); - assertNotNull(layer.getFillExtrusionBase().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionBase().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionBase().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionBase().getFunction().getStops().getClass()); - } - }); - } - - @Test - public void testFillExtrusionBaseAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-base"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionBase( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, fillExtrusionBase(0.3f)) - ) - ).withDefaultValue(fillExtrusionBase(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionBase()); - assertNotNull(layer.getFillExtrusionBase().getFunction()); - assertEquals(SourceFunction.class, layer.getFillExtrusionBase().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillExtrusionBase().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getFillExtrusionBase().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getFillExtrusionBase().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getFillExtrusionBase().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getFillExtrusionBase().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testFillExtrusionBaseAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-extrusion-base"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillExtrusionBase( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, fillExtrusionBase(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(fillExtrusionBase(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getFillExtrusionBase()); - assertNotNull(layer.getFillExtrusionBase().getFunction()); - assertEquals(CompositeFunction.class, layer.getFillExtrusionBase().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getFillExtrusionBase().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getFillExtrusionBase().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getFillExtrusionBase().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getFillExtrusionBase().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); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(fillExtrusionBase(expression)); + assertEquals(layer.getFillExtrusionBase().getExpression(), expression); }); } -} +}
\ No newline at end of file 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 939bcb6892..c70ea39ffa 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 @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class FillLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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"); } }); } @@ -71,18 +55,15 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,19 +72,16 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); - - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } @@ -112,46 +90,12 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-antialias"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillAntialias(true)); - assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillAntialiasAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-antialias"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(fillAntialias(true)); + assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true); }); } @@ -160,16 +104,13 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillOpacityTransition(options); - assertEquals(layer.getFillOpacityTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillOpacityTransition(options); + assertEquals(layer.getFillOpacityTransition(), options); }); } @@ -178,198 +119,43 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillOpacity(0.3f)); - assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(fillOpacity(0.3f)); + assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f); }); } @Test - public void testFillOpacityAsIdentitySourceFunction() { + public void testFillOpacityAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("fill-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("fill-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillOpacityAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(fillOpacity(expression)); + assertEquals(layer.getFillOpacity().getExpression(), expression); }); } - @Test - public void testFillOpacityAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillOpacity( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, fillOpacity(0.3f)) - ) - ).withDefaultValue(fillOpacity(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()); - assertNotNull(((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testFillOpacityAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillOpacity( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, fillOpacity(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(fillOpacity(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 testFillColorTransition() { validateTestSetup(); setupLayer(); Timber.i("fill-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillColorTransition(options); - assertEquals(layer.getFillColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillColorTransition(options); + assertEquals(layer.getFillColorTransition(), options); }); } @@ -378,157 +164,42 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testFillColorAsIdentitySourceFunction() { + public void testFillColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("fill-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("fill-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(fillColor(expression)); + assertEquals(layer.getFillColor().getExpression(), expression); }); } - @Test - public void testFillColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", fillColor(Color.RED)) - ) - ).withDefaultValue(fillColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getFillColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getFillColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getFillColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testFillColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("fill-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillColor(Color.RED)); - assertEquals(layer.getFillColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillColor(Color.RED)); + assertEquals(layer.getFillColorAsInt(), Color.RED); }); } @@ -537,16 +208,13 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-outline-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillOutlineColorTransition(options); - assertEquals(layer.getFillOutlineColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillOutlineColorTransition(options); + assertEquals(layer.getFillOutlineColorTransition(), options); }); } @@ -555,157 +223,42 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-outline-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillOutlineColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-outline-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testFillOutlineColorAsIdentitySourceFunction() { + public void testFillOutlineColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("fill-outline-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("fill-outline-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillOutlineColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-outline-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(fillOutlineColor(expression)); + assertEquals(layer.getFillOutlineColor().getExpression(), expression); }); } - @Test - public void testFillOutlineColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-outline-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - fillOutlineColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", fillOutlineColor(Color.RED)) - ) - ).withDefaultValue(fillOutlineColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getFillOutlineColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getFillOutlineColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getFillOutlineColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testFillOutlineColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("fill-outline-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillOutlineColor(Color.RED)); - assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillOutlineColor(Color.RED)); + assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); }); } @@ -714,16 +267,13 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-translateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillTranslateTransition(options); - assertEquals(layer.getFillTranslateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillTranslateTransition(options); + assertEquals(layer.getFillTranslateTransition(), options); }); } @@ -732,47 +282,12 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillTranslateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(fillTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -781,46 +296,12 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillTranslateAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP); }); } @@ -829,16 +310,13 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-patternTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setFillPatternTransition(options); - assertEquals(layer.getFillPatternTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillPatternTransition(options); + assertEquals(layer.getFillPatternTransition(), options); }); } @@ -847,47 +325,12 @@ public class FillLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("fill-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillPattern("pedestrian-polygon")); - assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testFillPatternAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("fill-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(fillPattern("pedestrian-polygon")); + assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); }); } - -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HeatmapLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HeatmapLayerTest.java index 364c8d2679..9a0374a763 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HeatmapLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HeatmapLayerTest.java @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.HeatmapLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class HeatmapLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new HeatmapLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new HeatmapLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); } }); } @@ -71,18 +55,15 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,19 +72,16 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); - - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } @@ -112,16 +90,13 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("heatmap-radiusTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHeatmapRadiusTransition(options); - assertEquals(layer.getHeatmapRadiusTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHeatmapRadiusTransition(options); + assertEquals(layer.getHeatmapRadiusTransition(), options); }); } @@ -130,380 +105,73 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("heatmap-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(heatmapRadius(0.3f)); - assertEquals((Float) layer.getHeatmapRadius().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHeatmapRadiusAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapRadius( - zoom( - exponential( - stop(2, heatmapRadius(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapRadius()); - assertNotNull(layer.getHeatmapRadius().getFunction()); - assertEquals(CameraFunction.class, layer.getHeatmapRadius().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapRadius().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHeatmapRadius().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(heatmapRadius(0.3f)); + assertEquals((Float) layer.getHeatmapRadius().getValue(), (Float) 0.3f); }); } @Test - public void testHeatmapRadiusAsIdentitySourceFunction() { + public void testHeatmapRadiusAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("heatmap-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapRadius(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getHeatmapRadius()); - assertNotNull(layer.getHeatmapRadius().getFunction()); - assertEquals(SourceFunction.class, layer.getHeatmapRadius().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapRadius().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass()); - } - }); - } + Timber.i("heatmap-radius-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHeatmapRadiusAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapRadius( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, heatmapRadius(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapRadius()); - assertNotNull(layer.getHeatmapRadius().getFunction()); - assertEquals(SourceFunction.class, layer.getHeatmapRadius().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapRadius().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(heatmapRadius(expression)); + assertEquals(layer.getHeatmapRadius().getExpression(), expression); }); } - @Test - public void testHeatmapRadiusAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapRadius( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, heatmapRadius(0.3f)) - ) - ).withDefaultValue(heatmapRadius(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapRadius()); - assertNotNull(layer.getHeatmapRadius().getFunction()); - assertEquals(SourceFunction.class, layer.getHeatmapRadius().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapRadius().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getHeatmapRadius().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getHeatmapRadius().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getHeatmapRadius().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testHeatmapRadiusAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-radius"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapRadius( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, heatmapRadius(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(heatmapRadius(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapRadius()); - assertNotNull(layer.getHeatmapRadius().getFunction()); - assertEquals(CompositeFunction.class, layer.getHeatmapRadius().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getHeatmapRadius().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getHeatmapRadius().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getHeatmapRadius().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 testHeatmapWeightAsConstant() { validateTestSetup(); setupLayer(); Timber.i("heatmap-weight"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(heatmapWeight(0.3f)); - assertEquals((Float) layer.getHeatmapWeight().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHeatmapWeightAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-weight"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapWeight( - zoom( - exponential( - stop(2, heatmapWeight(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapWeight()); - assertNotNull(layer.getHeatmapWeight().getFunction()); - assertEquals(CameraFunction.class, layer.getHeatmapWeight().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapWeight().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHeatmapWeight().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(heatmapWeight(0.3f)); + assertEquals((Float) layer.getHeatmapWeight().getValue(), (Float) 0.3f); }); } @Test - public void testHeatmapWeightAsIdentitySourceFunction() { + public void testHeatmapWeightAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("heatmap-weight"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapWeight(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getHeatmapWeight()); - assertNotNull(layer.getHeatmapWeight().getFunction()); - assertEquals(SourceFunction.class, layer.getHeatmapWeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapWeight().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass()); - } - }); - } + Timber.i("heatmap-weight-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHeatmapWeightAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-weight"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapWeight( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, heatmapWeight(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapWeight()); - assertNotNull(layer.getHeatmapWeight().getFunction()); - assertEquals(SourceFunction.class, layer.getHeatmapWeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapWeight().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(heatmapWeight(expression)); + assertEquals(layer.getHeatmapWeight().getExpression(), expression); }); } - @Test - public void testHeatmapWeightAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-weight"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapWeight( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, heatmapWeight(0.3f)) - ) - ).withDefaultValue(heatmapWeight(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapWeight()); - assertNotNull(layer.getHeatmapWeight().getFunction()); - assertEquals(SourceFunction.class, layer.getHeatmapWeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapWeight().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getHeatmapWeight().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getHeatmapWeight().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getHeatmapWeight().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testHeatmapWeightAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-weight"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapWeight( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, heatmapWeight(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(heatmapWeight(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapWeight()); - assertNotNull(layer.getHeatmapWeight().getFunction()); - assertEquals(CompositeFunction.class, layer.getHeatmapWeight().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getHeatmapWeight().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getHeatmapWeight().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getHeatmapWeight().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 testHeatmapIntensityTransition() { validateTestSetup(); setupLayer(); Timber.i("heatmap-intensityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHeatmapIntensityTransition(options); - assertEquals(layer.getHeatmapIntensityTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHeatmapIntensityTransition(options); + assertEquals(layer.getHeatmapIntensityTransition(), options); }); } @@ -512,47 +180,12 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("heatmap-intensity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(heatmapIntensity(0.3f)); - assertEquals((Float) layer.getHeatmapIntensity().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHeatmapIntensityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-intensity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapIntensity( - zoom( - exponential( - stop(2, heatmapIntensity(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapIntensity()); - assertNotNull(layer.getHeatmapIntensity().getFunction()); - assertEquals(CameraFunction.class, layer.getHeatmapIntensity().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHeatmapIntensity().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapIntensity().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHeatmapIntensity().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(heatmapIntensity(0.3f)); + assertEquals((Float) layer.getHeatmapIntensity().getValue(), (Float) 0.3f); }); } @@ -561,16 +194,13 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("heatmap-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHeatmapOpacityTransition(options); - assertEquals(layer.getHeatmapOpacityTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHeatmapOpacityTransition(options); + assertEquals(layer.getHeatmapOpacityTransition(), options); }); } @@ -579,48 +209,12 @@ public class HeatmapLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("heatmap-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(heatmapOpacity(0.3f)); - assertEquals((Float) layer.getHeatmapOpacity().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHeatmapOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("heatmap-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - heatmapOpacity( - zoom( - exponential( - stop(2, heatmapOpacity(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHeatmapOpacity()); - assertNotNull(layer.getHeatmapOpacity().getFunction()); - assertEquals(CameraFunction.class, layer.getHeatmapOpacity().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHeatmapOpacity().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapOpacity().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHeatmapOpacity().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(heatmapOpacity(0.3f)); + assertEquals((Float) layer.getHeatmapOpacity().getValue(), (Float) 0.3f); }); } - -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HillshadeLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HillshadeLayerTest.java index 1cb7b575be..1fdc6d6dab 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HillshadeLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/HillshadeLayerTest.java @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.HillshadeLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class HillshadeLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new HillshadeLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new HillshadeLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); } }); } @@ -71,18 +55,15 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,47 +72,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-illumination-direction"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeIlluminationDirection(0.3f)); - assertEquals((Float) layer.getHillshadeIlluminationDirection().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHillshadeIlluminationDirectionAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("hillshade-illumination-direction"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - hillshadeIlluminationDirection( - zoom( - exponential( - stop(2, hillshadeIlluminationDirection(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHillshadeIlluminationDirection()); - assertNotNull(layer.getHillshadeIlluminationDirection().getFunction()); - assertEquals(CameraFunction.class, layer.getHillshadeIlluminationDirection().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHillshadeIlluminationDirection().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeIlluminationDirection().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHillshadeIlluminationDirection().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(hillshadeIlluminationDirection(0.3f)); + assertEquals((Float) layer.getHillshadeIlluminationDirection().getValue(), (Float) 0.3f); }); } @@ -140,46 +86,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-illumination-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP)); - assertEquals((String) layer.getHillshadeIlluminationAnchor().getValue(), (String) HILLSHADE_ILLUMINATION_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHillshadeIlluminationAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("hillshade-illumination-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - hillshadeIlluminationAnchor( - zoom( - interval( - stop(2, hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getHillshadeIlluminationAnchor()); - assertNotNull(layer.getHillshadeIlluminationAnchor().getFunction()); - assertEquals(CameraFunction.class, layer.getHillshadeIlluminationAnchor().getFunction().getClass()); - assertEquals(IntervalStops.class, layer.getHillshadeIlluminationAnchor().getFunction().getStops().getClass()); - assertEquals(1, ((IntervalStops) layer.getHillshadeIlluminationAnchor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP)); + assertEquals((String) layer.getHillshadeIlluminationAnchor().getValue(), (String) HILLSHADE_ILLUMINATION_ANCHOR_MAP); }); } @@ -188,16 +100,13 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-exaggerationTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHillshadeExaggerationTransition(options); - assertEquals(layer.getHillshadeExaggerationTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeExaggerationTransition(options); + assertEquals(layer.getHillshadeExaggerationTransition(), options); }); } @@ -206,47 +115,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-exaggeration"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeExaggeration(0.3f)); - assertEquals((Float) layer.getHillshadeExaggeration().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHillshadeExaggerationAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("hillshade-exaggeration"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - hillshadeExaggeration( - zoom( - exponential( - stop(2, hillshadeExaggeration(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHillshadeExaggeration()); - assertNotNull(layer.getHillshadeExaggeration().getFunction()); - assertEquals(CameraFunction.class, layer.getHillshadeExaggeration().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHillshadeExaggeration().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeExaggeration().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHillshadeExaggeration().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(hillshadeExaggeration(0.3f)); + assertEquals((Float) layer.getHillshadeExaggeration().getValue(), (Float) 0.3f); }); } @@ -255,16 +129,13 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-shadow-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHillshadeShadowColorTransition(options); - assertEquals(layer.getHillshadeShadowColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeShadowColorTransition(options); + assertEquals(layer.getHillshadeShadowColorTransition(), options); }); } @@ -273,47 +144,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-shadow-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeShadowColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getHillshadeShadowColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHillshadeShadowColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("hillshade-shadow-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - hillshadeShadowColor( - zoom( - exponential( - stop(2, hillshadeShadowColor("rgba(0, 0, 0, 1)")) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHillshadeShadowColor()); - assertNotNull(layer.getHillshadeShadowColor().getFunction()); - assertEquals(CameraFunction.class, layer.getHillshadeShadowColor().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHillshadeShadowColor().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeShadowColor().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHillshadeShadowColor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(hillshadeShadowColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getHillshadeShadowColor().getValue(), (String) "rgba(0, 0, 0, 1)"); }); } @@ -322,15 +158,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-shadow-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeShadowColor(Color.RED)); - assertEquals(layer.getHillshadeShadowColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeShadowColor(Color.RED)); + assertEquals(layer.getHillshadeShadowColorAsInt(), Color.RED); }); } @@ -339,16 +172,13 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-highlight-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHillshadeHighlightColorTransition(options); - assertEquals(layer.getHillshadeHighlightColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeHighlightColorTransition(options); + assertEquals(layer.getHillshadeHighlightColorTransition(), options); }); } @@ -357,47 +187,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-highlight-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeHighlightColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getHillshadeHighlightColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHillshadeHighlightColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("hillshade-highlight-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - hillshadeHighlightColor( - zoom( - exponential( - stop(2, hillshadeHighlightColor("rgba(0, 0, 0, 1)")) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHillshadeHighlightColor()); - assertNotNull(layer.getHillshadeHighlightColor().getFunction()); - assertEquals(CameraFunction.class, layer.getHillshadeHighlightColor().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHillshadeHighlightColor().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeHighlightColor().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHillshadeHighlightColor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(hillshadeHighlightColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getHillshadeHighlightColor().getValue(), (String) "rgba(0, 0, 0, 1)"); }); } @@ -406,15 +201,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-highlight-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeHighlightColor(Color.RED)); - assertEquals(layer.getHillshadeHighlightColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeHighlightColor(Color.RED)); + assertEquals(layer.getHillshadeHighlightColorAsInt(), Color.RED); }); } @@ -423,16 +215,13 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-accent-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setHillshadeAccentColorTransition(options); - assertEquals(layer.getHillshadeAccentColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeAccentColorTransition(options); + assertEquals(layer.getHillshadeAccentColorTransition(), options); }); } @@ -441,47 +230,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-accent-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeAccentColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getHillshadeAccentColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testHillshadeAccentColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("hillshade-accent-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - hillshadeAccentColor( - zoom( - exponential( - stop(2, hillshadeAccentColor("rgba(0, 0, 0, 1)")) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getHillshadeAccentColor()); - assertNotNull(layer.getHillshadeAccentColor().getFunction()); - assertEquals(CameraFunction.class, layer.getHillshadeAccentColor().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getHillshadeAccentColor().getFunction().getStops().getClass()); - assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeAccentColor().getFunction().getStops()).getBase(), 0.001); - assertEquals(1, ((ExponentialStops) layer.getHillshadeAccentColor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(hillshadeAccentColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getHillshadeAccentColor().getValue(), (String) "rgba(0, 0, 0, 1)"); }); } @@ -490,16 +244,12 @@ public class HillshadeLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("hillshade-accent-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(hillshadeAccentColor(Color.RED)); - assertEquals(layer.getHillshadeAccentColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeAccentColor(Color.RED)); + assertEquals(layer.getHillshadeAccentColorAsInt(), Color.RED); }); } - -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LightTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LightTest.java index 88da6e45be..560aa91420 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LightTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LightTest.java @@ -6,15 +6,12 @@ import android.support.test.espresso.ViewAction; import android.support.test.runner.AndroidJUnit4; import android.view.View; -import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.style.light.Light; -import com.mapbox.mapboxsdk.style.functions.Function; -import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; import com.mapbox.mapboxsdk.style.light.Position; import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; import com.mapbox.mapboxsdk.testapp.activity.style.FillExtrusionStyleTestActivity; @@ -48,14 +45,11 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - light.setAnchor(ANCHOR_MAP); - assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.setAnchor(ANCHOR_MAP); + assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor()); }); } @@ -64,15 +58,12 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("positionTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - light.setPositionTransition(options); - assertEquals("Transition options should match", options, light.getPositionTransition()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.setPositionTransition(options); + assertEquals("Transition options should match", options, light.getPositionTransition()); }); } @@ -81,15 +72,12 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("position"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - Position position = new Position(1, 2, 3); - light.setPosition(position); - assertEquals("Position should match", position, light.getPosition()); - } + invoke(mapboxMap,(uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + Position position = new Position(1, 2, 3); + light.setPosition(position); + assertEquals("Position should match", position, light.getPosition()); }); } @@ -98,15 +86,12 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - light.setColorTransition(options); - assertEquals("Transition options should match", options, light.getColorTransition()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.setColorTransition(options); + assertEquals("Transition options should match", options, light.getColorTransition()); }); } @@ -115,14 +100,11 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - light.setColor("rgba(0, 0, 0, 1)"); - assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.setColor("rgba(0, 0, 0, 1)"); + assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor()); }); } @@ -131,15 +113,12 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("intensityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - light.setIntensityTransition(options); - assertEquals("Transition options should match", options, light.getIntensityTransition()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.setIntensityTransition(options); + assertEquals("Transition options should match", options, light.getIntensityTransition()); }); } @@ -148,14 +127,11 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("intensity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - light.setIntensity(0.3f); - assertEquals("Intensity should match", 0.3f, light.getIntensity()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.setIntensity(0.3f); + assertEquals("Intensity should match", 0.3f, light.getIntensity()); }); } @@ -180,8 +156,8 @@ public class LightTest extends BaseActivityTest { fillExtrusionLayer.setMinZoom(15); fillExtrusionLayer.setProperties( fillExtrusionColor(Color.LTGRAY), - fillExtrusionHeight(Function.property("height", new IdentityStops<Float>())), - fillExtrusionBase(Function.property("min_height", new IdentityStops<Float>())), + fillExtrusionHeight(Expression.get("height")), + fillExtrusionBase(Expression.get("min_height")), fillExtrusionOpacity(0.6f) ); mapboxMap.addLayer(fillExtrusionLayer); @@ -193,4 +169,4 @@ public class LightTest extends BaseActivityTest { protected Class getActivityClass() { return FillExtrusionStyleTestActivity.class; } -} +}
\ No newline at end of file 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 8123d24be8..a8e306d7a6 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 @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.LineLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class LineLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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"); } }); } @@ -71,18 +55,15 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,19 +72,16 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); - - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } @@ -112,46 +90,12 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-cap"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineCap(LINE_CAP_BUTT)); - assertEquals((String) layer.getLineCap().getValue(), (String) LINE_CAP_BUTT); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineCapAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-cap"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineCap(LINE_CAP_BUTT)); + assertEquals((String) layer.getLineCap().getValue(), (String) LINE_CAP_BUTT); }); } @@ -160,152 +104,42 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-join"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineJoin(LINE_JOIN_BEVEL)); - assertEquals((String) layer.getLineJoin().getValue(), (String) LINE_JOIN_BEVEL); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineJoinAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-join"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineJoin(LINE_JOIN_BEVEL)); + assertEquals((String) layer.getLineJoin().getValue(), (String) LINE_JOIN_BEVEL); }); } @Test - public void testLineJoinAsIdentitySourceFunction() { + public void testLineJoinAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("line-join"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineJoin(property("FeaturePropertyA", Stops.<String>identity())) - ); - - // Verify - assertNotNull(layer.getLineJoin()); - assertNotNull(layer.getLineJoin().getFunction()); - assertEquals(SourceFunction.class, layer.getLineJoin().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineJoin().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getLineJoin().getFunction().getStops().getClass()); - } - }); - } + Timber.i("line-join-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineJoinAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-join"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineJoin( - property( - "FeaturePropertyA", - interval( - stop(1, lineJoin(LINE_JOIN_BEVEL)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getLineJoin()); - assertNotNull(layer.getLineJoin().getFunction()); - assertEquals(SourceFunction.class, layer.getLineJoin().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineJoin().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getLineJoin().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(lineJoin(expression)); + assertEquals(layer.getLineJoin().getExpression(), expression); }); } + @Test public void testLineMiterLimitAsConstant() { validateTestSetup(); setupLayer(); Timber.i("line-miter-limit"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineMiterLimit(0.3f)); - assertEquals((Float) layer.getLineMiterLimit().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineMiterLimitAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-miter-limit"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineMiterLimit(0.3f)); + assertEquals((Float) layer.getLineMiterLimit().getValue(), (Float) 0.3f); }); } @@ -314,47 +148,12 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-round-limit"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineRoundLimit(0.3f)); - assertEquals((Float) layer.getLineRoundLimit().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineRoundLimitAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-round-limit"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineRoundLimit(0.3f)); + assertEquals((Float) layer.getLineRoundLimit().getValue(), (Float) 0.3f); }); } @@ -363,16 +162,13 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineOpacityTransition(options); - assertEquals(layer.getLineOpacityTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineOpacityTransition(options); + assertEquals(layer.getLineOpacityTransition(), options); }); } @@ -381,198 +177,43 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineOpacity(0.3f)); - assertEquals((Float) layer.getLineOpacity().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineOpacity(0.3f)); + assertEquals((Float) layer.getLineOpacity().getValue(), (Float) 0.3f); }); } @Test - public void testLineOpacityAsIdentitySourceFunction() { + public void testLineOpacityAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("line-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("line-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineOpacityAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineOpacity(expression)); + assertEquals(layer.getLineOpacity().getExpression(), expression); }); } - @Test - public void testLineOpacityAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineOpacity( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, lineOpacity(0.3f)) - ) - ).withDefaultValue(lineOpacity(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()); - assertNotNull(((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testLineOpacityAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineOpacity( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, lineOpacity(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(lineOpacity(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 testLineColorTransition() { validateTestSetup(); setupLayer(); Timber.i("line-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineColorTransition(options); - assertEquals(layer.getLineColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineColorTransition(options); + assertEquals(layer.getLineColorTransition(), options); }); } @@ -581,157 +222,42 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getLineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testLineColorAsIdentitySourceFunction() { + public void testLineColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("line-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("line-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(lineColor(expression)); + assertEquals(layer.getLineColor().getExpression(), expression); }); } - @Test - public void testLineColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", lineColor(Color.RED)) - ) - ).withDefaultValue(lineColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getLineColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getLineColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getLineColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testLineColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("line-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineColor(Color.RED)); - assertEquals(layer.getLineColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineColor(Color.RED)); + assertEquals(layer.getLineColorAsInt(), Color.RED); }); } @@ -740,16 +266,13 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-translateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineTranslateTransition(options); - assertEquals(layer.getLineTranslateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineTranslateTransition(options); + assertEquals(layer.getLineTranslateTransition(), options); }); } @@ -758,47 +281,12 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineTranslateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -807,46 +295,12 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getLineTranslateAnchor().getValue(), (String) LINE_TRANSLATE_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineTranslateAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getLineTranslateAnchor().getValue(), (String) LINE_TRANSLATE_ANCHOR_MAP); }); } @@ -855,16 +309,13 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-widthTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineWidthTransition(options); - assertEquals(layer.getLineWidthTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineWidthTransition(options); + assertEquals(layer.getLineWidthTransition(), options); }); } @@ -873,580 +324,102 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineWidth(0.3f)); - assertEquals((Float) layer.getLineWidth().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineWidthAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineWidth(0.3f)); + assertEquals((Float) layer.getLineWidth().getValue(), (Float) 0.3f); }); } @Test - public void testLineWidthAsIdentitySourceFunction() { + public void testLineWidthAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("line-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineWidth(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(SourceFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineWidth().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - } - }); - } + Timber.i("line-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineWidthAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineWidth( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, lineWidth(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(SourceFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineWidth().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineWidth(expression)); + assertEquals(layer.getLineWidth().getExpression(), expression); }); } - @Test - public void testLineWidthAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineWidth( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, lineWidth(0.3f)) - ) - ).withDefaultValue(lineWidth(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(SourceFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineWidth().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getLineWidth().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getLineWidth().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getLineWidth().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testLineWidthAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineWidth( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, lineWidth(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(lineWidth(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CompositeFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineWidth().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getLineWidth().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 testLineGapWidthTransition() { validateTestSetup(); setupLayer(); Timber.i("line-gap-widthTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineGapWidthTransition(options); - assertEquals(layer.getLineGapWidthTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineGapWidthAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("line-gap-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineGapWidth(0.3f)); - assertEquals((Float) layer.getLineGapWidth().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineGapWidthTransition(options); + assertEquals(layer.getLineGapWidthTransition(), options); }); } @Test - public void testLineGapWidthAsCameraFunction() { + public void testLineGapWidthAsConstant() { validateTestSetup(); setupLayer(); Timber.i("line-gap-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineGapWidthAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-gap-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(lineGapWidth(0.3f)); + assertEquals((Float) layer.getLineGapWidth().getValue(), (Float) 0.3f); }); } @Test - public void testLineGapWidthAsExponentialSourceFunction() { + public void testLineGapWidthAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("line-gap-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("line-gap-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineGapWidthAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-gap-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineGapWidth( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, lineGapWidth(0.3f)) - ) - ).withDefaultValue(lineGapWidth(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()); - assertNotNull(((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineGapWidth(expression)); + assertEquals(layer.getLineGapWidth().getExpression(), expression); }); - } - @Test - public void testLineGapWidthAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-gap-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineGapWidth( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, lineGapWidth(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(lineGapWidth(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 testLineOffsetTransition() { validateTestSetup(); setupLayer(); Timber.i("line-offsetTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineOffsetTransition(options); - assertEquals(layer.getLineOffsetTransition(), options); - } - }); - } - - @Test - public void testLineOffsetAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("line-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineOffset(0.3f)); - assertEquals((Float) layer.getLineOffset().getValue(), (Float) 0.3f); - } - }); - } - - @Test - public void testLineOffsetAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } - - @Test - public void testLineOffsetAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineOffsetAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineOffsetTransition(options); + assertEquals(layer.getLineOffsetTransition(), options); }); } @Test - public void testLineOffsetAsCategoricalSourceFunction() { + public void testLineOffsetAsConstant() { validateTestSetup(); setupLayer(); Timber.i("line-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineOffset( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, lineOffset(0.3f)) - ) - ).withDefaultValue(lineOffset(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()); - assertNotNull(((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue().getValue()); - } - }); - - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineOffsetAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineOffset( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, lineOffset(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(lineOffset(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); - } + // Set and Get + layer.setProperties(lineOffset(0.3f)); + assertEquals((Float) layer.getLineOffset().getValue(), (Float) 0.3f); }); } @@ -1455,216 +428,58 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-blurTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineBlurTransition(options); - assertEquals(layer.getLineBlurTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineBlurAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("line-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineBlur(0.3f)); - assertEquals((Float) layer.getLineBlur().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineBlurTransition(options); + assertEquals(layer.getLineBlurTransition(), options); }); } @Test - public void testLineBlurAsCameraFunction() { + public void testLineBlurAsConstant() { validateTestSetup(); setupLayer(); Timber.i("line-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineBlurAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(lineBlur(0.3f)); + assertEquals((Float) layer.getLineBlur().getValue(), (Float) 0.3f); }); } @Test - public void testLineBlurAsExponentialSourceFunction() { + public void testLineBlurAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("line-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("line-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineBlurAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineBlur( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, lineBlur(0.3f)) - ) - ).withDefaultValue(lineBlur(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()); - assertNotNull(((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineBlur(expression)); + assertEquals(layer.getLineBlur().getExpression(), expression); }); - } - @Test - public void testLineBlurAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - lineBlur( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, lineBlur(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(lineBlur(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 testLineDasharrayTransition() { validateTestSetup(); setupLayer(); Timber.i("line-dasharrayTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLineDasharrayTransition(options); - assertEquals(layer.getLineDasharrayTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineDasharrayTransition(options); + assertEquals(layer.getLineDasharrayTransition(), options); }); } @@ -1673,46 +488,12 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-dasharray"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineDasharray(new Float[] {})); - assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLineDasharrayAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-dasharray"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(lineDasharray(new Float[] {})); + assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); }); } @@ -1721,16 +502,13 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-patternTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setLinePatternTransition(options); - assertEquals(layer.getLinePatternTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLinePatternTransition(options); + assertEquals(layer.getLinePatternTransition(), options); }); } @@ -1739,47 +517,12 @@ public class LineLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("line-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(linePattern("pedestrian-polygon")); - assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testLinePatternAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("line-pattern"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(linePattern("pedestrian-polygon")); + assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); }); } - -} +}
\ No newline at end of file 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 df560e2632..0410d09369 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 @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.RasterLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class RasterLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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"); } }); } @@ -71,18 +55,15 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,16 +72,13 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setRasterOpacityTransition(options); - assertEquals(layer.getRasterOpacityTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterOpacityTransition(options); + assertEquals(layer.getRasterOpacityTransition(), options); }); } @@ -109,47 +87,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterOpacity(0.3f)); - assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterOpacityAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(rasterOpacity(0.3f)); + assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f); }); } @@ -158,16 +101,13 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-hue-rotateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setRasterHueRotateTransition(options); - assertEquals(layer.getRasterHueRotateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterHueRotateTransition(options); + assertEquals(layer.getRasterHueRotateTransition(), options); }); } @@ -176,47 +116,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-hue-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterHueRotate(0.3f)); - assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterHueRotateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-hue-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(rasterHueRotate(0.3f)); + assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f); }); } @@ -225,16 +130,13 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-brightness-minTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setRasterBrightnessMinTransition(options); - assertEquals(layer.getRasterBrightnessMinTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterBrightnessMinTransition(options); + assertEquals(layer.getRasterBrightnessMinTransition(), options); }); } @@ -243,47 +145,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-brightness-min"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterBrightnessMin(0.3f)); - assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterBrightnessMinAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-brightness-min"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(rasterBrightnessMin(0.3f)); + assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f); }); } @@ -292,16 +159,13 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-brightness-maxTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setRasterBrightnessMaxTransition(options); - assertEquals(layer.getRasterBrightnessMaxTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterBrightnessMaxTransition(options); + assertEquals(layer.getRasterBrightnessMaxTransition(), options); }); } @@ -310,47 +174,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-brightness-max"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterBrightnessMax(0.3f)); - assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterBrightnessMaxAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-brightness-max"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(rasterBrightnessMax(0.3f)); + assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f); }); } @@ -359,16 +188,13 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-saturationTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setRasterSaturationTransition(options); - assertEquals(layer.getRasterSaturationTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterSaturationTransition(options); + assertEquals(layer.getRasterSaturationTransition(), options); }); } @@ -377,47 +203,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-saturation"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterSaturation(0.3f)); - assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterSaturationAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-saturation"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(rasterSaturation(0.3f)); + assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f); }); } @@ -426,16 +217,13 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-contrastTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setRasterContrastTransition(options); - assertEquals(layer.getRasterContrastTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterContrastTransition(options); + assertEquals(layer.getRasterContrastTransition(), options); }); } @@ -444,47 +232,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-contrast"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterContrast(0.3f)); - assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterContrastAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-contrast"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(rasterContrast(0.3f)); + assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f); }); } @@ -493,48 +246,12 @@ public class RasterLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("raster-fade-duration"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterFadeDuration(0.3f)); - assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testRasterFadeDurationAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("raster-fade-duration"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(rasterFadeDuration(0.3f)); + assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); }); } - -} +}
\ No newline at end of file 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 781307862d..443c3d682a 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 @@ -3,31 +3,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -51,17 +38,14 @@ public class SymbolLayerTest extends BaseActivityTest { private void setupLayer() { Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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"); } }); } @@ -71,18 +55,15 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } @@ -91,19 +72,16 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); - - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } @@ -112,46 +90,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("symbol-placement"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT)); - assertEquals((String) layer.getSymbolPlacement().getValue(), (String) SYMBOL_PLACEMENT_POINT); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testSymbolPlacementAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("symbol-placement"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT)); + assertEquals((String) layer.getSymbolPlacement().getValue(), (String) SYMBOL_PLACEMENT_POINT); }); } @@ -160,47 +104,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("symbol-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(symbolSpacing(0.3f)); - assertEquals((Float) layer.getSymbolSpacing().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testSymbolSpacingAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("symbol-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(symbolSpacing(0.3f)); + assertEquals((Float) layer.getSymbolSpacing().getValue(), (Float) 0.3f); }); } @@ -209,46 +118,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("symbol-avoid-edges"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(symbolAvoidEdges(true)); - assertEquals((Boolean) layer.getSymbolAvoidEdges().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testSymbolAvoidEdgesAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("symbol-avoid-edges"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(symbolAvoidEdges(true)); + assertEquals((Boolean) layer.getSymbolAvoidEdges().getValue(), (Boolean) true); }); } @@ -257,46 +132,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-allow-overlap"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconAllowOverlap(true)); - assertEquals((Boolean) layer.getIconAllowOverlap().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconAllowOverlapAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-allow-overlap"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconAllowOverlap(true)); + assertEquals((Boolean) layer.getIconAllowOverlap().getValue(), (Boolean) true); }); } @@ -305,46 +146,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-ignore-placement"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconIgnorePlacement(true)); - assertEquals((Boolean) layer.getIconIgnorePlacement().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconIgnorePlacementAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-ignore-placement"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconIgnorePlacement(true)); + assertEquals((Boolean) layer.getIconIgnorePlacement().getValue(), (Boolean) true); }); } @@ -353,46 +160,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-optional"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconOptional(true)); - assertEquals((Boolean) layer.getIconOptional().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconOptionalAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-optional"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconOptional(true)); + assertEquals((Boolean) layer.getIconOptional().getValue(), (Boolean) true); }); } @@ -401,46 +174,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-rotation-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); - assertEquals((String) layer.getIconRotationAlignment().getValue(), (String) ICON_ROTATION_ALIGNMENT_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconRotationAlignmentAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-rotation-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); + assertEquals((String) layer.getIconRotationAlignment().getValue(), (String) ICON_ROTATION_ALIGNMENT_MAP); }); } @@ -449,228 +188,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconSize(0.3f)); - assertEquals((Float) layer.getIconSize().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconSizeAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconSize(0.3f)); + assertEquals((Float) layer.getIconSize().getValue(), (Float) 0.3f); }); } @Test - public void testIconSizeAsIdentitySourceFunction() { + public void testIconSizeAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconSize(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getIconSize()); - assertNotNull(layer.getIconSize().getFunction()); - assertEquals(SourceFunction.class, layer.getIconSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconSize().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getIconSize().getFunction().getStops().getClass()); - } - }); - } + Timber.i("icon-size-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconSizeAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconSize( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, iconSize(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getIconSize()); - assertNotNull(layer.getIconSize().getFunction()); - assertEquals(SourceFunction.class, layer.getIconSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconSize().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getIconSize().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconSize(expression)); + assertEquals(layer.getIconSize().getExpression(), expression); }); } - @Test - public void testIconSizeAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconSize( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, iconSize(0.3f)) - ) - ).withDefaultValue(iconSize(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getIconSize()); - assertNotNull(layer.getIconSize().getFunction()); - assertEquals(SourceFunction.class, layer.getIconSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconSize().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getIconSize().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getIconSize().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconSize().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getIconSize().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testIconSizeAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconSize( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, iconSize(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(iconSize(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getIconSize()); - assertNotNull(layer.getIconSize().getFunction()); - assertEquals(CompositeFunction.class, layer.getIconSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconSize().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getIconSize().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getIconSize().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getIconSize().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 testIconTextFitAsConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-text-fit"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTextFit(ICON_TEXT_FIT_NONE)); - assertEquals((String) layer.getIconTextFit().getValue(), (String) ICON_TEXT_FIT_NONE); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconTextFitAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-text-fit"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconTextFit(ICON_TEXT_FIT_NONE)); + assertEquals((String) layer.getIconTextFit().getValue(), (String) ICON_TEXT_FIT_NONE); }); } @@ -679,47 +232,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-text-fit-padding"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconTextFitPaddingAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-text-fit-padding"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconTextFitPadding(new Float[] {0f, 0f, 0f, 0f})); + assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); }); } @@ -728,334 +246,72 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-image"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconImage("undefined")); - assertEquals((String) layer.getIconImage().getValue(), (String) "undefined"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconImageAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-image"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconImage("undefined")); + assertEquals((String) layer.getIconImage().getValue(), (String) "undefined"); }); } @Test - public void testIconImageAsIdentitySourceFunction() { + public void testIconImageAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-image"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconImage(property("FeaturePropertyA", Stops.<String>identity())) - ); - - // Verify - assertNotNull(layer.getIconImage()); - assertNotNull(layer.getIconImage().getFunction()); - assertEquals(SourceFunction.class, layer.getIconImage().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconImage().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getIconImage().getFunction().getStops().getClass()); - } - }); - } + Timber.i("icon-image-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconImageAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-image"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconImage( - property( - "FeaturePropertyA", - interval( - stop(1, iconImage("undefined")) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getIconImage()); - assertNotNull(layer.getIconImage().getFunction()); - assertEquals(SourceFunction.class, layer.getIconImage().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconImage().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getIconImage().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(iconImage(expression)); + assertEquals(layer.getIconImage().getExpression(), expression); }); } + @Test public void testIconRotateAsConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconRotate(0.3f)); - assertEquals((Float) layer.getIconRotate().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconRotateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconRotate(0.3f)); + assertEquals((Float) layer.getIconRotate().getValue(), (Float) 0.3f); }); } @Test - public void testIconRotateAsIdentitySourceFunction() { + public void testIconRotateAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("icon-rotate-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconRotateAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconRotate(expression)); + assertEquals(layer.getIconRotate().getExpression(), expression); }); } - @Test - public void testIconRotateAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconRotate( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, iconRotate(0.3f)) - ) - ).withDefaultValue(iconRotate(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()); - assertNotNull(((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testIconRotateAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconRotate( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, iconRotate(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(iconRotate(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() { validateTestSetup(); setupLayer(); Timber.i("icon-padding"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconPadding(0.3f)); - assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconPaddingAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-padding"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconPadding(0.3f)); + assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); }); } @@ -1064,46 +320,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-keep-upright"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconKeepUpright(true)); - assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconKeepUprightAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-keep-upright"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconKeepUpright(true)); + assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); }); } @@ -1112,104 +334,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconOffsetAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } - - @Test - public void testIconOffsetAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(iconOffset(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -1218,151 +348,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconAnchor(ICON_ANCHOR_CENTER)); - assertEquals((String) layer.getIconAnchor().getValue(), (String) ICON_ANCHOR_CENTER); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconAnchor( - zoom( - interval( - stop(2, iconAnchor(ICON_ANCHOR_CENTER)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getIconAnchor()); - assertNotNull(layer.getIconAnchor().getFunction()); - assertEquals(CameraFunction.class, layer.getIconAnchor().getFunction().getClass()); - assertEquals(IntervalStops.class, layer.getIconAnchor().getFunction().getStops().getClass()); - assertEquals(1, ((IntervalStops) layer.getIconAnchor().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(iconAnchor(ICON_ANCHOR_CENTER)); + assertEquals((String) layer.getIconAnchor().getValue(), (String) ICON_ANCHOR_CENTER); }); } @Test - public void testIconAnchorAsIdentitySourceFunction() { + public void testIconAnchorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconAnchor(property("FeaturePropertyA", Stops.<String>identity())) - ); - - // Verify - assertNotNull(layer.getIconAnchor()); - assertNotNull(layer.getIconAnchor().getFunction()); - assertEquals(SourceFunction.class, layer.getIconAnchor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconAnchor().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getIconAnchor().getFunction().getStops().getClass()); - } - }); - } + Timber.i("icon-anchor-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconAnchorAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconAnchor( - property( - "FeaturePropertyA", - interval( - stop(1, iconAnchor(ICON_ANCHOR_CENTER)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getIconAnchor()); - assertNotNull(layer.getIconAnchor().getFunction()); - assertEquals(SourceFunction.class, layer.getIconAnchor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconAnchor().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getIconAnchor().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(iconAnchor(expression)); + assertEquals(layer.getIconAnchor().getExpression(), expression); }); } + @Test public void testIconPitchAlignmentAsConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-pitch-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconPitchAlignment(ICON_PITCH_ALIGNMENT_MAP)); - assertEquals((String) layer.getIconPitchAlignment().getValue(), (String) ICON_PITCH_ALIGNMENT_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconPitchAlignmentAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-pitch-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconPitchAlignment( - zoom( - interval( - stop(2, iconPitchAlignment(ICON_PITCH_ALIGNMENT_MAP)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getIconPitchAlignment()); - assertNotNull(layer.getIconPitchAlignment().getFunction()); - assertEquals(CameraFunction.class, layer.getIconPitchAlignment().getFunction().getClass()); - assertEquals(IntervalStops.class, layer.getIconPitchAlignment().getFunction().getStops().getClass()); - assertEquals(1, ((IntervalStops) layer.getIconPitchAlignment().getFunction().getStops()).size()); - } + // Set and Get + layer.setProperties(iconPitchAlignment(ICON_PITCH_ALIGNMENT_MAP)); + assertEquals((String) layer.getIconPitchAlignment().getValue(), (String) ICON_PITCH_ALIGNMENT_MAP); }); } @@ -1371,46 +392,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-pitch-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)); - assertEquals((String) layer.getTextPitchAlignment().getValue(), (String) TEXT_PITCH_ALIGNMENT_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextPitchAlignmentAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-pitch-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)); + assertEquals((String) layer.getTextPitchAlignment().getValue(), (String) TEXT_PITCH_ALIGNMENT_MAP); }); } @@ -1419,46 +406,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-rotation-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)); - assertEquals((String) layer.getTextRotationAlignment().getValue(), (String) TEXT_ROTATION_ALIGNMENT_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextRotationAlignmentAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-rotation-alignment"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)); + assertEquals((String) layer.getTextRotationAlignment().getValue(), (String) TEXT_ROTATION_ALIGNMENT_MAP); }); } @@ -1467,208 +420,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-field"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textField("")); - assertEquals((String) layer.getTextField().getValue(), (String) ""); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextFieldAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-field"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textField("")); + assertEquals((String) layer.getTextField().getValue(), (String) ""); }); } @Test - public void testTextFieldAsIdentitySourceFunction() { + public void testTextFieldAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-field"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("text-field-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextFieldAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-field"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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() { - validateTestSetup(); - setupLayer(); - Timber.i("text-font"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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 + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textField(expression)); + assertEquals(layer.getTextField().getExpression(), expression); }); } - @Test - public void testTextFontAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-font"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } @Test - public void testTextFontAsIdentitySourceFunction() { + public void testTextFontAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-font"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textFont(property("FeaturePropertyA", Stops.<String[]>identity())) - ); - - // Verify - assertNotNull(layer.getTextFont()); - assertNotNull(layer.getTextFont().getFunction()); - assertEquals(SourceFunction.class, layer.getTextFont().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextFont().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextFont().getFunction().getStops().getClass()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextFontAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-font"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textFont( - property( - "FeaturePropertyA", - interval( - stop(1, textFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"})) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextFont()); - assertNotNull(layer.getTextFont().getFunction()); - assertEquals(SourceFunction.class, layer.getTextFont().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextFont().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getTextFont().getFunction().getStops().getClass()); - } + // 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"}); }); } @@ -1677,411 +464,72 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textSize(0.3f)); - assertEquals((Float) layer.getTextSize().getValue(), (Float) 0.3f); - } - }); - } - - @Test - public void testTextSizeAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextSizeAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textSize(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getTextSize()); - assertNotNull(layer.getTextSize().getFunction()); - assertEquals(SourceFunction.class, layer.getTextSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextSize().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextSize().getFunction().getStops().getClass()); - } + // Set and Get + layer.setProperties(textSize(0.3f)); + assertEquals((Float) layer.getTextSize().getValue(), (Float) 0.3f); }); } @Test - public void testTextSizeAsExponentialSourceFunction() { + public void testTextSizeAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textSize( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, textSize(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextSize()); - assertNotNull(layer.getTextSize().getFunction()); - assertEquals(SourceFunction.class, layer.getTextSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextSize().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextSize().getFunction().getStops().getClass()); - } - }); - } + Timber.i("text-size-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextSizeAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textSize( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textSize(0.3f)) - ) - ).withDefaultValue(textSize(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextSize()); - assertNotNull(layer.getTextSize().getFunction()); - assertEquals(SourceFunction.class, layer.getTextSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextSize().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getTextSize().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getTextSize().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextSize().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextSize().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textSize(expression)); + assertEquals(layer.getTextSize().getExpression(), expression); }); - } - @Test - public void testTextSizeAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-size"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textSize( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textSize(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textSize(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextSize()); - assertNotNull(layer.getTextSize().getFunction()); - assertEquals(CompositeFunction.class, layer.getTextSize().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextSize().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextSize().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getTextSize().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextSize().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 testTextMaxWidthAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-max-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textMaxWidth(0.3f)); - assertEquals((Float) layer.getTextMaxWidth().getValue(), (Float) 0.3f); - } - }); - } - - @Test - public void testTextMaxWidthAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-max-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextMaxWidthAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-max-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textMaxWidth(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getTextMaxWidth()); - assertNotNull(layer.getTextMaxWidth().getFunction()); - assertEquals(SourceFunction.class, layer.getTextMaxWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextMaxWidth().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextMaxWidth().getFunction().getStops().getClass()); - } + // Set and Get + layer.setProperties(textMaxWidth(0.3f)); + assertEquals((Float) layer.getTextMaxWidth().getValue(), (Float) 0.3f); }); } @Test - public void testTextMaxWidthAsExponentialSourceFunction() { + public void testTextMaxWidthAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-max-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textMaxWidth( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, textMaxWidth(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextMaxWidth()); - assertNotNull(layer.getTextMaxWidth().getFunction()); - assertEquals(SourceFunction.class, layer.getTextMaxWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextMaxWidth().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextMaxWidth().getFunction().getStops().getClass()); - } - }); - } + Timber.i("text-max-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextMaxWidthAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-max-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textMaxWidth( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textMaxWidth(0.3f)) - ) - ).withDefaultValue(textMaxWidth(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextMaxWidth()); - assertNotNull(layer.getTextMaxWidth().getFunction()); - assertEquals(SourceFunction.class, layer.getTextMaxWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextMaxWidth().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getTextMaxWidth().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getTextMaxWidth().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextMaxWidth().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextMaxWidth().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textMaxWidth(expression)); + assertEquals(layer.getTextMaxWidth().getExpression(), expression); }); - } - @Test - public void testTextMaxWidthAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-max-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textMaxWidth( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textMaxWidth(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textMaxWidth(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextMaxWidth()); - assertNotNull(layer.getTextMaxWidth().getFunction()); - assertEquals(CompositeFunction.class, layer.getTextMaxWidth().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextMaxWidth().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextMaxWidth().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getTextMaxWidth().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextMaxWidth().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 testTextLineHeightAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-line-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textLineHeight(0.3f)); - assertEquals((Float) layer.getTextLineHeight().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextLineHeightAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-line-height"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textLineHeight(0.3f)); + assertEquals((Float) layer.getTextLineHeight().getValue(), (Float) 0.3f); }); } @@ -2090,439 +538,102 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-letter-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textLetterSpacing(0.3f)); - assertEquals((Float) layer.getTextLetterSpacing().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextLetterSpacingAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-letter-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textLetterSpacing(0.3f)); + assertEquals((Float) layer.getTextLetterSpacing().getValue(), (Float) 0.3f); }); } @Test - public void testTextLetterSpacingAsIdentitySourceFunction() { + public void testTextLetterSpacingAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-letter-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textLetterSpacing(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getTextLetterSpacing()); - assertNotNull(layer.getTextLetterSpacing().getFunction()); - assertEquals(SourceFunction.class, layer.getTextLetterSpacing().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextLetterSpacing().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextLetterSpacing().getFunction().getStops().getClass()); - } - }); - } + Timber.i("text-letter-spacing-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextLetterSpacingAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-letter-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textLetterSpacing( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, textLetterSpacing(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextLetterSpacing()); - assertNotNull(layer.getTextLetterSpacing().getFunction()); - assertEquals(SourceFunction.class, layer.getTextLetterSpacing().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextLetterSpacing().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextLetterSpacing().getFunction().getStops().getClass()); - } - }); - } - - @Test - public void testTextLetterSpacingAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-letter-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textLetterSpacing( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textLetterSpacing(0.3f)) - ) - ).withDefaultValue(textLetterSpacing(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextLetterSpacing()); - assertNotNull(layer.getTextLetterSpacing().getFunction()); - assertEquals(SourceFunction.class, layer.getTextLetterSpacing().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextLetterSpacing().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getTextLetterSpacing().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getTextLetterSpacing().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextLetterSpacing().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextLetterSpacing().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textLetterSpacing(expression)); + assertEquals(layer.getTextLetterSpacing().getExpression(), expression); }); - } - @Test - public void testTextLetterSpacingAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-letter-spacing"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textLetterSpacing( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textLetterSpacing(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textLetterSpacing(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextLetterSpacing()); - assertNotNull(layer.getTextLetterSpacing().getFunction()); - assertEquals(CompositeFunction.class, layer.getTextLetterSpacing().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextLetterSpacing().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextLetterSpacing().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getTextLetterSpacing().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextLetterSpacing().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 testTextJustifyAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-justify"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textJustify(TEXT_JUSTIFY_LEFT)); - assertEquals((String) layer.getTextJustify().getValue(), (String) TEXT_JUSTIFY_LEFT); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextJustifyAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-justify"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textJustify(TEXT_JUSTIFY_LEFT)); + assertEquals((String) layer.getTextJustify().getValue(), (String) TEXT_JUSTIFY_LEFT); }); } @Test - public void testTextJustifyAsIdentitySourceFunction() { + public void testTextJustifyAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-justify"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textJustify(property("FeaturePropertyA", Stops.<String>identity())) - ); - - // Verify - assertNotNull(layer.getTextJustify()); - assertNotNull(layer.getTextJustify().getFunction()); - assertEquals(SourceFunction.class, layer.getTextJustify().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextJustify().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextJustify().getFunction().getStops().getClass()); - } - }); - } + Timber.i("text-justify-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextJustifyAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-justify"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textJustify( - property( - "FeaturePropertyA", - interval( - stop(1, textJustify(TEXT_JUSTIFY_LEFT)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextJustify()); - assertNotNull(layer.getTextJustify().getFunction()); - assertEquals(SourceFunction.class, layer.getTextJustify().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextJustify().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getTextJustify().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textJustify(expression)); + assertEquals(layer.getTextJustify().getExpression(), expression); }); } + @Test public void testTextAnchorAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textAnchor(TEXT_ANCHOR_CENTER)); - assertEquals((String) layer.getTextAnchor().getValue(), (String) TEXT_ANCHOR_CENTER); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textAnchor(TEXT_ANCHOR_CENTER)); + assertEquals((String) layer.getTextAnchor().getValue(), (String) TEXT_ANCHOR_CENTER); }); } @Test - public void testTextAnchorAsIdentitySourceFunction() { + public void testTextAnchorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textAnchor(property("FeaturePropertyA", Stops.<String>identity())) - ); - - // Verify - assertNotNull(layer.getTextAnchor()); - assertNotNull(layer.getTextAnchor().getFunction()); - assertEquals(SourceFunction.class, layer.getTextAnchor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextAnchor().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextAnchor().getFunction().getStops().getClass()); - } - }); - } + Timber.i("text-anchor-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextAnchorAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textAnchor( - property( - "FeaturePropertyA", - interval( - stop(1, textAnchor(TEXT_ANCHOR_CENTER)) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextAnchor()); - assertNotNull(layer.getTextAnchor().getFunction()); - assertEquals(SourceFunction.class, layer.getTextAnchor().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextAnchor().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getTextAnchor().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textAnchor(expression)); + assertEquals(layer.getTextAnchor().getExpression(), expression); }); } + @Test public void testTextMaxAngleAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-max-angle"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textMaxAngle(0.3f)); - assertEquals((Float) layer.getTextMaxAngle().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextMaxAngleAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-max-angle"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textMaxAngle(0.3f)); + assertEquals((Float) layer.getTextMaxAngle().getValue(), (Float) 0.3f); }); } @@ -2531,229 +642,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textRotate(0.3f)); - assertEquals((Float) layer.getTextRotate().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextRotateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textRotate(0.3f)); + assertEquals((Float) layer.getTextRotate().getValue(), (Float) 0.3f); }); } @Test - public void testTextRotateAsIdentitySourceFunction() { + public void testTextRotateAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textRotate(property("FeaturePropertyA", Stops.<Float>identity())) - ); - - // Verify - assertNotNull(layer.getTextRotate()); - assertNotNull(layer.getTextRotate().getFunction()); - assertEquals(SourceFunction.class, layer.getTextRotate().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextRotate().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextRotate().getFunction().getStops().getClass()); - } - }); - } + Timber.i("text-rotate-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextRotateAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textRotate( - property( - "FeaturePropertyA", - exponential( - stop(0.3f, textRotate(0.3f)) - ).withBase(0.5f) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextRotate()); - assertNotNull(layer.getTextRotate().getFunction()); - assertEquals(SourceFunction.class, layer.getTextRotate().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextRotate().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextRotate().getFunction().getStops().getClass()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textRotate(expression)); + assertEquals(layer.getTextRotate().getExpression(), expression); }); } - @Test - public void testTextRotateAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textRotate( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textRotate(0.3f)) - ) - ).withDefaultValue(textRotate(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextRotate()); - assertNotNull(layer.getTextRotate().getFunction()); - assertEquals(SourceFunction.class, layer.getTextRotate().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextRotate().getFunction()).getProperty()); - assertEquals(CategoricalStops.class, layer.getTextRotate().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.getTextRotate().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextRotate().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextRotate().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testTextRotateAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-rotate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textRotate( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textRotate(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textRotate(0.3f)) - ) - ); - - // Verify - assertNotNull(layer.getTextRotate()); - assertNotNull(layer.getTextRotate().getFunction()); - assertEquals(CompositeFunction.class, layer.getTextRotate().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextRotate().getFunction()).getProperty()); - assertEquals(ExponentialStops.class, layer.getTextRotate().getFunction().getStops().getClass()); - assertEquals(1, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).size()); - - ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops = - (ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextRotate().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 testTextPaddingAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-padding"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textPadding(0.3f)); - assertEquals((Float) layer.getTextPadding().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextPaddingAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-padding"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textPadding(0.3f)); + assertEquals((Float) layer.getTextPadding().getValue(), (Float) 0.3f); }); } @@ -2762,46 +686,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-keep-upright"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textKeepUpright(true)); - assertEquals((Boolean) layer.getTextKeepUpright().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextKeepUprightAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-keep-upright"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textKeepUpright(true)); + assertEquals((Boolean) layer.getTextKeepUpright().getValue(), (Boolean) true); }); } @@ -2810,209 +700,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-transform"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textTransform(TEXT_TRANSFORM_NONE)); - assertEquals((String) layer.getTextTransform().getValue(), (String) TEXT_TRANSFORM_NONE); - } - }); - } - - @Test - public void testTextTransformAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-transform"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextTransformAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-transform"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(textTransform(TEXT_TRANSFORM_NONE)); + assertEquals((String) layer.getTextTransform().getValue(), (String) TEXT_TRANSFORM_NONE); }); } @Test - public void testTextTransformAsIntervalSourceFunction() { + public void testTextTransformAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-transform"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("text-transform-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextOffsetAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("text-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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 + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textTransform(expression)); + assertEquals(layer.getTextTransform().getExpression(), expression); }); } - @Test - public void testTextOffsetAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } @Test - public void testTextOffsetAsIdentitySourceFunction() { + public void testTextOffsetAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textOffset(property("FeaturePropertyA", Stops.<Float[]>identity())) - ); - - // Verify - assertNotNull(layer.getTextOffset()); - assertNotNull(layer.getTextOffset().getFunction()); - assertEquals(SourceFunction.class, layer.getTextOffset().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOffset().getFunction()).getProperty()); - assertEquals(IdentityStops.class, layer.getTextOffset().getFunction().getStops().getClass()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextOffsetAsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-offset"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textOffset( - property( - "FeaturePropertyA", - interval( - stop(1, textOffset(new Float[] {0f, 0f})) - ) - ) - ) - ); - - // Verify - assertNotNull(layer.getTextOffset()); - assertNotNull(layer.getTextOffset().getFunction()); - assertEquals(SourceFunction.class, layer.getTextOffset().getFunction().getClass()); - assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOffset().getFunction()).getProperty()); - assertEquals(IntervalStops.class, layer.getTextOffset().getFunction().getStops().getClass()); - } + // Set and Get + layer.setProperties(textOffset(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -3021,46 +744,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-allow-overlap"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textAllowOverlap(true)); - assertEquals((Boolean) layer.getTextAllowOverlap().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextAllowOverlapAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-allow-overlap"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textAllowOverlap(true)); + assertEquals((Boolean) layer.getTextAllowOverlap().getValue(), (Boolean) true); }); } @@ -3069,46 +758,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-ignore-placement"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textIgnorePlacement(true)); - assertEquals((Boolean) layer.getTextIgnorePlacement().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextIgnorePlacementAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-ignore-placement"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textIgnorePlacement(true)); + assertEquals((Boolean) layer.getTextIgnorePlacement().getValue(), (Boolean) true); }); } @@ -3117,46 +772,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-optional"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textOptional(true)); - assertEquals((Boolean) layer.getTextOptional().getValue(), (Boolean) true); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextOptionalAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-optional"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textOptional(true)); + assertEquals((Boolean) layer.getTextOptional().getValue(), (Boolean) true); }); } @@ -3165,216 +786,58 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setIconOpacityTransition(options); - assertEquals(layer.getIconOpacityTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconOpacityAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconOpacity(0.3f)); - assertEquals((Float) layer.getIconOpacity().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconOpacityTransition(options); + assertEquals(layer.getIconOpacityTransition(), options); }); } @Test - public void testIconOpacityAsCameraFunction() { + public void testIconOpacityAsConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconOpacityAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(iconOpacity(0.3f)); + assertEquals((Float) layer.getIconOpacity().getValue(), (Float) 0.3f); }); } @Test - public void testIconOpacityAsExponentialSourceFunction() { + public void testIconOpacityAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("icon-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconOpacityAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconOpacity( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, iconOpacity(0.3f)) - ) - ).withDefaultValue(iconOpacity(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()); - assertNotNull(((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconOpacity(expression)); + assertEquals(layer.getIconOpacity().getExpression(), expression); }); - } - @Test - public void testIconOpacityAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconOpacity( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, iconOpacity(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(iconOpacity(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 testIconColorTransition() { validateTestSetup(); setupLayer(); Timber.i("icon-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setIconColorTransition(options); - assertEquals(layer.getIconColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconColorTransition(options); + assertEquals(layer.getIconColorTransition(), options); }); } @@ -3383,157 +846,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getIconColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testIconColorAsIdentitySourceFunction() { + public void testIconColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("icon-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(iconColor(expression)); + assertEquals(layer.getIconColor().getExpression(), expression); }); } - @Test - public void testIconColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", iconColor(Color.RED)) - ) - ).withDefaultValue(iconColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getIconColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getIconColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testIconColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconColor(Color.RED)); - assertEquals(layer.getIconColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconColor(Color.RED)); + assertEquals(layer.getIconColorAsInt(), Color.RED); }); } @@ -3542,16 +890,13 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-halo-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setIconHaloColorTransition(options); - assertEquals(layer.getIconHaloColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconHaloColorTransition(options); + assertEquals(layer.getIconHaloColorTransition(), options); }); } @@ -3560,157 +905,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getIconHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testIconHaloColorAsIdentitySourceFunction() { + public void testIconHaloColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("icon-halo-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(iconHaloColor(expression)); + assertEquals(layer.getIconHaloColor().getExpression(), expression); }); } - @Test - public void testIconHaloColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconHaloColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", iconHaloColor(Color.RED)) - ) - ).withDefaultValue(iconHaloColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getIconHaloColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconHaloColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getIconHaloColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testIconHaloColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloColor(Color.RED)); - assertEquals(layer.getIconHaloColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconHaloColor(Color.RED)); + assertEquals(layer.getIconHaloColorAsInt(), Color.RED); }); } @@ -3719,16 +949,13 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-halo-widthTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setIconHaloWidthTransition(options); - assertEquals(layer.getIconHaloWidthTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconHaloWidthTransition(options); + assertEquals(layer.getIconHaloWidthTransition(), options); }); } @@ -3737,398 +964,88 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloWidth(0.3f)); - assertEquals((Float) layer.getIconHaloWidth().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloWidthAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconHaloWidth(0.3f)); + assertEquals((Float) layer.getIconHaloWidth().getValue(), (Float) 0.3f); }); } @Test - public void testIconHaloWidthAsIdentitySourceFunction() { + public void testIconHaloWidthAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("icon-halo-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloWidthAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconHaloWidth( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, iconHaloWidth(0.3f)) - ) - ).withDefaultValue(iconHaloWidth(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()); - assertNotNull(((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconHaloWidth(expression)); + assertEquals(layer.getIconHaloWidth().getExpression(), expression); }); - } - @Test - public void testIconHaloWidthAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconHaloWidth( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, iconHaloWidth(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(iconHaloWidth(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 testIconHaloBlurTransition() { validateTestSetup(); setupLayer(); Timber.i("icon-halo-blurTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setIconHaloBlurTransition(options); - assertEquals(layer.getIconHaloBlurTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloBlurAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloBlur(0.3f)); - assertEquals((Float) layer.getIconHaloBlur().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconHaloBlurTransition(options); + assertEquals(layer.getIconHaloBlurTransition(), options); }); } @Test - public void testIconHaloBlurAsCameraFunction() { + public void testIconHaloBlurAsConstant() { validateTestSetup(); setupLayer(); Timber.i("icon-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloBlurAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(iconHaloBlur(0.3f)); + assertEquals((Float) layer.getIconHaloBlur().getValue(), (Float) 0.3f); }); } @Test - public void testIconHaloBlurAsExponentialSourceFunction() { + public void testIconHaloBlurAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("icon-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("icon-halo-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconHaloBlurAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconHaloBlur( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, iconHaloBlur(0.3f)) - ) - ).withDefaultValue(iconHaloBlur(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()); - assertNotNull(((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconHaloBlur(expression)); + assertEquals(layer.getIconHaloBlur().getExpression(), expression); }); - } - @Test - public void testIconHaloBlurAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - iconHaloBlur( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, iconHaloBlur(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(iconHaloBlur(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 testIconTranslateTransition() { validateTestSetup(); setupLayer(); Timber.i("icon-translateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setIconTranslateTransition(options); - assertEquals(layer.getIconTranslateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconTranslateTransition(options); + assertEquals(layer.getIconTranslateTransition(), options); }); } @@ -4137,47 +1054,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconTranslateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -4186,46 +1068,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("icon-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getIconTranslateAnchor().getValue(), (String) ICON_TRANSLATE_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testIconTranslateAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("icon-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getIconTranslateAnchor().getValue(), (String) ICON_TRANSLATE_ANCHOR_MAP); }); } @@ -4234,216 +1082,58 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-opacityTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setTextOpacityTransition(options); - assertEquals(layer.getTextOpacityTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextOpacityAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("text-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textOpacity(0.3f)); - assertEquals((Float) layer.getTextOpacity().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextOpacityTransition(options); + assertEquals(layer.getTextOpacityTransition(), options); }); } @Test - public void testTextOpacityAsCameraFunction() { + public void testTextOpacityAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextOpacityAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(textOpacity(0.3f)); + assertEquals((Float) layer.getTextOpacity().getValue(), (Float) 0.3f); }); } @Test - public void testTextOpacityAsExponentialSourceFunction() { + public void testTextOpacityAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("text-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextOpacityAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textOpacity( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textOpacity(0.3f)) - ) - ).withDefaultValue(textOpacity(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()); - assertNotNull(((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textOpacity(expression)); + assertEquals(layer.getTextOpacity().getExpression(), expression); }); - } - @Test - public void testTextOpacityAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-opacity"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textOpacity( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textOpacity(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textOpacity(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 testTextColorTransition() { validateTestSetup(); setupLayer(); Timber.i("text-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setTextColorTransition(options); - assertEquals(layer.getTextColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextColorTransition(options); + assertEquals(layer.getTextColorTransition(), options); }); } @@ -4452,157 +1142,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getTextColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // 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 testTextColorAsIdentitySourceFunction() { + public void testTextColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("text-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(textColor(expression)); + assertEquals(layer.getTextColor().getExpression(), expression); }); } - @Test - public void testTextColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", textColor(Color.RED)) - ) - ).withDefaultValue(textColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getTextColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getTextColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testTextColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("text-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textColor(Color.RED)); - assertEquals(layer.getTextColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textColor(Color.RED)); + assertEquals(layer.getTextColorAsInt(), Color.RED); }); } @@ -4611,16 +1186,13 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-halo-colorTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setTextHaloColorTransition(options); - assertEquals(layer.getTextHaloColorTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextHaloColorTransition(options); + assertEquals(layer.getTextHaloColorTransition(), options); }); } @@ -4629,157 +1201,42 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getTextHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloColorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // 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 testTextHaloColorAsIdentitySourceFunction() { + public void testTextHaloColorAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + Timber.i("text-halo-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloColorAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(textHaloColor(expression)); + assertEquals(layer.getTextHaloColor().getExpression(), expression); }); } - @Test - public void testTextHaloColorAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textHaloColor( - property( - "FeaturePropertyA", - categorical( - stop("valueA", textHaloColor(Color.RED)) - ) - ).withDefaultValue(textHaloColor(Color.GREEN)) - ) - ); - - // 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()); - assertNotNull(((SourceFunction) layer.getTextHaloColor().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextHaloColor().getFunction()).getDefaultValue().getValue()); - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getTextHaloColor().getFunction()).getDefaultValue().getColorInt()); - } - }); - - } @Test public void testTextHaloColorAsIntConstant() { validateTestSetup(); setupLayer(); Timber.i("text-halo-color"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloColor(Color.RED)); - assertEquals(layer.getTextHaloColorAsInt(), Color.RED); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textHaloColor(Color.RED)); + assertEquals(layer.getTextHaloColorAsInt(), Color.RED); }); } @@ -4788,216 +1245,58 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-halo-widthTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setTextHaloWidthTransition(options); - assertEquals(layer.getTextHaloWidthTransition(), options); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloWidthAsConstant() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloWidth(0.3f)); - assertEquals((Float) layer.getTextHaloWidth().getValue(), (Float) 0.3f); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextHaloWidthTransition(options); + assertEquals(layer.getTextHaloWidthTransition(), options); }); } @Test - public void testTextHaloWidthAsCameraFunction() { + public void testTextHaloWidthAsConstant() { validateTestSetup(); setupLayer(); Timber.i("text-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloWidthAsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(textHaloWidth(0.3f)); + assertEquals((Float) layer.getTextHaloWidth().getValue(), (Float) 0.3f); }); } @Test - public void testTextHaloWidthAsExponentialSourceFunction() { + public void testTextHaloWidthAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("text-halo-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloWidthAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textHaloWidth( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textHaloWidth(0.3f)) - ) - ).withDefaultValue(textHaloWidth(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()); - assertNotNull(((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue().getValue()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textHaloWidth(expression)); + assertEquals(layer.getTextHaloWidth().getExpression(), expression); }); - } - @Test - public void testTextHaloWidthAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-width"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textHaloWidth( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textHaloWidth(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textHaloWidth(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 testTextHaloBlurTransition() { validateTestSetup(); setupLayer(); Timber.i("text-halo-blurTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setTextHaloBlurTransition(options); - assertEquals(layer.getTextHaloBlurTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextHaloBlurTransition(options); + assertEquals(layer.getTextHaloBlurTransition(), options); }); } @@ -5006,198 +1305,43 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloBlur(0.3f)); - assertEquals((Float) layer.getTextHaloBlur().getValue(), (Float) 0.3f); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloBlurAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textHaloBlur(0.3f)); + assertEquals((Float) layer.getTextHaloBlur().getValue(), (Float) 0.3f); }); } @Test - public void testTextHaloBlurAsIdentitySourceFunction() { + public void testTextHaloBlurAsExpression() { validateTestSetup(); setupLayer(); - Timber.i("text-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } - }); - } + Timber.i("text-halo-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextHaloBlurAsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textHaloBlur(expression)); + assertEquals(layer.getTextHaloBlur().getExpression(), expression); }); } - @Test - public void testTextHaloBlurAsCategoricalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textHaloBlur( - property( - "FeaturePropertyA", - categorical( - stop(1.0f, textHaloBlur(0.3f)) - ) - ).withDefaultValue(textHaloBlur(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()); - assertNotNull(((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue().getValue()); - assertEquals(0.3f, ((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue().getValue()); - } - }); - - } - - @Test - public void testTextHaloBlurAsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-halo-blur"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - textHaloBlur( - composite( - "FeaturePropertyA", - exponential( - stop(0, 0.3f, textHaloBlur(0.9f)) - ).withBase(0.5f) - ).withDefaultValue(textHaloBlur(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 testTextTranslateTransition() { validateTestSetup(); setupLayer(); Timber.i("text-translateTransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.setTextTranslateTransition(options); - assertEquals(layer.getTextTranslateTransition(), options); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextTranslateTransition(options); + assertEquals(layer.getTextTranslateTransition(), options); }); } @@ -5206,47 +1350,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextTranslateAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-translate"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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()); - } + // Set and Get + layer.setProperties(textTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); }); } @@ -5255,47 +1364,12 @@ public class SymbolLayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("text-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set and Get - layer.setProperties(textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); - } - }); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - @Test - public void testTextTranslateAnchorAsCameraFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("text-translate-anchor"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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()); - } + // Set and Get + layer.setProperties(textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); }); } - -} +}
\ No newline at end of file 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 4e014c4384..09d4328b70 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 @@ -7,31 +7,18 @@ package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; -import android.support.test.espresso.UiController; 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.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; 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 com.mapbox.mapboxsdk.style.expressions.Expression.*; import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; import static org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; @@ -56,25 +43,19 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { private void setupLayer() { <% if (type === 'background') { -%> Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - layer = mapboxMap.getLayerAs("background"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + layer = mapboxMap.getLayerAs("background"); }); <% } else { -%> Timber.i("Retrieving layer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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"); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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"); } }); <% } -%> @@ -85,18 +66,15 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("Visibility"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); }); } <% if (!(type === 'background' || type === 'raster' || type === 'hillshade')) { -%> @@ -106,19 +84,16 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Get initial - assertEquals(layer.getSourceLayer(), "composite"); + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); - // Set - final String sourceLayer = "test"; - layer.setSourceLayer(sourceLayer); - assertEquals(layer.getSourceLayer(), sourceLayer); - } + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); }); } <% } -%> @@ -131,16 +106,13 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("<%- property.name %>TransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - layer.set<%- camelize(property.name) %>Transition(options); - assertEquals(layer.get<%- camelize(property.name) %>Transition(), options); - } + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.set<%- camelize(property.name) %>Transition(options); + assertEquals(layer.get<%- camelize(property.name) %>Transition(), options); }); } <% } -%> @@ -150,291 +122,32 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + 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) %>); - } + // 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)) { -%> +<% if (isDataDriven(property)) { -%> +<% if (!(property.name.endsWith("-font")||property.name.endsWith("-offset"))) { -%> @Test - public void test<%- camelize(property.name) %>AsCameraFunction() { + public void test<%- camelize(property.name) %>AsExpression() { validateTestSetup(); setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - <%- camelizeWithLeadingLowercase(property.name) %>( - zoom( -<% if (property.function == 'piecewise-constant') { -%> - interval( - stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) - ) -<% } else { -%> - exponential( - stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) - ).withBase(0.5f) -<% } -%> - ) - ) - ); - - // 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)) { -%> - - @Test - public void test<%- camelize(property.name) %>AsIdentitySourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - <%- camelizeWithLeadingLowercase(property.name) %>(property("FeaturePropertyA", Stops.<<%- propertyType(property) %>>identity())) - ); - - // 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()); - } + Timber.i("<%- property.name %>-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = <%- defaultExpressionJava(property) %>(Expression.get("undefined")); + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(expression)); + assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), expression); }); } -<% if (property.function == 'piecewise-constant') { -%> - - @Test - public void test<%- camelize(property.name) %>AsIntervalSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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() { - validateTestSetup(); - setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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 { -%> - - @Test - public void test<%- camelize(property.name) %>AsExponentialSourceFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - 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) %>)) -<% } -%> - ).withBase(0.5f) - ) - ) - ); - - // 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() { - validateTestSetup(); - setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // Set - layer.setProperties( - <%- camelizeWithLeadingLowercase(property.name) %>( - property( - "FeaturePropertyA", - categorical( -<% if (property.type == 'color') { -%> - stop("valueA", <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) - ) - ).withDefaultValue(<%- camelizeWithLeadingLowercase(property.name) %>(Color.GREEN)) -<% } else {-%> - stop(1.0f, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) - ) - ).withDefaultValue(<%- 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(CategoricalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); - assertNotNull(((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue()); - assertNotNull(((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue().getValue()); -<% if (property.type === 'color') { -%> - assertEquals(Color.GREEN, (int) ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue().getColorInt()); -<% } else { -%> - assertEquals(<%- defaultValueJava(property) %>, ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue().getValue()); -<% } -%> - } - }); - - } -<% if (property.type !== 'color') { -%> - - @Test - public void test<%- camelize(property.name) %>AsCompositeFunction() { - validateTestSetup(); - setupLayer(); - Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); - - // 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(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) -<% } else { -%> - ) -<% } -%> - ) - ); - - // 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') { -%> @@ -444,19 +157,15 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { validateTestSetup(); setupLayer(); Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(layer); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); - // Set and Get - layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); - assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); - } + // Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); + assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); }); } <% } -%> <% } -%> <% } -%> - -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/light.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/light.junit.ejs index 2f22a8f3f0..96f23871c5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/light.junit.ejs +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/light.junit.ejs @@ -9,15 +9,12 @@ import android.support.test.espresso.ViewAction; import android.support.test.runner.AndroidJUnit4; import android.view.View; -import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.style.light.Light; -import com.mapbox.mapboxsdk.style.functions.Function; -import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; import com.mapbox.mapboxsdk.style.light.Position; import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; import com.mapbox.mapboxsdk.testapp.activity.style.FillExtrusionStyleTestActivity; @@ -53,15 +50,12 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("<%- property.name %>TransitionOptions"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - TransitionOptions options = new TransitionOptions(300, 100); - light.set<%- camelize(property.name) %>Transition(options); - assertEquals("Transition options should match", options, light.get<%- camelize(property.name) %>Transition()); - } + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.set<%- camelize(property.name) %>Transition(options); + assertEquals("Transition options should match", options, light.get<%- camelize(property.name) %>Transition()); }); } <% } -%> @@ -72,15 +66,12 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - Position position = new Position(1, 2, 3); - light.set<%- camelize(property.name) %>(position); - assertEquals("Position should match", position, light.get<%- camelize(property.name) %>()); - } + invoke(mapboxMap,(uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + Position position = new Position(1, 2, 3); + light.set<%- camelize(property.name) %>(position); + assertEquals("Position should match", position, light.get<%- camelize(property.name) %>()); }); } <% } else { -%> @@ -90,18 +81,15 @@ public class LightTest extends BaseActivityTest { validateTestSetup(); setupLight(); Timber.i("<%- property.name %>"); - invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { - @Override - public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { - assertNotNull(light); - // Set and Get - light.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>); <% if (property.name == 'color') { -%> - assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>.replaceAll("\\s+", ""), light.get<%- camelize(property.name) %>()); + assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>.replaceAll("\\s+", ""), light.get<%- camelize(property.name) %>()); <% } else { -%> - assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>, light.get<%- camelize(property.name) %>()); + assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>, light.get<%- camelize(property.name) %>()); <% } -%> - } }); } <% } -%> @@ -128,8 +116,8 @@ public class LightTest extends BaseActivityTest { fillExtrusionLayer.setMinZoom(15); fillExtrusionLayer.setProperties( fillExtrusionColor(Color.LTGRAY), - fillExtrusionHeight(Function.property("height", new IdentityStops<Float>())), - fillExtrusionBase(Function.property("min_height", new IdentityStops<Float>())), + fillExtrusionHeight(Expression.get("height")), + fillExtrusionBase(Expression.get("min_height")), fillExtrusionOpacity(0.6f) ); mapboxMap.addLayer(fillExtrusionLayer); @@ -141,4 +129,4 @@ public class LightTest extends BaseActivityTest { protected Class getActivityClass() { return FillExtrusionStyleTestActivity.class; } -} +}
\ No newline at end of file |