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