1
2
3
4
5
6
7
8
9
10 package org.mule.util;
11
12 import org.mule.tck.junit4.AbstractMuleTestCase;
13
14 import org.apache.commons.lang.SerializationUtils;
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertFalse;
19 import static org.junit.Assert.assertTrue;
20
21 public class CaseInsensitiveHashMapTestCase extends AbstractMuleTestCase
22 {
23 protected CaseInsensitiveHashMap createTestMap()
24 {
25 CaseInsensitiveHashMap map = new CaseInsensitiveHashMap();
26 map.put("FOO", "BAR");
27 map.put("DOO", Integer.valueOf(3));
28 return map;
29 }
30
31 @Test
32 public void testMap() throws Exception
33 {
34 CaseInsensitiveHashMap map = createTestMap();
35 doTestMap(map);
36 }
37
38 @Test
39 public void testMapSerialization() throws Exception
40 {
41 CaseInsensitiveHashMap map = createTestMap();
42 doTestMap(map);
43
44 byte[] bytes = SerializationUtils.serialize(map);
45 CaseInsensitiveHashMap resultMap = (CaseInsensitiveHashMap)SerializationUtils.deserialize(bytes);
46 doTestMap(resultMap);
47 }
48
49 public void doTestMap(CaseInsensitiveHashMap map) throws Exception
50 {
51 assertEquals("BAR", map.get("FOO"));
52 assertEquals("BAR", map.get("foo"));
53 assertEquals("BAR", map.get("Foo"));
54
55 assertEquals(Integer.valueOf(3), map.get("DOO"));
56 assertEquals(Integer.valueOf(3), map.get("doo"));
57 assertEquals(Integer.valueOf(3), map.get("Doo"));
58
59 assertEquals(2, map.size());
60
61
62 for (Object o : map.keySet())
63 {
64 assertTrue(o.equals("FOO") || o.equals("DOO"));
65 assertFalse(o.equals("foo") || o.equals("doo"));
66 }
67 }
68 }