/
DefaultExtJSONParser_parseArray_2.java
125 lines (104 loc) · 3.95 KB
/
DefaultExtJSONParser_parseArray_2.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.alibaba.json.bvt.parser;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.Feature;
@SuppressWarnings("deprecation")
public class DefaultExtJSONParser_parseArray_2 extends TestCase {
public void test_0() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[['1']]");
parser.config(Feature.AllowISO8601DateFormat, false);
List<List<Integer>> list = (List<List<Integer>>) parser.parseArrayWithType(new TypeReference<List<List<Integer>>>() {
}.getType());
Assert.assertEquals(new Integer(1), list.get(0).get(0));
}
public void test_1() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("['1','2']");
parser.config(Feature.AllowISO8601DateFormat, false);
List<Object> list = new ArrayList<Object>();
parser.parseArray(Integer.class, list);
Assert.assertEquals(new Integer(1), list.get(0));
Assert.assertEquals(new Integer(2), list.get(1));
}
public void test_error_0() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("['1','2'}");
parser.config(Feature.AllowISO8601DateFormat, false);
Exception error = null;
try {
List<Object> list = new ArrayList<Object>();
parser.parseArray(Integer.class, list);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error_1() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[['1']]");
parser.config(Feature.AllowISO8601DateFormat, false);
Exception error = null;
try {
parser.parseArrayWithType(new TypeReference<Map<?, ?>>() {
}.getType());
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error_2() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[new X()]");
parser.config(Feature.AllowISO8601DateFormat, false);
List list = new ArrayList();
Exception error = null;
try {
parser.parseArray(list);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error_3() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[] a");
parser.config(Feature.AllowISO8601DateFormat, false);
List list = new ArrayList();
Exception error = null;
try {
parser.parseArray(list);
parser.close();
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error_4() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("['1','2'}");
parser.config(Feature.AllowISO8601DateFormat, false);
Exception error = null;
try {
parser.parseArray(new Type[] {});
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error_5() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[]");
parser.config(Feature.AllowISO8601DateFormat, false);
Assert.assertEquals(1, parser.parseArray(new Type[] { Integer[].class }).length);
}
public void test_error_6() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("['1' 1 '2'}");
parser.config(Feature.AllowISO8601DateFormat, false);
Exception error = null;
try {
parser.parseArray(new Type[] {Integer.class});
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}