forked from stleary/JSON-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSONObjectRecursiveExceptionTest.java
75 lines (62 loc) · 1.87 KB
/
JSONObjectRecursiveExceptionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.json.junit;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hamcrest.core.StringContains;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class JSONObjectRecursiveExceptionTest {
public static class RecursiveList {
public List<RecursiveList> getRecursiveList() {
return Collections.singletonList(this);
}
}
public static class RecursiveArray {
public RecursiveArray[] getRecursiveArray() {
return new RecursiveArray[] {this};
}
}
public static class RecursiveMap {
public Map<String, RecursiveMap> getRecursiveMap() {
Map<String, RecursiveMap> map = new HashMap<String, RecursiveMap>();
map.put("test", this);
return map;
}
}
public static class Recursive {
public Recursive getSelf() {
return this;
}
}
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Before
public void before() {
exceptionRule.expect(JSONException.class);
exceptionRule.expectMessage(StringContains.containsString("JavaBean object contains recursively defined member variable of key"));
}
@Test
public void testRecursiveList() {
new JSONObject(new RecursiveList());
}
@Ignore
@Test
public void testRecursiveArray() {
new JSONObject(new RecursiveArray());
}
@Ignore
@Test
public void testRecursiveMap() {
new JSONObject(new RecursiveMap());
}
@Test
public void testRecursive() {
new JSONObject(new Recursive());
}
}