From ed8a12e4ef592e1d7f1ea5e5053cdb2d254b1241 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 29 Aug 2018 18:28:51 +0200 Subject: [android] - provide correct expression integration for newly created property values --- .../com/mapbox/mapboxsdk/style/layers/PropertyValue.java | 5 +++-- .../mapbox/mapboxsdk/style/expressions/ExpressionTest.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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 a38f810f1c..7a5e69f609 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 @@ -46,7 +46,7 @@ public class PropertyValue { * @return true if this is a expression, false if not */ public boolean isExpression() { - return !isNull() && value instanceof JsonArray; + return !isNull() && (value instanceof JsonArray || value instanceof Expression); } /** @@ -57,7 +57,8 @@ public class PropertyValue { @Nullable public Expression getExpression() { if (isExpression()) { - return Expression.Converter.convert((JsonArray) value); + return value instanceof JsonArray ? + Expression.Converter.convert((JsonArray) value) : (Expression) value; } else { Logger.w(TAG, "not a expression, try value"); return null; diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java index 79bcdd7b5e..5ab1542b8b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -4,6 +4,7 @@ import android.graphics.Color; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.style.layers.PropertyValue; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -87,6 +88,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase; import static com.mapbox.mapboxsdk.style.expressions.Expression.var; import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; @@ -96,6 +98,18 @@ import static org.junit.Assert.assertEquals; @RunWith(RobolectricTestRunner.class) public class ExpressionTest { + @Test + public void testPropertyValueIsExpression() { + PropertyValue property = lineWidth(Expression.get("width")); + assertTrue(property.isExpression()); + } + + @Test + public void testPropertyValueEqualsExpression() { + PropertyValue property = lineWidth(Expression.get("width")); + assertEquals(Expression.get("width"), property.getExpression()); + } + @Test public void testRgb() throws Exception { Object[] expected = new Object[] {"rgb", 0f, 0f, 0f}; -- cgit v1.2.1