View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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          // Test that the key set contains the same case as we put in
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  }