mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 11:05:28 -04:00
cleanup-and-merge-tests: pull in unit tests from #809
This commit is contained in:
parent
5ddb8c3d35
commit
86bb0a1a02
@ -3760,6 +3760,48 @@ public class JSONObjectTest {
|
||||
String jsonString = object.toString();
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void testCircleReferenceFirstLevel() {
|
||||
Map<Object, Object> jsonObject = new HashMap<>();
|
||||
|
||||
jsonObject.put("test", jsonObject);
|
||||
|
||||
new JSONObject(jsonObject, new JSONParserConfiguration());
|
||||
}
|
||||
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void testCircleReferenceMultiplyLevel_notConfigured_expectedStackOverflow() {
|
||||
Map<Object, Object> inside = new HashMap<>();
|
||||
|
||||
Map<Object, Object> jsonObject = new HashMap<>();
|
||||
inside.put("test", jsonObject);
|
||||
jsonObject.put("test", inside);
|
||||
|
||||
new JSONObject(jsonObject, new JSONParserConfiguration().withMaxNestingDepth(99999));
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void testCircleReferenceMultiplyLevel_configured_expectedJSONException() {
|
||||
Map<Object, Object> inside = new HashMap<>();
|
||||
|
||||
Map<Object, Object> jsonObject = new HashMap<>();
|
||||
inside.put("test", jsonObject);
|
||||
jsonObject.put("test", inside);
|
||||
|
||||
new JSONObject(jsonObject, new JSONParserConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentKeySameInstanceNotACircleReference() {
|
||||
Map<Object, Object> map1 = new HashMap<>();
|
||||
Map<Object, Object> map2 = new HashMap<>();
|
||||
|
||||
map1.put("test1", map2);
|
||||
map1.put("test2", map2);
|
||||
|
||||
new JSONObject(map1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build nested map of max maxDepth
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user