1   /**
2    * Copyright 2007 Art Technology Group, Inc (ATG)
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    *
7    * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and limitations under the License.
13   */
14  
15  package atg.taglib.json.util;
16  
17  import static org.junit.Assert.assertFalse;
18  import static org.junit.Assert.assertTrue;
19  
20  import org.junit.Test;
21  
22  /**
23   * Test class for JSONArray equality testing
24   *
25   * @author James Wiltshire
26   * @version $Id$
27   */
28  
29  public class JsonArrayEqualityTest
30  {
31    @Test
32    public void testArrays() throws JSONException
33    {
34      String s1="{foo:[]}";
35      String s2="{foo:[1,2,3]}";
36      String s3="{foo:[\"a\",\"b\",\"c\"]}";
37      String s4="{foo:[{bar:\"baz\",biz:\"boz\"},{bar2:\"baz2\",biz2:\"boz2\"}]}";
38        
39      JSONObject o1= new JSONObject(s1);
40      JSONObject o2= new JSONObject(s2);
41      JSONObject o3= new JSONObject(s3);
42      JSONObject o4= new JSONObject(s4);
43      
44      assertFalse(o1.equals(o2));
45      assertFalse(o1.equals(o3));
46      assertFalse(o1.equals(o4));
47      assertFalse(o2.equals(o3));
48      assertFalse(o2.equals(o4));
49      assertFalse(o3.equals(o4));
50      
51      
52      assertFalse(o1.equals(new JSONObject()));
53      assertFalse(o2.equals(new JSONObject()));
54      assertFalse(o3.equals(new JSONObject()));
55      assertFalse(o4.equals(new JSONObject()));
56      
57      assertTrue(o1.equals(new JSONObject(s1)));
58      assertTrue(o2.equals(new JSONObject(s2)));
59      assertTrue(o3.equals(new JSONObject(s3)));
60      assertTrue(o4.equals(new JSONObject(s4)));
61      
62      assertFalse(o1.equals(null));
63        
64    }
65  
66  }
67