From f4f92a699df149a22376b68e756838e76aa9a0a5 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Sat, 17 Jan 2009 22:32:59 +0000 Subject: [PATCH] Added test for pretty printing of Maps. --- .../gson/functional/PrettyPrintingTest.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/PrettyPrintingTest.java b/gson/src/test/java/com/google/gson/functional/PrettyPrintingTest.java index 3ab79f8d..cfdc5fef 100644 --- a/gson/src/test/java/com/google/gson/functional/PrettyPrintingTest.java +++ b/gson/src/test/java/com/google/gson/functional/PrettyPrintingTest.java @@ -15,19 +15,21 @@ */ package com.google.gson.functional; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.common.TestTypes.ArrayOfObjects; import com.google.gson.common.TestTypes.BagOfPrimitives; import com.google.gson.reflect.TypeToken; -import junit.framework.TestCase; - -import java.lang.reflect.Type; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - /** * Functional tests for pretty printing option. * @@ -38,7 +40,7 @@ public class PrettyPrintingTest extends TestCase { private static int PRINT_MARGIN = 80; private static int RIGHT_MARGIN = 4; - private static boolean DEBUG = false; + private static boolean DEBUG = true; private Gson gson; @@ -86,6 +88,14 @@ public class PrettyPrintingTest extends TestCase { String json = gson.toJson(list); assertEquals("[[1,2],[3,4],[5,6],[7,8],[9,0],[10]]\n", json); } + + public void testMap() { + Map map = new LinkedHashMap(); + map.put("abc", 1); + map.put("def", 5); + String json = gson.toJson(map); + assertEquals("{\"abc\":1,\"def\":5}\n", json); + } public void testMultipleArrays() { int[][][] ints = new int[][][] { { { 1 }, { 2 } } };