1 16 package org.apache.commons.collections; 17 18 import java.util.ArrayList ; 19 import java.util.Hashtable ; 20 import java.util.List ; 21 import java.util.StringTokenizer ; 22 23 import junit.framework.Assert; 24 import junit.framework.Test; 25 26 32 public class TestEnumerationUtils extends BulkTest { 33 34 public TestEnumerationUtils(String name) { 35 super(name); 36 } 37 38 public static final String TO_LIST_FIXTURE = "this is a test"; 39 40 public void testToListWithStringTokenizer() { 41 List expectedList1 = new ArrayList (); 42 StringTokenizer st = new StringTokenizer (TO_LIST_FIXTURE); 43 while (st.hasMoreTokens()) { 44 expectedList1.add(st.nextToken()); 45 } 46 List expectedList2 = new ArrayList (); 47 expectedList2.add("this"); 48 expectedList2.add("is"); 49 expectedList2.add("a"); 50 expectedList2.add("test"); 51 List actualList = EnumerationUtils.toList(new StringTokenizer (TO_LIST_FIXTURE)); 52 Assert.assertEquals(expectedList1, expectedList2); 53 Assert.assertEquals(expectedList1, actualList); 54 Assert.assertEquals(expectedList2, actualList); 55 } 56 57 public void testToListWithHashtable() { 58 Hashtable expected = new Hashtable (); 59 expected.put("one", new Integer (1)); 60 expected.put("two", new Integer (2)); 61 expected.put("three", new Integer (3)); 62 List actualEltList = EnumerationUtils.toList(expected.elements()); 64 Assert.assertEquals(expected.size(), actualEltList.size()); 65 Assert.assertTrue(actualEltList.contains(new Integer (1))); 66 Assert.assertTrue(actualEltList.contains(new Integer (2))); 67 Assert.assertTrue(actualEltList.contains(new Integer (3))); 68 List expectedEltList = new ArrayList (); 69 expectedEltList.add(new Integer (1)); 70 expectedEltList.add(new Integer (2)); 71 expectedEltList.add(new Integer (3)); 72 Assert.assertTrue(actualEltList.containsAll(expectedEltList)); 73 74 List actualKeyList = EnumerationUtils.toList(expected.keys()); 76 Assert.assertEquals(expected.size(), actualEltList.size()); 77 Assert.assertTrue(actualKeyList.contains("one")); 78 Assert.assertTrue(actualKeyList.contains("two")); 79 Assert.assertTrue(actualKeyList.contains("three")); 80 List expectedKeyList = new ArrayList (); 81 expectedKeyList.add("one"); 82 expectedKeyList.add("two"); 83 expectedKeyList.add("three"); 84 Assert.assertTrue(actualKeyList.containsAll(expectedKeyList)); 85 } 86 87 public static Test suite() { 88 return BulkTest.makeSuite(TestEnumerationUtils.class); 89 } 90 91 } 92 | Popular Tags |