<% const type = locals.type; 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; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.style.functions.CompositeFunction; import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.functions.SourceFunction; import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; import org.junit.After; import org.junit.Before; 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.*; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; /** * Basic smoke tests for <%- camelize(type) %>Layer */ @RunWith(AndroidJUnit4.class) public class <%- camelize(type) %>LayerTest extends BaseActivityTest { private <%- camelize(type) %>Layer layer; @Override protected Class getActivityClass() { return EspressoTestActivity.class; } private void setupLayer(){ <% 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() { validateTestSetup(); setupLayer(); Timber.i("Visibility"); assertNotNull(layer); // Get initial assertEquals(layer.getVisibility().getValue(), VISIBLE); // Set layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } <% if (!(type === 'background' || type === 'raster')) { -%> @Test public void testSourceLayer() { validateTestSetup(); setupLayer(); Timber.i("SourceLayer"); assertNotNull(layer); // Get initial assertEquals(layer.getSourceLayer(), "composite"); // Set final String sourceLayer = "test"; layer.setSourceLayer(sourceLayer); assertEquals(layer.getSourceLayer(), sourceLayer); } <% } -%> <% for (const property of properties) { -%> <% if (property.transition) { -%> @Test public void test<%- camelize(property.name) %>Transition() { validateTestSetup(); setupLayer(); Timber.i("<%- property.name %>TransitionOptions"); 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); } <% } -%> @Test public void test<%- camelize(property.name) %>AsConstant() { validateTestSetup(); setupLayer(); 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() { validateTestSetup(); setupLayer(); 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 { -%> 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 %>"); 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()); } <% if (property.function == 'piecewise-constant') { -%> @Test public void test<%- camelize(property.name) %>AsIntervalSourceFunction() { validateTestSetup(); setupLayer(); 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() { validateTestSetup(); setupLayer(); 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 { -%> @Test public void test<%- camelize(property.name) %>AsExponentialSourceFunction() { validateTestSetup(); setupLayer(); 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) %>)) <% } -%> ).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 %>"); 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 %>"); 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>, <%- propertyType(property) %>> stops = (ExponentialStops>, <%- propertyType(property) %>>) layer.get<%- camelize(property.name) %>().getFunction().getStops(); Stop>, <%- 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() { validateTestSetup(); setupLayer(); 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); } <% } -%> <% } -%> }