[android] - provide correct expression integration for newly created property values

This commit is contained in:
Tobrun
2018-08-29 18:28:51 +02:00
committed by Tobrun
parent 3f021970ea
commit e4bcd1abed
2 changed files with 18 additions and 2 deletions

View File

@@ -46,7 +46,7 @@ public class PropertyValue<T> {
* @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,9 @@ public class PropertyValue<T> {
@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;

View File

@@ -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};