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+ */
1616package com .alibaba .dubbo .common .json ;
1717
1818import java .io .StringReader ;
2323import java .util .Map ;
2424
2525import junit .framework .Assert ;
26- import junit .framework .TestCase ;
26+ import org .junit .Ignore ;
27+ import org .junit .Test ;
2728
28- public class JSONTest extends TestCase
29- {
29+ import static org .junit .Assert .assertEquals ;
30+
31+ public class JSONTest {
32+ @ Test
33+ @ Ignore
3034 public void testException () throws Exception {
3135 MyException e = new MyException ("001" , "AAAAAAAA" );
3236
@@ -42,6 +46,7 @@ public void testException() throws Exception {
4246 Assert .assertEquals ("AAAAAAAA" , result .getMessage ());
4347 }
4448
49+ @ Test
4550 @ SuppressWarnings ("unchecked" )
4651 public void testMap () throws Exception {
4752 Map <String , String > map = new HashMap <String , String >();
@@ -57,6 +62,7 @@ public void testMap() throws Exception {
5762 Assert .assertEquals ("bbb" , result .get ("aaa" ));
5863 }
5964
65+ @ Test
6066 @ SuppressWarnings ("unchecked" )
6167 public void testMapArray () throws Exception {
6268 Map <String , String > map = new HashMap <String , String >();
@@ -73,6 +79,7 @@ public void testMapArray() throws Exception {
7379 Assert .assertEquals ("bbb" , ((Map <String , String >)result [0 ]).get ("aaa" ));
7480 }
7581
82+ @ Test
7683 @ SuppressWarnings ("unchecked" )
7784 public void testLinkedMap () throws Exception {
7885 LinkedHashMap <String , String > map = new LinkedHashMap <String , String >();
@@ -88,6 +95,7 @@ public void testLinkedMap() throws Exception {
8895 Assert .assertEquals ("bbb" , result .get ("aaa" ));
8996 }
9097
98+ @ Test
9199 public void testObject2Json () throws Exception
92100 {
93101 Bean bean = new Bean ();
@@ -104,6 +112,7 @@ public void testObject2Json() throws Exception
104112 assertEquals ("{\" name\" :\" ql\" ,\" array\" :[1,3,4]}" , JSON .json (bean , new String []{"name" , "array" }));
105113 }
106114
115+ @ Test
107116 public void testParse2JSONObject () throws Exception
108117 {
109118 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
121130 System .out .println ("parse to JSONObject 10000 times in: " + ( System .currentTimeMillis ()-now ) );
122131 }
123132
133+ @ Test
124134 @ SuppressWarnings ("unchecked" )
125135 public void testParse2Class () throws Exception
126136 {
@@ -132,7 +142,7 @@ public void testParse2Class() throws Exception
132142 List l1 = (List )JSON .parse ("[1.2,2,3,4,5]" , List .class );
133143 assertEquals (l1 .size (), 5 );
134144 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 ());
136146
137147 Bean bean = JSON .parse ("{name:'qianlei',array:[1,2,3,4,98.123],displayName:'钱磊',$$:214726,$b:TRUE}" , Bean .class );
138148 assertEquals (bean .getName (), "qianlei" );
@@ -150,6 +160,7 @@ public void testParse2Class() throws Exception
150160 System .out .println ("parse to Class 10000 times in: " + ( System .currentTimeMillis ()-now ) );
151161 }
152162
163+ @ Test
153164 public void testParse2Arguments () throws Exception
154165 {
155166 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