From cc5cbe5a1fd8ae6149ecacda472062b4067dd71b Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 20 Oct 2011 04:57:58 +0000 Subject: [PATCH] Integration test for long serialization policy. --- .../gson/LongSerializationPolicyTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gson/src/test/java/com/google/gson/LongSerializationPolicyTest.java b/gson/src/test/java/com/google/gson/LongSerializationPolicyTest.java index 111a1719..d0a06320 100644 --- a/gson/src/test/java/com/google/gson/LongSerializationPolicyTest.java +++ b/gson/src/test/java/com/google/gson/LongSerializationPolicyTest.java @@ -36,13 +36,29 @@ public class LongSerializationPolicyTest extends TestCase { assertEquals(1556L, element.getAsLong()); } + public void testDefaultLongSerializationIntegration() { + Gson gson = new GsonBuilder() + .setLongSerializationPolicy(LongSerializationPolicy.DEFAULT) + .create(); + assertEquals("[1]", gson.toJson(new long[] { 1L }, long[].class)); + assertEquals("[1]", gson.toJson(new Long[] { 1L }, Long[].class)); + } + public void testStringLongSerialization() throws Exception { JsonElement element = LongSerializationPolicy.STRING.serialize(1556L); assertTrue(element.isJsonPrimitive()); - + JsonPrimitive jsonPrimitive = element.getAsJsonPrimitive(); assertFalse(jsonPrimitive.isNumber()); assertTrue(jsonPrimitive.isString()); assertEquals("1556", element.getAsString()); } + + public void testStringLongSerializationIntegration() { + Gson gson = new GsonBuilder() + .setLongSerializationPolicy(LongSerializationPolicy.STRING) + .create(); + assertEquals("[\"1\"]", gson.toJson(new long[] { 1L }, long[].class)); + assertEquals("[\"1\"]", gson.toJson(new Long[] { 1L }, Long[].class)); + } }