1 package net.sourceforge.jpotpourri.util;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.LinkedHashMap;
6 import java.util.LinkedHashSet;
7 import java.util.Map;
8 import java.util.Set;
9
10 import junit.framework.TestCase;
11
12
13
14
15 public class CollectionUtilTest extends TestCase {
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public final void testToStringSetOfObject() {
62
63 assertEquals("null", CollectionUtil.toString((Set<?>) null));
64 assertEquals("Set[]", CollectionUtil.toString(new HashSet<String>()));
65
66 final Set<String> set = new LinkedHashSet<String>(2);
67 set.add("abc");
68 set.add("def");
69 assertEquals("Set[abc;def]", CollectionUtil.toString(set));
70 }
71
72
73
74
75
76
77
78 public final void testToStringMapOfObjectObject() throws Exception {
79 assertEquals("null", CollectionUtil.toString((Map<?, ?>) null));
80 assertEquals("Map[]", CollectionUtil.toString(new HashMap<String, String>()));
81
82 final Map<String, String> map = new LinkedHashMap<String, String>(4);
83 map.put("a", "b");
84 map.put("1", "2");
85 map.put("x", "");
86 map.put("y", null);
87 assertEquals("Map[a=b;1=2;x=;y=null]", CollectionUtil.toString(map));
88 }
89 }