1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-18 00:10:51 -07:00

Tests for deep copy and mutability of toList() and toMap().

Both toMap() and toList() return deep copies, which are also mutable. That is, any changes to the JSONObject or JSONArray do not affect the newly create Map or List, and vice-versa. The resulting objects can be altered.
This commit is contained in:
Nicholas Cull 2016-07-23 22:51:50 +10:00
parent 72c2b911bf
commit ae77b5cd83
2 changed files with 17 additions and 0 deletions

View file

@ -920,5 +920,13 @@ public class JSONArrayTest {
assertTrue("val3 list val 2 should not be null", val3Val2List != null);
assertTrue("val3 list val 2 should have 1 element", val3Val2List.size() == 1);
assertTrue("val3 list val 2 list element 1 should be null", val3Val2List.get(0) == null);
// assert that toList() is a deep copy
jsonArray.getJSONObject(1).put("key1", "still val1");
assertTrue("val2 map key 1 should be val1", val2Map.get("key1").equals("val1"));
// assert that the new list is mutable
assertTrue("Removing an entry should succeed", list.remove(2) != null);
assertTrue("List should have 2 elements", list.size() == 2);
}
}