summaryrefslogtreecommitdiffstats
path: root/json/src/test/java/org/json/JSONObjectTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'json/src/test/java/org/json/JSONObjectTest.java')
-rw-r--r--json/src/test/java/org/json/JSONObjectTest.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/json/src/test/java/org/json/JSONObjectTest.java b/json/src/test/java/org/json/JSONObjectTest.java
index 8abd88f..e89db94 100644
--- a/json/src/test/java/org/json/JSONObjectTest.java
+++ b/json/src/test/java/org/json/JSONObjectTest.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.TreeMap;
import junit.framework.TestCase;
/**
@@ -988,9 +989,44 @@ public class JSONObjectTest extends TestCase {
ArrayList<Object> list = new ArrayList<Object>();
list.add("a");
list.add(new ArrayList<String>());
- HashMap<String, Object> map = new HashMap<String, Object>();
+ Map<String, Object> map = new TreeMap<String, Object>();
map.put("x", "l");
map.put("y", list);
- assertEquals("{\"y\":[\"a\",[]],\"x\":\"l\"}", new JSONObject(map).toString());
+ assertEquals("{\"x\":\"l\",\"y\":[\"a\",[]]}", new JSONObject(map).toString());
+ }
+
+ public void testAppendExistingInvalidKey() throws JSONException {
+ JSONObject object = new JSONObject();
+ object.put("foo", 5);
+ try {
+ object.append("foo", 6);
+ fail();
+ } catch (JSONException expected) {
+ }
+ }
+
+ public void testAppendExistingArray() throws JSONException {
+ JSONArray array = new JSONArray();
+ JSONObject object = new JSONObject();
+ object.put("foo", array);
+ object.append("foo", 5);
+ assertEquals("[5]", array.toString());
+ }
+
+ public void testAppendPutArray() throws JSONException {
+ JSONObject object = new JSONObject();
+ object.append("foo", 5);
+ assertEquals("{\"foo\":[5]}", object.toString());
+ object.append("foo", new JSONArray());
+ assertEquals("{\"foo\":[5,[]]}", object.toString());
+ }
+
+ public void testAppendNull() {
+ JSONObject object = new JSONObject();
+ try {
+ object.append(null, 5);
+ fail();
+ } catch (JSONException e) {
+ }
}
}