summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs
diff options
context:
space:
mode:
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.ejs367
1 files changed, 288 insertions, 79 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 3b81b0805b..f1d68caa24 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs
@@ -3,6 +3,7 @@
const properties = locals.properties;
-%>
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`.
+
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
@@ -12,6 +13,15 @@ import android.support.test.runner.AndroidJUnit4;
import timber.log.Timber;
import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
+import com.mapbox.mapboxsdk.style.functions.CameraFunction;
+import com.mapbox.mapboxsdk.style.functions.SourceFunction;
+import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops;
+import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops;
+import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
+import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops;
+import com.mapbox.mapboxsdk.style.functions.stops.Stop;
+import com.mapbox.mapboxsdk.style.functions.stops.Stops;
import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity;
@@ -23,6 +33,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import static com.mapbox.mapboxsdk.style.functions.Function.*;
+import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
+import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
import static org.junit.Assert.*;
import static com.mapbox.mapboxsdk.style.layers.Property.*;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*;
@@ -33,112 +46,308 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*;
@RunWith(AndroidJUnit4.class)
public class <%- camelize(type) %>LayerTest extends BaseStyleTest {
- @Rule
- public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class);
+ @Rule
+ public final ActivityTestRule<RuntimeStyleTestActivity> rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class);
+
+ private <%- camelize(type) %>Layer layer;
- private <%- camelize(type) %>Layer layer;
+ private OnMapReadyIdlingResource idlingResource;
- private OnMapReadyIdlingResource idlingResource;
+ private MapboxMap mapboxMap;
- private MapboxMap mapboxMap;
+ @Before
+ public void setup() {
+ idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
+ Espresso.registerIdlingResources(idlingResource);
+ mapboxMap = rule.getActivity().getMapboxMap();
- @Before
- public void setup() {
- idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
- Espresso.registerIdlingResources(idlingResource);
+<% if (type === 'background') { -%>
+ Timber.i("Retrieving layer");
+ layer = mapboxMap.getLayerAs("background");
+<% } else { -%>
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Timber.i("Adding layer");
+ layer = new <%- camelize(type) %>Layer("my-layer", "composite");
+ layer.setSourceLayer("composite");
+ mapboxMap.addLayer(layer);
+ // Layer reference is now stale, get new reference
+ layer = mapboxMap.getLayerAs("my-layer");
}
+<% } -%>
+ }
- @Test
- public void testSetVisibility() {
- checkViewIsDisplayed(R.id.mapView);
+ @Test
+ public void testSetVisibility() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("Visibility");
+ assertNotNull(layer);
- mapboxMap = rule.getActivity().getMapboxMap();
+ // Get initial
+ assertEquals(layer.getVisibility().getValue(), VISIBLE);
-<% if (type === 'background') { -%>
- Timber.i("Retrieving layer");
- layer = mapboxMap.getLayerAs("background");
+ // Set
+ layer.setProperties(visibility(NONE));
+ assertEquals(layer.getVisibility().getValue(), NONE);
+ }
+
+<% for (const property of properties) { -%>
+ @Test
+ public void test<%- camelize(property.name) %>AsConstant() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set and Get
+ layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>));
+ assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>);
+ }
+<% if (supportsZoomFunction(property)) { -%>
+
+ @Test
+ public void test<%- camelize(property.name) %>AsCameraFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(
+ zoom(
+<% if (property.function == 'piecewise-constant') { -%>
+ interval(
+ stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
+ )
<% } else { -%>
- if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
- Timber.i("Adding layer");
- layer = new <%- camelize(type) %>Layer("my-layer", "composite");
- layer.setSourceLayer("composite");
- mapboxMap.addLayer(layer);
- //Layer reference is now stale, get new reference
- layer = mapboxMap.getLayerAs("my-layer");
- }
+ exponential(
+ stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
+ ).withBase(0.5f)
<% } -%>
- Timber.i("visibility");
- assertNotNull(layer);
+ )
+ )
+ );
- //Get initial
- assertEquals(layer.getVisibility().getValue(), VISIBLE);
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(CameraFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+<% if (property.function == 'piecewise-constant') { -%>
+ assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ assertEquals(1, ((IntervalStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size());
+<% } else { -%>
+ assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ assertEquals(0.5f, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).getBase(), 0.001);
+ assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size());
+<% } -%>
+ }
+<% } -%>
+<% if (supportsPropertyFunction(property)) { -%>
- //Set
- layer.setProperties(visibility(NONE));
- assertEquals(layer.getVisibility().getValue(), NONE);
- }
+ @Test
+ public void test<%- camelize(property.name) %>AsIdentitySourceFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
-<% for (const property of properties) { -%>
- @Test
- public void test<%- camelize(property.name) %>() {
- checkViewIsDisplayed(R.id.mapView);
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(property("FeaturePropertyA", Stops.<<%- propertyType(property) %>>identity()))
+ );
- mapboxMap = rule.getActivity().getMapboxMap();
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+ assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
+ assertEquals(IdentityStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ }
+<% if (property.function == 'piecewise-constant') { -%>
-<% if (type === 'background') { -%>
- Timber.i("Retrieving layer");
- layer = mapboxMap.getLayerAs("background");
+ @Test
+ public void test<%- camelize(property.name) %>AsIntervalSourceFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(
+ property(
+ "FeaturePropertyA",
+ interval(
+<% if (property.type == 'color') { -%>
+ stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
+<% } else {-%>
+ stop(1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
+ )
+<% } -%>
+ )
+ )
+ );
+
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+ assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
+ assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ }
+<% } else if (property.type === 'array') { -%>
+
+ @Test
+ public void test<%- camelize(property.name) %>AsIntervalSourceFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(
+ property(
+ "FeaturePropertyA",
+ interval(
+<% if (property.type == 'color') { -%>
+ stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
+<% } else {-%>
+ stop(1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
+<% } -%>
+ )
+ )
+ )
+ );
+
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+ assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
+ assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ }
<% } else { -%>
- if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
- Timber.i("Adding layer");
- layer = new <%- camelize(type) %>Layer("my-layer", "composite");
- layer.setSourceLayer("composite");
- mapboxMap.addLayer(layer);
- //Layer reference is now stale, get new reference
- layer = mapboxMap.getLayerAs("my-layer");
- }
+
+ @Test
+ public void test<%- camelize(property.name) %>AsExponentialSourceFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(
+ property(
+ "FeaturePropertyA",
+ exponential(
+<% if (property.type == 'color') { -%>
+ stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
+<% } else {-%>
+ stop(<%- defaultValueJava(property) %>, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
<% } -%>
- Timber.i("<%- property.name %>");
- assertNotNull(layer);
+ ).withBase(0.5f)
+ )
+ )
+ );
- //Set and Get
- layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>));
- assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>);
- }
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+ assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
+ assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ }
+
+ @Test
+ public void test<%- camelize(property.name) %>AsCategoricalSourceFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(
+ property(
+ "FeaturePropertyA",
+ categorical(
<% if (property.type == 'color') { -%>
+ stop("valueA", <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
+ )
+ )
+<% } else {-%>
+ stop(1.0f, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
+ )
+ ).withDefaultValue(<%- defaultValueJava(property) %>)
+<% } -%>
+ )
+ );
- @Test
- public void test<%- camelize(property.name) %>AsInt() {
- checkViewIsDisplayed(R.id.mapView);
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+ assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
+ assertEquals(CategoricalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+<% if (property.type !== 'color') { -%>
+ assertEquals(<%- defaultValueJava(property) %>, ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue());
+<% } -%>
+ }
+<% if (property.type !== 'color') { -%>
- mapboxMap = rule.getActivity().getMapboxMap();
+ @Test
+ public void test<%- camelize(property.name) %>AsCompositeFunction() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
-<% if (type === 'background') { -%>
- Timber.i("Retrieving layer");
- layer = mapboxMap.getLayerAs("background");
+ // Set
+ layer.setProperties(
+ <%- camelizeWithLeadingLowercase(property.name) %>(
+ composite(
+ "FeaturePropertyA",
+ exponential(
+ stop(0, 0.3f, <%- camelizeWithLeadingLowercase(property.name) %>(0.9f))
+ ).withBase(0.5f)
+<% if (property.type == 'number') { -%>
+ ).withDefaultValue(<%- defaultValueJava(property) %>)
<% } else { -%>
- if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
- Timber.i("Adding layer");
- layer = new <%- camelize(type) %>Layer("my-layer", "composite");
- layer.setSourceLayer("composite");
- mapboxMap.addLayer(layer);
- //Layer reference is now stale, get new reference
- layer = mapboxMap.getLayerAs("my-layer");
- }
+ )
<% } -%>
- Timber.i("<%- property.name %>");
- assertNotNull(layer);
+ )
+ );
- //Set and Get
- layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED));
- assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED);
- }
+ // Verify
+ assertNotNull(layer.get<%- camelize(property.name) %>());
+ assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
+ assertEquals(CompositeFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
+ assertEquals("FeaturePropertyA", ((CompositeFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
+ assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
+ assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size());
+
+ ExponentialStops<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>> stops =
+ (ExponentialStops<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>>) layer.get<%- camelize(property.name) %>().getFunction().getStops();
+ Stop<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>> stop = stops.iterator().next();
+ assertEquals(0f, stop.in.zoom, 0.001);
+ assertEquals(0.3f, stop.in.value, 0.001f);
+ assertEquals(0.9f, stop.out, 0.001f);
+ }
+<% } -%>
+<% } -%>
+<% } -%>
+<% if (property.type == 'color') { -%>
+
+ @Test
+ public void test<%- camelize(property.name) %>AsIntConstant() {
+ checkViewIsDisplayed(R.id.mapView);
+ Timber.i("<%- property.name %>");
+ assertNotNull(layer);
+
+ // Set and Get
+ layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED));
+ assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED);
+ }
<% } -%>
<% } -%>
- @After
- public void unregisterIntentServiceIdlingResource() {
- Espresso.unregisterIdlingResources(idlingResource);
- }
+ @After
+ public void unregisterIntentServiceIdlingResource() {
+ Espresso.unregisterIdlingResources(idlingResource);
+ }
}