From 69661216a3687fdf360af30fe7a24bba7310c100 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Fri, 11 Feb 2011 18:22:58 +0000 Subject: [PATCH] Minor clean-up of warnings (in 1.5) and added new test for non-Empty maps. --- .../google/gson/DefaultMapJsonSerializerTest.java | 13 +++++++++++++ .../com/google/gson/functional/CollectionTest.java | 4 ++-- .../functional/ExclusionStrategyFunctionalTest.java | 1 - 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gson/src/test/java/com/google/gson/DefaultMapJsonSerializerTest.java b/gson/src/test/java/com/google/gson/DefaultMapJsonSerializerTest.java index 91461588..fcd627c4 100644 --- a/gson/src/test/java/com/google/gson/DefaultMapJsonSerializerTest.java +++ b/gson/src/test/java/com/google/gson/DefaultMapJsonSerializerTest.java @@ -58,4 +58,17 @@ public class DefaultMapJsonSerializerTest extends TestCase { JsonObject emptyMapJsonObject = (JsonObject) element; assertTrue(emptyMapJsonObject.entrySet().isEmpty()); } + + public void testNonEmptyMapSerialization() { + Type mapType = new TypeToken>() { }.getType(); + Map myMap = new HashMap(); + String key = "key1"; + myMap.put(key, "value1"); + Gson gson = new Gson(); + JsonElement element = gson.toJsonTree(myMap, mapType); + + assertTrue(element.isJsonObject()); + JsonObject mapJsonObject = element.getAsJsonObject(); + assertTrue(mapJsonObject.has(key)); + } } diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index 46ffe4be..1192c7ec 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -201,7 +201,7 @@ public class CollectionTest extends TestCase { assertEquals("[1,2,3,4,5,6,7,8,9]", gson.toJson(target)); } - @SuppressWarnings({ "rawtypes" }) + @SuppressWarnings("unchecked") public void testRawCollectionSerialization() { BagOfPrimitives bag1 = new BagOfPrimitives(); Collection target = Arrays.asList(bag1, bag1); @@ -276,7 +276,7 @@ public class CollectionTest extends TestCase { assertTrue(deserializedCollection.contains(objB)); } - @SuppressWarnings({ "rawtypes" }) + @SuppressWarnings("unchecked") private static int[] toIntArray(Collection collection) { int[] ints = new int[collection.size()]; int i = 0; diff --git a/gson/src/test/java/com/google/gson/functional/ExclusionStrategyFunctionalTest.java b/gson/src/test/java/com/google/gson/functional/ExclusionStrategyFunctionalTest.java index 77b8c118..3115cc71 100644 --- a/gson/src/test/java/com/google/gson/functional/ExclusionStrategyFunctionalTest.java +++ b/gson/src/test/java/com/google/gson/functional/ExclusionStrategyFunctionalTest.java @@ -107,7 +107,6 @@ public class ExclusionStrategyFunctionalTest extends TestCase { // Field tag only annotation } - @SuppressWarnings("unused") private static class SampleObjectForTest { @Foo private final int annotatedField;