diff options
Diffstat (limited to 'gson/src/test/java/com/google/gson/functional/SecurityTest.java')
-rw-r--r-- | gson/src/test/java/com/google/gson/functional/SecurityTest.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/gson/src/test/java/com/google/gson/functional/SecurityTest.java b/gson/src/test/java/com/google/gson/functional/SecurityTest.java index aa1c2d45..9e9272e1 100644 --- a/gson/src/test/java/com/google/gson/functional/SecurityTest.java +++ b/gson/src/test/java/com/google/gson/functional/SecurityTest.java @@ -16,18 +16,21 @@ package com.google.gson.functional; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.common.TestTypes.BagOfPrimitives; - -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; /** * Tests for security-related aspects of Gson * * @author Inderjeet Singh */ -public class SecurityTest extends TestCase { +public class SecurityTest { /** * Keep this in sync with Gson.JSON_NON_EXECUTABLE_PREFIX */ @@ -35,18 +38,19 @@ public class SecurityTest extends TestCase { private GsonBuilder gsonBuilder; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { gsonBuilder = new GsonBuilder(); } + @Test public void testNonExecutableJsonSerialization() { Gson gson = gsonBuilder.generateNonExecutableJson().create(); String json = gson.toJson(new BagOfPrimitives()); assertTrue(json.startsWith(JSON_NON_EXECUTABLE_PREFIX)); } + @Test public void testNonExecutableJsonDeserialization() { String json = JSON_NON_EXECUTABLE_PREFIX + "{longValue:1}"; Gson gson = gsonBuilder.create(); @@ -54,6 +58,7 @@ public class SecurityTest extends TestCase { assertEquals(1, target.longValue); } + @Test public void testJsonWithNonExectuableTokenSerialization() { Gson gson = gsonBuilder.generateNonExecutableJson().create(); String json = gson.toJson(JSON_NON_EXECUTABLE_PREFIX); @@ -64,6 +69,7 @@ public class SecurityTest extends TestCase { * Gson should be able to deserialize a stream with non-exectuable token even if it is created * without {@link GsonBuilder#generateNonExecutableJson()}. */ + @Test public void testJsonWithNonExectuableTokenWithRegularGsonDeserialization() { Gson gson = gsonBuilder.create(); String json = JSON_NON_EXECUTABLE_PREFIX + "{stringValue:')]}\\u0027\\n'}"; @@ -75,6 +81,7 @@ public class SecurityTest extends TestCase { * Gson should be able to deserialize a stream with non-exectuable token if it is created * with {@link GsonBuilder#generateNonExecutableJson()}. */ + @Test public void testJsonWithNonExectuableTokenWithConfiguredGsonDeserialization() { // Gson should be able to deserialize a stream with non-exectuable token even if it is created Gson gson = gsonBuilder.generateNonExecutableJson().create(); |