|  | 
| 11 | 11 | 
 | 
| 12 | 12 | 
 | 
| 13 | 13 | /** | 
| 14 |  | - * Tests for JSON-Java JSONStringer.  | 
| 15 |  | - * TODO: Could use a lot more testing. For example, cascade-style productions. | 
|  | 14 | + * Tests for JSON-Java JSONStringer and JSONWriter. | 
| 16 | 15 |  */ | 
| 17 | 16 | public class JSONStringerTest { | 
| 18 | 17 | 
 | 
| @@ -234,43 +233,44 @@ public void simpleArrayString() { | 
| 234 | 233 |     } | 
| 235 | 234 | 
 | 
| 236 | 235 |     /** | 
| 237 |  | -     * Build a nested JSON doc using JSONString API calls, | 
| 238 |  | -     * then convert to JSONObject | 
|  | 236 | +     * Build a nested JSON doc using JSONString API calls, then convert to | 
|  | 237 | +     * JSONObject. Will create a long cascade of output by reusing the | 
|  | 238 | +     * returned values.. | 
| 239 | 239 |      */ | 
| 240 | 240 |     @Test | 
| 241 | 241 |     public void complexObjectString() { | 
| 242 | 242 |         JSONStringer jsonStringer = new JSONStringer(); | 
| 243 |  | -        jsonStringer.object(); | 
| 244 |  | -        jsonStringer.key("trueValue").value(true); | 
| 245 |  | -        jsonStringer.key("falseValue").value(false); | 
| 246 |  | -        jsonStringer.key("nullValue").value(null); | 
| 247 |  | -        jsonStringer.key("stringValue").value("hello world!"); | 
| 248 |  | -        jsonStringer.key("object2").object(); | 
| 249 |  | -        jsonStringer.key("k1").value("v1"); | 
| 250 |  | -        jsonStringer.key("k2").value("v2"); | 
| 251 |  | -        jsonStringer.key("k3").value("v3"); | 
| 252 |  | -        jsonStringer.key("array1").array(); | 
| 253 |  | -        jsonStringer.value(1); | 
| 254 |  | -        jsonStringer.value(2); | 
| 255 |  | -        jsonStringer.object(); | 
| 256 |  | -        jsonStringer.key("k4").value("v4"); | 
| 257 |  | -        jsonStringer.key("k5").value("v5"); | 
| 258 |  | -        jsonStringer.key("k6").value("v6"); | 
| 259 |  | -        jsonStringer.key("array2").array(); | 
| 260 |  | -        jsonStringer.value(5); | 
| 261 |  | -        jsonStringer.value(6); | 
| 262 |  | -        jsonStringer.value(7); | 
| 263 |  | -        jsonStringer.value(8); | 
| 264 |  | -        jsonStringer.endArray(); | 
| 265 |  | -        jsonStringer.endObject(); | 
| 266 |  | -        jsonStringer.value(3); | 
| 267 |  | -        jsonStringer.value(4); | 
| 268 |  | -        jsonStringer.endArray(); | 
| 269 |  | -        jsonStringer.endObject(); | 
| 270 |  | -        jsonStringer.key("complexStringValue").value("h\be\tllo w\u1234orld!"); | 
| 271 |  | -        jsonStringer.key("intValue").value(42); | 
| 272 |  | -        jsonStringer.key("doubleValue").value(-23.45e67); | 
| 273 |  | -        jsonStringer.endObject(); | 
|  | 243 | +        jsonStringer.object(). | 
|  | 244 | +            key("trueValue").value(true). | 
|  | 245 | +            key("falseValue").value(false). | 
|  | 246 | +            key("nullValue").value(null). | 
|  | 247 | +            key("stringValue").value("hello world!"). | 
|  | 248 | +            key("object2").object(). | 
|  | 249 | +            key("k1").value("v1"). | 
|  | 250 | +            key("k2").value("v2"). | 
|  | 251 | +            key("k3").value("v3"). | 
|  | 252 | +            key("array1").array(). | 
|  | 253 | +            value(1). | 
|  | 254 | +            value(2). | 
|  | 255 | +            object(). | 
|  | 256 | +            key("k4").value("v4"). | 
|  | 257 | +            key("k5").value("v5"). | 
|  | 258 | +            key("k6").value("v6"). | 
|  | 259 | +            key("array2").array(). | 
|  | 260 | +            value(5). | 
|  | 261 | +            value(6). | 
|  | 262 | +            value(7). | 
|  | 263 | +            value(8). | 
|  | 264 | +            endArray(). | 
|  | 265 | +            endObject(). | 
|  | 266 | +            value(3). | 
|  | 267 | +            value(4). | 
|  | 268 | +            endArray(). | 
|  | 269 | +            endObject(). | 
|  | 270 | +            key("complexStringValue").value("h\be\tllo w\u1234orld!"). | 
|  | 271 | +            key("intValue").value(42). | 
|  | 272 | +            key("doubleValue").value(-23.45e67). | 
|  | 273 | +            endObject(); | 
| 274 | 274 |         String str = jsonStringer.toString(); | 
| 275 | 275 |         JSONObject jsonObject = new JSONObject(str); | 
| 276 | 276 | 
 | 
|  | 
0 commit comments