Adding unit-tests to verify bugs.
This commit is contained in:
parent
e345feb438
commit
d2cf574e86
@ -198,7 +198,7 @@ public class ArrayTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testArrayOfPrimitivesAsObjectsSerialization() throws Exception {
|
||||
Object[] objs = new Object[]{1, "abc", 0.3f, 5L};
|
||||
Object[] objs = new Object[] {1, "abc", 0.3f, 5L};
|
||||
String json = gson.toJson(objs);
|
||||
assertTrue(json.contains("abc"));
|
||||
assertTrue(json.contains("0.3"));
|
||||
@ -269,6 +269,11 @@ public class ArrayTest extends TestCase {
|
||||
assertTrue(json.contains("Manufacturing\"]]"));
|
||||
}
|
||||
|
||||
public void testMultiDimenstionalObjectArraysSerialization() {
|
||||
Object[][] array = new Object[][] { new Object[] { 1, 2 } };
|
||||
assertEquals("[[1,2]]", gson.toJson(array));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression tests for Issue 272
|
||||
*/
|
||||
|
@ -341,18 +341,23 @@ public class MapTest extends TestCase {
|
||||
*/
|
||||
public void testSerializeMaps() {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
HashMap<String, Object> innerMap = new HashMap<String, Object>();
|
||||
map.put("a", 12);
|
||||
map.put("b", null);
|
||||
map.put("c", new HashMap<String, Object>());
|
||||
map.put("c", innerMap);
|
||||
|
||||
assertEquals("{\"a\":12,\"b\":null,\"c\":{}}",
|
||||
new GsonBuilder().serializeNulls().create().toJson(map));
|
||||
assertEquals("{\"a\":12,\"b\":null,\"c\":{}}",
|
||||
new GsonBuilder().serializeNulls().create().toJson(map));
|
||||
assertEquals("{\"a\":12,\"c\":{}}",
|
||||
new GsonBuilder().create().toJson(map));
|
||||
assertEquals("{\n \"a\": 12,\n \"b\": null,\n \"c\": {}\n}",
|
||||
new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(map));
|
||||
assertEquals("{\"a\":12,\"c\":{}}",
|
||||
new GsonBuilder().create().toJson(map));
|
||||
assertEquals("{\n \"a\": 12,\n \"c\": {}\n}",
|
||||
new GsonBuilder().setPrettyPrinting().create().toJson(map));
|
||||
|
||||
innerMap.put("d", "e");
|
||||
assertEquals("{\"a\":12,\"c\":{\"d\":\"e\"}}",
|
||||
new Gson().toJson(map));
|
||||
}
|
||||
|
||||
public final void testInterfaceTypeMap() {
|
||||
|
Loading…
Reference in New Issue
Block a user