1 17 18 package org.apache.tools.ant.util; 19 20 import java.util.Hashtable ; 21 import java.util.Properties ; 22 import java.util.Stack ; 23 import java.util.Vector ; 24 25 import junit.framework.TestCase; 26 27 31 public class CollectionUtilsTest extends TestCase { 32 33 public CollectionUtilsTest(String name) { 34 super(name); 35 } 36 37 public void testVectorEquals() { 38 assertTrue(!CollectionUtils.equals(null, new Vector ())); 39 assertTrue(!CollectionUtils.equals(new Vector (), null)); 40 assertTrue(CollectionUtils.equals(new Vector (), new Vector ())); 41 Vector v1 = new Vector (); 42 Stack s2 = new Stack (); 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 ())); 67 assertTrue(!CollectionUtils.equals(new Hashtable (), null)); 68 assertTrue(CollectionUtils.equals(new Hashtable (), new Properties ())); 69 Hashtable h1 = new Hashtable (); 70 Properties p2 = new Properties (); 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 |