001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.util;
020:
021: import java.util.Hashtable;
022: import java.util.Properties;
023: import java.util.Stack;
024: import java.util.Vector;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * Tests for org.apache.tools.ant.util.CollectionUtils.
030: *
031: */
032: public class CollectionUtilsTest extends TestCase {
033:
034: public CollectionUtilsTest(String name) {
035: super (name);
036: }
037:
038: public void testVectorEquals() {
039: assertTrue(!CollectionUtils.equals(null, new Vector()));
040: assertTrue(!CollectionUtils.equals(new Vector(), null));
041: assertTrue(CollectionUtils.equals(new Vector(), new Vector()));
042: Vector v1 = new Vector();
043: Stack s2 = new Stack();
044: v1.addElement("foo");
045: s2.push("foo");
046: assertTrue(CollectionUtils.equals(v1, s2));
047: assertTrue(CollectionUtils.equals(s2, v1));
048: v1.addElement("bar");
049: assertTrue(!CollectionUtils.equals(v1, s2));
050: assertTrue(!CollectionUtils.equals(s2, v1));
051: s2.push("bar");
052: assertTrue(CollectionUtils.equals(v1, s2));
053: assertTrue(CollectionUtils.equals(s2, v1));
054: s2.push("baz");
055: assertTrue(!CollectionUtils.equals(v1, s2));
056: assertTrue(!CollectionUtils.equals(s2, v1));
057: v1.addElement("baz");
058: assertTrue(CollectionUtils.equals(v1, s2));
059: assertTrue(CollectionUtils.equals(s2, v1));
060: v1.addElement("zyzzy");
061: s2.push("zyzzy2");
062: assertTrue(!CollectionUtils.equals(v1, s2));
063: assertTrue(!CollectionUtils.equals(s2, v1));
064: }
065:
066: public void testDictionaryEquals() {
067: assertTrue(!CollectionUtils.equals(null, new Hashtable()));
068: assertTrue(!CollectionUtils.equals(new Hashtable(), null));
069: assertTrue(CollectionUtils.equals(new Hashtable(),
070: new Properties()));
071: Hashtable h1 = new Hashtable();
072: Properties p2 = new Properties();
073: h1.put("foo", "");
074: p2.put("foo", "");
075: assertTrue(CollectionUtils.equals(h1, p2));
076: assertTrue(CollectionUtils.equals(p2, h1));
077: h1.put("bar", "");
078: assertTrue(!CollectionUtils.equals(h1, p2));
079: assertTrue(!CollectionUtils.equals(p2, h1));
080: p2.put("bar", "");
081: assertTrue(CollectionUtils.equals(h1, p2));
082: assertTrue(CollectionUtils.equals(p2, h1));
083: p2.put("baz", "");
084: assertTrue(!CollectionUtils.equals(h1, p2));
085: assertTrue(!CollectionUtils.equals(p2, h1));
086: h1.put("baz", "");
087: assertTrue(CollectionUtils.equals(h1, p2));
088: assertTrue(CollectionUtils.equals(p2, h1));
089: h1.put("zyzzy", "");
090: p2.put("zyzzy2", "");
091: assertTrue(!CollectionUtils.equals(h1, p2));
092: assertTrue(!CollectionUtils.equals(p2, h1));
093: p2.put("zyzzy", "");
094: h1.put("zyzzy2", "");
095: assertTrue(CollectionUtils.equals(h1, p2));
096: assertTrue(CollectionUtils.equals(p2, h1));
097: h1.put("dada", "1");
098: p2.put("dada", "2");
099: assertTrue(!CollectionUtils.equals(h1, p2));
100: assertTrue(!CollectionUtils.equals(p2, h1));
101: }
102: }
|