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/testapp/style/layer.junit.ejs | |
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/testapp/style/layer.junit.ejs')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs | 401 |
1 files changed, 55 insertions, 346 deletions
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 |