1 16 package org.apache.commons.collections.map; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 import java.util.Set ; 21 22 import junit.framework.Test; 23 import junit.textui.TestRunner; 24 25 import org.apache.commons.collections.BulkTest; 26 27 34 public class TestCaseInsensitiveMap extends AbstractTestIterableMap { 35 36 public TestCaseInsensitiveMap(String testName) { 37 super(testName); 38 } 39 40 public static void main(String [] args) { 41 TestRunner.run(suite()); 42 } 43 44 public static Test suite() { 45 return BulkTest.makeSuite(TestCaseInsensitiveMap.class); 46 } 47 48 public Map makeEmptyMap() { 49 return new CaseInsensitiveMap(); 50 } 51 52 public String getCompatibilityVersion() { 53 return "3"; 54 } 55 56 58 public void testCaseInsensitive() { 59 Map map = new CaseInsensitiveMap(); 60 map.put("One", "One"); 61 map.put("Two", "Two"); 62 assertEquals("One", (String ) map.get("one")); 63 assertEquals("One", (String ) map.get("oNe")); 64 map.put("two", "Three"); 65 assertEquals("Three", (String ) map.get("Two")); 66 } 67 68 public void testNullHandling() { 69 Map map = new CaseInsensitiveMap(); 70 map.put("One", "One"); 71 map.put("Two", "Two"); 72 map.put(null, "Three"); 73 assertEquals("Three", (String ) map.get(null)); 74 map.put(null, "Four"); 75 assertEquals("Four", (String ) map.get(null)); 76 Set keys = map.keySet(); 77 assertTrue(keys.contains("one")); 78 assertTrue(keys.contains("two")); 79 assertTrue(keys.contains(null)); 80 assertTrue(keys.size() == 3); 81 } 82 83 public void testPutAll() { 84 Map map = new HashMap (); 85 map.put("One", "One"); 86 map.put("Two", "Two"); 87 map.put("one", "Three"); 88 map.put(null, "Four"); 89 map.put(new Integer (20), "Five"); 90 Map caseInsensitiveMap = new CaseInsensitiveMap(map); 91 assertTrue(caseInsensitiveMap.size() == 4); Set keys = caseInsensitiveMap.keySet(); 93 assertTrue(keys.contains("one")); 94 assertTrue(keys.contains("two")); 95 assertTrue(keys.contains(null)); 96 assertTrue(keys.contains(Integer.toString(20))); 97 assertTrue(keys.size() == 4); 98 assertTrue(!caseInsensitiveMap.containsValue("One") 99 || !caseInsensitiveMap.containsValue("Three")); assertEquals(caseInsensitiveMap.get(null), "Four"); 101 } 102 103 public void testClone() { 104 CaseInsensitiveMap map = new CaseInsensitiveMap(10); 105 map.put("1", "1"); 106 Map cloned = (Map ) map.clone(); 107 assertEquals(map.size(), cloned.size()); 108 assertSame(map.get("1"), cloned.get("1")); 109 } 110 111 119 } 120 | Popular Tags |