Add support for all container types to JsonFieldDecoderTester
@@ -21,6 +21,7 @@ import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.type.Type;
import com.google.common.collect.ImmutableSet;
import io.airlift.json.ObjectMapperProvider;
+import io.airlift.slice.Slice;
import java.util.Map;
import java.util.Optional;
@@ -71,6 +72,30 @@ public class JsonFieldDecoderTester
assertEquals(decodedValue.getLong(), expectedValue);
}
+ public void assertDecodedAs(String jsonValue, Type type, double expectedValue)
+ {
+ checkArgument(type.getJavaType() == double.class, "Wrong (not double based) presto type '%s'", type);
+ FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type);
+ assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type));
+ assertEquals(decodedValue.getDouble(), expectedValue);
+ }
+
+ public void assertDecodedAs(String jsonValue, Type type, Slice expectedValue)
+ {
+ checkArgument(type.getJavaType() == Slice.class, "Wrong (not Slice based) presto type '%s'", type);
+ FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type);
+ assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type));
+ assertEquals(decodedValue.getSlice(), expectedValue);
+ }
+
+ public void assertDecodedAs(String jsonValue, Type type, boolean expectedValue)
+ {
+ checkArgument(type.getJavaType() == boolean.class, "Wrong (not boolean based) presto type '%s'", type);
+ FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type);
+ assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type));
+ assertEquals(decodedValue.getBoolean(), expectedValue);
+ }
+
public void assertDecodedAsNull(String jsonValue, Type type)
{
FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type);
