diff options
Diffstat (limited to 'gson/src/test/java/com/google/gson/functional/UncategorizedTest.java')
-rw-r--r-- | gson/src/test/java/com/google/gson/functional/UncategorizedTest.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/gson/src/test/java/com/google/gson/functional/UncategorizedTest.java b/gson/src/test/java/com/google/gson/functional/UncategorizedTest.java index 0ac03803..58171de0 100644 --- a/gson/src/test/java/com/google/gson/functional/UncategorizedTest.java +++ b/gson/src/test/java/com/google/gson/functional/UncategorizedTest.java @@ -15,6 +15,11 @@ */ package com.google.gson.functional; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -23,13 +28,12 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.common.TestTypes.BagOfPrimitives; import com.google.gson.common.TestTypes.ClassOverridingEquals; - import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; - -import java.lang.reflect.Type; +import org.junit.Before; +import org.junit.Test; /** * Functional tests that do not fall neatly into any of the existing classification. @@ -37,16 +41,16 @@ import java.lang.reflect.Type; * @author Inderjeet Singh * @author Joel Leitch */ -public class UncategorizedTest extends TestCase { +public class UncategorizedTest { private Gson gson = null; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { gson = new Gson(); } + @Test public void testInvalidJsonDeserializationFails() throws Exception { try { gson.fromJson("adfasdf1112,,,\":", BagOfPrimitives.class); @@ -59,6 +63,7 @@ public class UncategorizedTest extends TestCase { } catch (JsonParseException expected) { } } + @Test public void testObjectEqualButNotSameSerialization() throws Exception { ClassOverridingEquals objA = new ClassOverridingEquals(); ClassOverridingEquals objB = new ClassOverridingEquals(); @@ -67,11 +72,13 @@ public class UncategorizedTest extends TestCase { assertEquals(objB.getExpectedJson(), json); } + @Test public void testStaticFieldsAreNotSerialized() { BagOfPrimitives target = new BagOfPrimitives(); assertFalse(gson.toJson(target).contains("DEFAULT_VALUE")); } + @Test public void testGsonInstanceReusableForSerializationAndDeserialization() { BagOfPrimitives bag = new BagOfPrimitives(); String json = gson.toJson(bag); @@ -84,6 +91,7 @@ public class UncategorizedTest extends TestCase { * base class object. For a motivation for this test, see Issue 37 and * http://groups.google.com/group/google-gson/browse_thread/thread/677d56e9976d7761 */ + @Test public void testReturningDerivedClassesDuringDeserialization() { Gson gson = new GsonBuilder().registerTypeAdapter(Base.class, new BaseTypeAdapter()).create(); String json = "{\"opType\":\"OP1\"}"; @@ -101,6 +109,7 @@ public class UncategorizedTest extends TestCase { * Test that trailing whitespace is ignored. * http://code.google.com/p/google-gson/issues/detail?id=302 */ + @Test public void testTrailingWhitespace() throws Exception { List<Integer> integers = gson.fromJson("[1,2,3] \n\n ", new TypeToken<List<Integer>>() {}.getType()); |