diff options
Diffstat (limited to 'gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java')
-rw-r--r-- | gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java b/gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java index a179fa8e..1b6ed887 100644 --- a/gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java +++ b/gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java @@ -16,15 +16,19 @@ package com.google.gson.functional; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import com.google.gson.Gson; import com.google.gson.JsonObject; - -import junit.framework.TestCase; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.junit.Before; +import org.junit.Test; /** * Tests for Gson serialization of a sub-class object while encountering a base-class type @@ -32,15 +36,15 @@ import java.util.Map; * @author Inderjeet Singh */ @SuppressWarnings("unused") -public class MoreSpecificTypeSerializationTest extends TestCase { +public class MoreSpecificTypeSerializationTest { private Gson gson; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { gson = new Gson(); } + @Test public void testSubclassFields() { ClassWithBaseFields target = new ClassWithBaseFields(new Sub(1, 2)); String json = gson.toJson(target); @@ -48,6 +52,7 @@ public class MoreSpecificTypeSerializationTest extends TestCase { assertTrue(json.contains("\"s\":2")); } + @Test public void testListOfSubclassFields() { Collection<Base> list = new ArrayList<>(); list.add(new Base(1)); @@ -58,6 +63,7 @@ public class MoreSpecificTypeSerializationTest extends TestCase { assertTrue(json, json.contains("{\"s\":3,\"b\":2}")); } + @Test public void testMapOfSubclassFields() { Map<String, Base> map = new HashMap<>(); map.put("base", new Base(1)); @@ -73,6 +79,7 @@ public class MoreSpecificTypeSerializationTest extends TestCase { /** * For parameterized type, Gson ignores the more-specific type and sticks to the declared type */ + @Test public void testParameterizedSubclassFields() { ClassWithParameterizedBaseFields target = new ClassWithParameterizedBaseFields( new ParameterizedSub<>("one", "two")); @@ -85,6 +92,7 @@ public class MoreSpecificTypeSerializationTest extends TestCase { * For parameterized type in a List, Gson ignores the more-specific type and sticks to * the declared type */ + @Test public void testListOfParameterizedSubclassFields() { Collection<ParameterizedBase<String>> list = new ArrayList<>(); list.add(new ParameterizedBase<>("one")); @@ -100,6 +108,7 @@ public class MoreSpecificTypeSerializationTest extends TestCase { * For parameterized type in a map, Gson ignores the more-specific type and sticks to the * declared type */ + @Test public void testMapOfParameterizedSubclassFields() { Map<String, ParameterizedBase<String>> map = new HashMap<>(); map.put("base", new ParameterizedBase<>("one")); |