View Javadoc

1   /*
2    * $Id: CaseInsensitiveHashMapTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.util;
11  
12  import org.mule.tck.AbstractMuleTestCase;
13  
14  import org.apache.commons.lang.SerializationUtils;
15  import org.junit.Test;
16  
17  public class CaseInsensitiveHashMapTestCase extends AbstractMuleTestCase
18  {
19      protected CaseInsensitiveHashMap createTestMap()
20      {
21          CaseInsensitiveHashMap map = new CaseInsensitiveHashMap();
22          map.put("FOO", "BAR");
23          map.put("DOO", Integer.valueOf(3));
24          return map;
25      }
26  
27      @Test
28      public void testMap() throws Exception
29      {
30          CaseInsensitiveHashMap map = createTestMap();
31          doTestMap(map);
32      }
33  
34      @Test
35      public void testMapSerialization() throws Exception
36      {
37          CaseInsensitiveHashMap map = createTestMap();
38          doTestMap(map);
39  
40          byte[] bytes = SerializationUtils.serialize(map);
41          CaseInsensitiveHashMap resultMap = (CaseInsensitiveHashMap)SerializationUtils.deserialize(bytes);
42          doTestMap(resultMap);
43      }
44  
45      public void doTestMap(CaseInsensitiveHashMap  map) throws Exception
46      {
47          assertEquals("BAR", map.get("FOO"));
48          assertEquals("BAR", map.get("foo"));
49          assertEquals("BAR", map.get("Foo"));
50  
51          assertEquals(Integer.valueOf(3), map.get("DOO"));
52          assertEquals(Integer.valueOf(3), map.get("doo"));
53          assertEquals(Integer.valueOf(3), map.get("Doo"));
54  
55          assertEquals(2, map.size());
56  
57          // Test that the key set contains the same case as we put in
58          for (Object o : map.keySet())
59          {
60              assertTrue(o.equals("FOO") || o.equals("DOO"));
61              assertFalse(o.equals("foo") || o.equals("doo"));
62          }
63      }
64  }