1
2
3
4
5
6
7
8
9
10
11 package org.mule.util;
12
13 import org.mule.tck.AbstractMuleTestCase;
14
15 import java.util.Arrays;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.apache.commons.collections.map.CaseInsensitiveMap;
21
22 public class MapUtilsTestCase extends AbstractMuleTestCase
23 {
24
25 public void testMapCreationNullClass()
26 {
27 try
28 {
29 MapUtils.mapWithKeysAndValues(null, (String[])null, (String[])null);
30 fail();
31 }
32 catch (IllegalArgumentException ex)
33 {
34
35 }
36 }
37
38 public void testMapCreationWithoutElements()
39 {
40 Map m = MapUtils.mapWithKeysAndValues(HashMap.class, (List)null, (List)null);
41 assertTrue(m.isEmpty());
42 }
43
44 public void testCaseInsensitiveMapCreation()
45 {
46 List strings = Arrays.asList(new String[]{"foo"});
47
48 Map m = MapUtils.mapWithKeysAndValues(CaseInsensitiveMap.class, strings.iterator(), strings
49 .iterator());
50
51 assertEquals("foo", m.get("foo"));
52 assertEquals("foo", m.get("Foo"));
53 assertEquals("foo", m.get("FOO"));
54 }
55
56 public void testToStringNull() throws Exception
57 {
58 Map props = null;
59 assertEquals("{}", MapUtils.toString(props, false));
60 assertEquals("{}", MapUtils.toString(props, true));
61 }
62
63 public void testToStringEmpty() throws Exception
64 {
65 Map props = new HashMap();
66 assertEquals("{}", MapUtils.toString(props, false));
67 assertEquals("{}", MapUtils.toString(props, true));
68 }
69
70 public void testToStringSingleElement() throws Exception
71 {
72 Map props = MapUtils.mapWithKeysAndValues(HashMap.class, new Object[]{"foo"}, new Object[]{"bar"});
73
74 assertEquals("{foo=bar}", MapUtils.toString(props, false));
75 assertEquals("{" + SystemUtils.LINE_SEPARATOR + "foo=bar" + SystemUtils.LINE_SEPARATOR + "}",
76 MapUtils.toString(props, true));
77 }
78
79 public void testToStringMultipleElements() throws Exception
80 {
81 Map props = MapUtils.mapWithKeysAndValues(HashMap.class, new Object[]{"foo", "foozle"}, new Object[]{
82 "bar", "doozle"});
83
84 String result = MapUtils.toString(props, false);
85 assertTrue(result.indexOf("foo=bar") != -1);
86 assertTrue(result.indexOf("foozle=doozle") != -1);
87
88 result = MapUtils.toString(props, true);
89 assertTrue(result.startsWith("{" + SystemUtils.LINE_SEPARATOR));
90 assertTrue(result.indexOf("foo=bar") != -1);
91 assertTrue(result.indexOf("foozle=doozle") != -1);
92 assertTrue(result.endsWith(SystemUtils.LINE_SEPARATOR + "}"));
93 }
94
95 }