1
- /*
2
- * Copyright 1999-2011 Alibaba Group.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
1
+ /*
2
+ * Copyright 1999-2011 Alibaba Group.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
16
package com .alibaba .dubbo .common .json ;
17
17
18
18
import java .io .StringReader ;
23
23
import java .util .Map ;
24
24
25
25
import junit .framework .Assert ;
26
- import junit .framework .TestCase ;
26
+ import org .junit .Ignore ;
27
+ import org .junit .Test ;
27
28
28
- public class JSONTest extends TestCase
29
- {
29
+ import static org .junit .Assert .assertEquals ;
30
+
31
+ public class JSONTest {
32
+ @ Test
33
+ @ Ignore
30
34
public void testException () throws Exception {
31
35
MyException e = new MyException ("001" , "AAAAAAAA" );
32
36
@@ -42,6 +46,7 @@ public void testException() throws Exception {
42
46
Assert .assertEquals ("AAAAAAAA" , result .getMessage ());
43
47
}
44
48
49
+ @ Test
45
50
@ SuppressWarnings ("unchecked" )
46
51
public void testMap () throws Exception {
47
52
Map <String , String > map = new HashMap <String , String >();
@@ -57,6 +62,7 @@ public void testMap() throws Exception {
57
62
Assert .assertEquals ("bbb" , result .get ("aaa" ));
58
63
}
59
64
65
+ @ Test
60
66
@ SuppressWarnings ("unchecked" )
61
67
public void testMapArray () throws Exception {
62
68
Map <String , String > map = new HashMap <String , String >();
@@ -73,6 +79,7 @@ public void testMapArray() throws Exception {
73
79
Assert .assertEquals ("bbb" , ((Map <String , String >)result [0 ]).get ("aaa" ));
74
80
}
75
81
82
+ @ Test
76
83
@ SuppressWarnings ("unchecked" )
77
84
public void testLinkedMap () throws Exception {
78
85
LinkedHashMap <String , String > map = new LinkedHashMap <String , String >();
@@ -88,6 +95,7 @@ public void testLinkedMap() throws Exception {
88
95
Assert .assertEquals ("bbb" , result .get ("aaa" ));
89
96
}
90
97
98
+ @ Test
91
99
public void testObject2Json () throws Exception
92
100
{
93
101
Bean bean = new Bean ();
@@ -104,6 +112,7 @@ public void testObject2Json() throws Exception
104
112
assertEquals ("{\" name\" :\" ql\" ,\" array\" :[1,3,4]}" , JSON .json (bean , new String []{"name" , "array" }));
105
113
}
106
114
115
+ @ Test
107
116
public void testParse2JSONObject () throws Exception
108
117
{
109
118
JSONObject jo = (JSONObject )JSON .parse ("{name:'qianlei',array:[1,2,3,4,98.123],b1:TRUE,$1:NULL,$2:FALSE,__3:NULL}" );
@@ -121,6 +130,7 @@ public void testParse2JSONObject() throws Exception
121
130
System .out .println ("parse to JSONObject 10000 times in: " + ( System .currentTimeMillis ()-now ) );
122
131
}
123
132
133
+ @ Test
124
134
@ SuppressWarnings ("unchecked" )
125
135
public void testParse2Class () throws Exception
126
136
{
@@ -132,7 +142,7 @@ public void testParse2Class() throws Exception
132
142
List l1 = (List )JSON .parse ("[1.2,2,3,4,5]" , List .class );
133
143
assertEquals (l1 .size (), 5 );
134
144
for (int i =0 ;i <5 ;i ++)
135
- assertEquals (o1 [i ], ((Number )l1 .get (i )).intValue ());
145
+ assertEquals (o1 [i ], ((Number ) l1 .get (i )).intValue ());
136
146
137
147
Bean bean = JSON .parse ("{name:'qianlei',array:[1,2,3,4,98.123],displayName:'钱磊',$$:214726,$b:TRUE}" , Bean .class );
138
148
assertEquals (bean .getName (), "qianlei" );
@@ -150,6 +160,7 @@ public void testParse2Class() throws Exception
150
160
System .out .println ("parse to Class 10000 times in: " + ( System .currentTimeMillis ()-now ) );
151
161
}
152
162
163
+ @ Test
153
164
public void testParse2Arguments () throws Exception
154
165
{
155
166
Object [] test = JSON .parse ("[1.2, 2, {name:'qianlei',array:[1,2,3,4,98.123]} ]" , new Class <?>[]{ int .class , int .class , Bean .class });
0 commit comments