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