From d2cf574e8633bee099fd388242dcab9478ff5db7 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Fri, 15 Apr 2011 06:33:09 +0000 Subject: [PATCH] Adding unit-tests to verify bugs. --- .../com/google/gson/functional/ArrayTest.java | 7 ++++++- .../java/com/google/gson/functional/MapTest.java | 15 ++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/ArrayTest.java b/gson/src/test/java/com/google/gson/functional/ArrayTest.java index b10daf87..ab4f5878 100644 --- a/gson/src/test/java/com/google/gson/functional/ArrayTest.java +++ b/gson/src/test/java/com/google/gson/functional/ArrayTest.java @@ -198,7 +198,7 @@ public class ArrayTest extends TestCase { } public void testArrayOfPrimitivesAsObjectsSerialization() throws Exception { - Object[] objs = new Object[]{1, "abc", 0.3f, 5L}; + Object[] objs = new Object[] {1, "abc", 0.3f, 5L}; String json = gson.toJson(objs); assertTrue(json.contains("abc")); assertTrue(json.contains("0.3")); @@ -269,6 +269,11 @@ public class ArrayTest extends TestCase { assertTrue(json.contains("Manufacturing\"]]")); } + public void testMultiDimenstionalObjectArraysSerialization() { + Object[][] array = new Object[][] { new Object[] { 1, 2 } }; + assertEquals("[[1,2]]", gson.toJson(array)); + } + /** * Regression tests for Issue 272 */ diff --git a/gson/src/test/java/com/google/gson/functional/MapTest.java b/gson/src/test/java/com/google/gson/functional/MapTest.java index 16bd779e..1f3858c1 100755 --- a/gson/src/test/java/com/google/gson/functional/MapTest.java +++ b/gson/src/test/java/com/google/gson/functional/MapTest.java @@ -341,18 +341,23 @@ public class MapTest extends TestCase { */ public void testSerializeMaps() { Map map = new LinkedHashMap(); + HashMap innerMap = new HashMap(); map.put("a", 12); map.put("b", null); - map.put("c", new HashMap()); + map.put("c", innerMap); assertEquals("{\"a\":12,\"b\":null,\"c\":{}}", new GsonBuilder().serializeNulls().create().toJson(map)); - assertEquals("{\"a\":12,\"b\":null,\"c\":{}}", - new GsonBuilder().serializeNulls().create().toJson(map)); - assertEquals("{\"a\":12,\"c\":{}}", - new GsonBuilder().create().toJson(map)); + assertEquals("{\n \"a\": 12,\n \"b\": null,\n \"c\": {}\n}", + new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(map)); assertEquals("{\"a\":12,\"c\":{}}", new GsonBuilder().create().toJson(map)); + assertEquals("{\n \"a\": 12,\n \"c\": {}\n}", + new GsonBuilder().setPrettyPrinting().create().toJson(map)); + + innerMap.put("d", "e"); + assertEquals("{\"a\":12,\"c\":{\"d\":\"e\"}}", + new Gson().toJson(map)); } public final void testInterfaceTypeMap() {