From 732cd8d20acfb9b97f76393962035d5374e84bb8 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Sun, 5 Mar 2017 01:06:44 -0800 Subject: [android] use PropertyValue for default values in functions --- .../style/functions/CompositeFunction.java | 11 ++-- .../mapboxsdk/style/functions/SourceFunction.java | 11 ++-- .../mapboxsdk/style/layers/PropertyValue.java | 28 +++++++- .../mapboxsdk/testapp/style/CircleLayerTest.java | 50 +++++++++----- .../mapboxsdk/testapp/style/FillLayerTest.java | 18 +++-- .../mapboxsdk/testapp/style/LineLayerTest.java | 37 +++++++---- .../mapboxsdk/testapp/style/SymbolLayerTest.java | 76 +++++++++++++++------- .../mapbox/mapboxsdk/testapp/style/layer.junit.ejs | 14 ++-- 8 files changed, 169 insertions(+), 76 deletions(-) (limited to 'platform') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java index 1db14afc5f..8ded7ecd34 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java @@ -8,6 +8,7 @@ import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; 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.PropertyValue; import java.util.Map; @@ -27,7 +28,7 @@ import java.util.Map; public class CompositeFunction extends Function, O> { private final String property; - private O defaultValue; + private PropertyValue defaultValue; CompositeFunction(@NonNull String property, @NonNull CategoricalStops, O> stops) { @@ -51,7 +52,7 @@ public class CompositeFunction extends Function, O> stops) { super(stops); - this.defaultValue = defaultValue; + this.defaultValue = new PropertyValue<>(property, defaultValue); this.property = property; } @@ -61,7 +62,7 @@ public class CompositeFunction extends Function withDefaultValue(O defaultValue) { + public CompositeFunction withDefaultValue(PropertyValue defaultValue) { this.defaultValue = defaultValue; return this; } @@ -70,7 +71,7 @@ public class CompositeFunction extends Function getDefaultValue() { return defaultValue; } @@ -91,7 +92,7 @@ public class CompositeFunction extends Function valueObject = super.toValueObject(); valueObject.put(PROPERTY_KEY, property); if (defaultValue != null) { - valueObject.put(DEFAULT_VALUE_KEY, defaultValue); + valueObject.put(DEFAULT_VALUE_KEY, defaultValue.value); } return valueObject; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java index f0eed760a4..33f436ae71 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java @@ -4,6 +4,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.mapbox.mapboxsdk.style.functions.stops.Stops; +import com.mapbox.mapboxsdk.style.layers.PropertyValue; import java.util.Map; @@ -25,7 +26,7 @@ import java.util.Map; public class SourceFunction extends Function { private final String property; - private O defaultValue; + private PropertyValue defaultValue; SourceFunction(@NonNull String property, @NonNull Stops stops) { this(null, property, stops); @@ -37,7 +38,7 @@ public class SourceFunction extends Function { private SourceFunction(@Nullable O defaultValue, @NonNull String property, @NonNull Stops stops) { super(stops); this.property = property; - this.defaultValue = defaultValue; + this.defaultValue = defaultValue != null ? new PropertyValue<>(property, defaultValue) : null; } @@ -56,7 +57,7 @@ public class SourceFunction extends Function { * @param defaultValue the default value to use when no other applies * @return this (for chaining) */ - public SourceFunction withDefaultValue(O defaultValue) { + public SourceFunction withDefaultValue(PropertyValue defaultValue) { this.defaultValue = defaultValue; return this; } @@ -65,7 +66,7 @@ public class SourceFunction extends Function { * @return the defaultValue */ @Nullable - public O getDefaultValue() { + public PropertyValue getDefaultValue() { return defaultValue; } @@ -77,7 +78,7 @@ public class SourceFunction extends Function { Map valueObject = super.toValueObject(); valueObject.put(PROPERTY_KEY, property); if (defaultValue != null) { - valueObject.put(DEFAULT_VALUE_KEY, defaultValue); + valueObject.put(DEFAULT_VALUE_KEY, defaultValue.value); } return valueObject; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java index 5286e6916d..68727c8a4f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java @@ -1,9 +1,12 @@ package com.mapbox.mapboxsdk.style.layers; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.exceptions.ConversionException; import com.mapbox.mapboxsdk.style.functions.Function; +import com.mapbox.mapboxsdk.utils.ColorUtils; import timber.log.Timber; @@ -15,7 +18,14 @@ public class PropertyValue { public final String name; public final T value; - /* package */ PropertyValue(@NonNull String name, T value) { + /** + * Not part of the public API. + * + * @param name the property name + * @param value the property value + * @see PropertyFactory for construction of {@link PropertyValue}s + */ + public PropertyValue(@NonNull String name, T value) { this.name = name; this.value = value; } @@ -54,6 +64,22 @@ public class PropertyValue { } } + @ColorInt + @Nullable + public Integer getColorInt() { + if (!isValue() || !(value instanceof String)) { + Timber.e("%s is not a String value and can not be converted to a color it", name); + return null; + } + + try { + return ColorUtils.rgbaToColor((String) value); + } catch (ConversionException ex) { + Timber.e("%s could not be converted to a Color int: %s", name, ex.getMessage()); + return null; + } + } + @Override public String toString() { return String.format("%s: %s", name, value); 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 c48a6f1d68..a8f35356b5 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 @@ -177,7 +177,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop(1.0f, circleRadius(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleRadius(0.3f)) ) ); @@ -187,7 +187,9 @@ public class CircleLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleRadius().getFunction()).getDefaultValue().getValue()); } @Test @@ -204,7 +206,7 @@ public class CircleLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, circleRadius(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleRadius(0.3f)) ) ); @@ -320,7 +322,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop("valueA", circleColor(Color.RED)) ) - ) + ).withDefaultValue(circleColor(Color.GREEN)) ) ); @@ -330,6 +332,9 @@ public class CircleLayerTest extends BaseStyleTest { 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 @@ -439,7 +444,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop(1.0f, circleBlur(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleBlur(0.3f)) ) ); @@ -449,7 +454,9 @@ public class CircleLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleBlur().getFunction()).getDefaultValue().getValue()); } @Test @@ -466,7 +473,7 @@ public class CircleLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, circleBlur(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleBlur(0.3f)) ) ); @@ -582,7 +589,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop(1.0f, circleOpacity(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleOpacity(0.3f)) ) ); @@ -592,7 +599,9 @@ public class CircleLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleOpacity().getFunction()).getDefaultValue().getValue()); } @Test @@ -609,7 +618,7 @@ public class CircleLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, circleOpacity(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleOpacity(0.3f)) ) ); @@ -834,7 +843,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop(1.0f, circleStrokeWidth(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleStrokeWidth(0.3f)) ) ); @@ -844,7 +853,9 @@ public class CircleLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getDefaultValue().getValue()); } @Test @@ -861,7 +872,7 @@ public class CircleLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, circleStrokeWidth(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleStrokeWidth(0.3f)) ) ); @@ -977,7 +988,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop("valueA", circleStrokeColor(Color.RED)) ) - ) + ).withDefaultValue(circleStrokeColor(Color.GREEN)) ) ); @@ -987,6 +998,9 @@ public class CircleLayerTest extends BaseStyleTest { 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 @@ -1096,7 +1110,7 @@ public class CircleLayerTest extends BaseStyleTest { categorical( stop(1.0f, circleStrokeOpacity(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleStrokeOpacity(0.3f)) ) ); @@ -1106,7 +1120,9 @@ public class CircleLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getDefaultValue().getValue()); } @Test @@ -1123,7 +1139,7 @@ public class CircleLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, circleStrokeOpacity(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(circleStrokeOpacity(0.3f)) ) ); 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 dd59b97525..a1d362f0f9 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 @@ -213,7 +213,7 @@ public class FillLayerTest extends BaseStyleTest { categorical( stop(1.0f, fillOpacity(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(fillOpacity(0.3f)) ) ); @@ -223,7 +223,9 @@ public class FillLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue().getValue()); } @Test @@ -240,7 +242,7 @@ public class FillLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, fillOpacity(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(fillOpacity(0.3f)) ) ); @@ -356,7 +358,7 @@ public class FillLayerTest extends BaseStyleTest { categorical( stop("valueA", fillColor(Color.RED)) ) - ) + ).withDefaultValue(fillColor(Color.GREEN)) ) ); @@ -366,6 +368,9 @@ public class FillLayerTest extends BaseStyleTest { 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 @@ -475,7 +480,7 @@ public class FillLayerTest extends BaseStyleTest { categorical( stop("valueA", fillOutlineColor(Color.RED)) ) - ) + ).withDefaultValue(fillOutlineColor(Color.GREEN)) ) ); @@ -485,6 +490,9 @@ public class FillLayerTest extends BaseStyleTest { 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 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 740393ad36..466873f9e5 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 @@ -323,7 +323,7 @@ public class LineLayerTest extends BaseStyleTest { categorical( stop(1.0f, lineOpacity(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineOpacity(0.3f)) ) ); @@ -333,7 +333,9 @@ public class LineLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getLineOpacity().getFunction()).getDefaultValue().getValue()); } @Test @@ -350,7 +352,7 @@ public class LineLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, lineOpacity(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineOpacity(0.3f)) ) ); @@ -466,7 +468,7 @@ public class LineLayerTest extends BaseStyleTest { categorical( stop("valueA", lineColor(Color.RED)) ) - ) + ).withDefaultValue(lineColor(Color.GREEN)) ) ); @@ -476,6 +478,9 @@ public class LineLayerTest extends BaseStyleTest { 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 @@ -695,7 +700,7 @@ public class LineLayerTest extends BaseStyleTest { categorical( stop(1.0f, lineGapWidth(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineGapWidth(0.3f)) ) ); @@ -705,7 +710,9 @@ public class LineLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getLineGapWidth().getFunction()).getDefaultValue().getValue()); } @Test @@ -722,7 +729,7 @@ public class LineLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, lineGapWidth(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineGapWidth(0.3f)) ) ); @@ -838,7 +845,7 @@ public class LineLayerTest extends BaseStyleTest { categorical( stop(1.0f, lineOffset(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineOffset(0.3f)) ) ); @@ -848,7 +855,9 @@ public class LineLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getLineOffset().getFunction()).getDefaultValue().getValue()); } @Test @@ -865,7 +874,7 @@ public class LineLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, lineOffset(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineOffset(0.3f)) ) ); @@ -981,7 +990,7 @@ public class LineLayerTest extends BaseStyleTest { categorical( stop(1.0f, lineBlur(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineBlur(0.3f)) ) ); @@ -991,7 +1000,9 @@ public class LineLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getLineBlur().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getLineBlur().getFunction()).getDefaultValue().getValue()); } @Test @@ -1008,7 +1019,7 @@ public class LineLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, lineBlur(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(lineBlur(0.3f)) ) ); 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 3b3bc9c8b5..c90af339b1 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 @@ -576,7 +576,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, iconRotate(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconRotate(0.3f)) ) ); @@ -586,7 +586,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getIconRotate().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getIconRotate().getFunction()).getDefaultValue().getValue()); } @Test @@ -603,7 +605,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, iconRotate(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconRotate(0.3f)) ) ); @@ -1656,7 +1658,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, iconOpacity(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconOpacity(0.3f)) ) ); @@ -1666,7 +1668,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getIconOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOpacity().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getIconOpacity().getFunction()).getDefaultValue().getValue()); } @Test @@ -1683,7 +1687,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, iconOpacity(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconOpacity(0.3f)) ) ); @@ -1799,7 +1803,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop("valueA", iconColor(Color.RED)) ) - ) + ).withDefaultValue(iconColor(Color.GREEN)) ) ); @@ -1809,6 +1813,9 @@ public class SymbolLayerTest extends BaseStyleTest { 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 @@ -1918,7 +1925,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop("valueA", iconHaloColor(Color.RED)) ) - ) + ).withDefaultValue(iconHaloColor(Color.GREEN)) ) ); @@ -1928,6 +1935,9 @@ public class SymbolLayerTest extends BaseStyleTest { 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 @@ -2037,7 +2047,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, iconHaloWidth(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconHaloWidth(0.3f)) ) ); @@ -2047,7 +2057,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getIconHaloWidth().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloWidth().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getIconHaloWidth().getFunction()).getDefaultValue().getValue()); } @Test @@ -2064,7 +2076,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, iconHaloWidth(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconHaloWidth(0.3f)) ) ); @@ -2180,7 +2192,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, iconHaloBlur(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconHaloBlur(0.3f)) ) ); @@ -2190,7 +2202,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getIconHaloBlur().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconHaloBlur().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getIconHaloBlur().getFunction()).getDefaultValue().getValue()); } @Test @@ -2207,7 +2221,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, iconHaloBlur(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(iconHaloBlur(0.3f)) ) ); @@ -2396,7 +2410,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, textOpacity(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(textOpacity(0.3f)) ) ); @@ -2406,7 +2420,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getTextOpacity().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOpacity().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getTextOpacity().getFunction()).getDefaultValue().getValue()); } @Test @@ -2423,7 +2439,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, textOpacity(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(textOpacity(0.3f)) ) ); @@ -2539,7 +2555,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop("valueA", textColor(Color.RED)) ) - ) + ).withDefaultValue(textColor(Color.GREEN)) ) ); @@ -2549,6 +2565,9 @@ public class SymbolLayerTest extends BaseStyleTest { 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 @@ -2658,7 +2677,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop("valueA", textHaloColor(Color.RED)) ) - ) + ).withDefaultValue(textHaloColor(Color.GREEN)) ) ); @@ -2668,6 +2687,9 @@ public class SymbolLayerTest extends BaseStyleTest { 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 @@ -2777,7 +2799,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, textHaloWidth(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(textHaloWidth(0.3f)) ) ); @@ -2787,7 +2809,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getTextHaloWidth().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloWidth().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getTextHaloWidth().getFunction()).getDefaultValue().getValue()); } @Test @@ -2804,7 +2828,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, textHaloWidth(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(textHaloWidth(0.3f)) ) ); @@ -2920,7 +2944,7 @@ public class SymbolLayerTest extends BaseStyleTest { categorical( stop(1.0f, textHaloBlur(0.3f)) ) - ).withDefaultValue(0.3f) + ).withDefaultValue(textHaloBlur(0.3f)) ) ); @@ -2930,7 +2954,9 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(SourceFunction.class, layer.getTextHaloBlur().getFunction().getClass()); assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextHaloBlur().getFunction()).getProperty()); assertEquals(CategoricalStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); - assertEquals(0.3f, ((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getTextHaloBlur().getFunction()).getDefaultValue().getValue()); } @Test @@ -2947,7 +2973,7 @@ public class SymbolLayerTest extends BaseStyleTest { exponential( stop(0, 0.3f, textHaloBlur(0.9f)) ).withBase(0.5f) - ).withDefaultValue(0.3f) + ).withDefaultValue(textHaloBlur(0.3f)) ) ); 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 f1d68caa24..3dc88d29bb 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 @@ -269,11 +269,11 @@ public class <%- camelize(type) %>LayerTest extends BaseStyleTest { <% 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(<%- defaultValueJava(property) %>) + ).withDefaultValue(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) <% } -%> ) ); @@ -284,8 +284,12 @@ public class <%- camelize(type) %>LayerTest extends BaseStyleTest { 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()); + 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') { -%> @@ -305,7 +309,7 @@ public class <%- camelize(type) %>LayerTest extends BaseStyleTest { stop(0, 0.3f, <%- camelizeWithLeadingLowercase(property.name) %>(0.9f)) ).withBase(0.5f) <% if (property.type == 'number') { -%> - ).withDefaultValue(<%- defaultValueJava(property) %>) + ).withDefaultValue(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) <% } else { -%> ) <% } -%> -- cgit v1.2.1