This commit is contained in:
jon.chambers@gmail.com
2013-08-10 04:03:08 +00:00
parent 9012fdfd93
commit d4af019078

View File

@@ -230,4 +230,27 @@ public class JSONValueTest extends TestCase {
JSONValue.writeJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3} }, writer); JSONValue.writeJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3} }, writer);
assertEquals("[\"Hello\",12,[1,2,3]]", writer.toString()); assertEquals("[\"Hello\",12,[1,2,3]]", writer.toString());
} }
public void testArraysOfArrays() throws IOException {
StringWriter writer;
final int[][][] nestedIntArray = new int[][][]{{{1}, {5}}, {{2}, {6}}};
final String expectedNestedIntString = "[[[1],[5]],[[2],[6]]]";
assertEquals(expectedNestedIntString, JSONValue.toJSONString(nestedIntArray));
writer = new StringWriter();
JSONValue.writeJSONString(nestedIntArray, writer);
assertEquals(expectedNestedIntString, writer.toString());
final String[][] nestedStringArray = new String[][]{{"a", "b"}, {"c", "d"}};
final String expectedNestedStringString = "[[\"a\",\"b\"],[\"c\",\"d\"]]";
assertEquals(expectedNestedStringString, JSONValue.toJSONString(nestedStringArray));
writer = new StringWriter();
JSONValue.writeJSONString(nestedStringArray, writer);
assertEquals(expectedNestedStringString, writer.toString());
}
} }