KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > CollectionUtilsTest


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation
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  */

17
18 package org.apache.tools.ant.util;
19
20 import java.util.Hashtable JavaDoc;
21 import java.util.Properties JavaDoc;
22 import java.util.Stack JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import junit.framework.TestCase;
26
27 /**
28  * Tests for org.apache.tools.ant.util.CollectionUtils.
29  *
30  */

31 public class CollectionUtilsTest extends TestCase {
32
33     public CollectionUtilsTest(String JavaDoc name) {
34         super(name);
35     }
36
37     public void testVectorEquals() {
38         assertTrue(!CollectionUtils.equals(null, new Vector JavaDoc()));
39         assertTrue(!CollectionUtils.equals(new Vector JavaDoc(), null));
40         assertTrue(CollectionUtils.equals(new Vector JavaDoc(), new Vector JavaDoc()));
41         Vector JavaDoc v1 = new Vector JavaDoc();
42         Stack JavaDoc s2 = new Stack JavaDoc();
43         v1.addElement("foo");
44         s2.push("foo");
45         assertTrue(CollectionUtils.equals(v1, s2));
46         assertTrue(CollectionUtils.equals(s2, v1));
47         v1.addElement("bar");
48         assertTrue(!CollectionUtils.equals(v1, s2));
49         assertTrue(!CollectionUtils.equals(s2, v1));
50         s2.push("bar");
51         assertTrue(CollectionUtils.equals(v1, s2));
52         assertTrue(CollectionUtils.equals(s2, v1));
53         s2.push("baz");
54         assertTrue(!CollectionUtils.equals(v1, s2));
55         assertTrue(!CollectionUtils.equals(s2, v1));
56         v1.addElement("baz");
57         assertTrue(CollectionUtils.equals(v1, s2));
58         assertTrue(CollectionUtils.equals(s2, v1));
59         v1.addElement("zyzzy");
60         s2.push("zyzzy2");
61         assertTrue(!CollectionUtils.equals(v1, s2));
62         assertTrue(!CollectionUtils.equals(s2, v1));
63     }
64
65     public void testDictionaryEquals() {
66         assertTrue(!CollectionUtils.equals(null, new Hashtable JavaDoc()));
67         assertTrue(!CollectionUtils.equals(new Hashtable JavaDoc(), null));
68         assertTrue(CollectionUtils.equals(new Hashtable JavaDoc(), new Properties JavaDoc()));
69         Hashtable JavaDoc h1 = new Hashtable JavaDoc();
70         Properties JavaDoc p2 = new Properties JavaDoc();
71         h1.put("foo", "");
72         p2.put("foo", "");
73         assertTrue(CollectionUtils.equals(h1, p2));
74         assertTrue(CollectionUtils.equals(p2, h1));
75         h1.put("bar", "");
76         assertTrue(!CollectionUtils.equals(h1, p2));
77         assertTrue(!CollectionUtils.equals(p2, h1));
78         p2.put("bar", "");
79         assertTrue(CollectionUtils.equals(h1, p2));
80         assertTrue(CollectionUtils.equals(p2, h1));
81         p2.put("baz", "");
82         assertTrue(!CollectionUtils.equals(h1, p2));
83         assertTrue(!CollectionUtils.equals(p2, h1));
84         h1.put("baz", "");
85         assertTrue(CollectionUtils.equals(h1, p2));
86         assertTrue(CollectionUtils.equals(p2, h1));
87         h1.put("zyzzy", "");
88         p2.put("zyzzy2", "");
89         assertTrue(!CollectionUtils.equals(h1, p2));
90         assertTrue(!CollectionUtils.equals(p2, h1));
91         p2.put("zyzzy", "");
92         h1.put("zyzzy2", "");
93         assertTrue(CollectionUtils.equals(h1, p2));
94         assertTrue(CollectionUtils.equals(p2, h1));
95         h1.put("dada", "1");
96         p2.put("dada", "2");
97         assertTrue(!CollectionUtils.equals(h1, p2));
98         assertTrue(!CollectionUtils.equals(p2, h1));
99     }
100 }
101
Popular Tags