KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > TestCaseInsensitiveMap


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.map;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import junit.framework.Test;
23 import junit.textui.TestRunner;
24
25 import org.apache.commons.collections.BulkTest;
26
27 /**
28  * Tests for the {@link CaseInsensitiveMap} implementation.
29  *
30  * @version $Revision: 1.4 $ $Date: 2004/02/27 00:25:14 $
31  *
32  * @author Commons-Collections team
33  */

34 public class TestCaseInsensitiveMap extends AbstractTestIterableMap {
35
36     public TestCaseInsensitiveMap(String JavaDoc testName) {
37         super(testName);
38     }
39
40     public static void main(String JavaDoc[] args) {
41         TestRunner.run(suite());
42     }
43     
44     public static Test suite() {
45         return BulkTest.makeSuite(TestCaseInsensitiveMap.class);
46     }
47
48     public Map JavaDoc makeEmptyMap() {
49         return new CaseInsensitiveMap();
50     }
51     
52     public String JavaDoc getCompatibilityVersion() {
53         return "3";
54     }
55    
56     //-------------------------------------------------------------------------
57

58     public void testCaseInsensitive() {
59         Map JavaDoc map = new CaseInsensitiveMap();
60         map.put("One", "One");
61         map.put("Two", "Two");
62         assertEquals("One", (String JavaDoc) map.get("one"));
63         assertEquals("One", (String JavaDoc) map.get("oNe"));
64         map.put("two", "Three");
65         assertEquals("Three", (String JavaDoc) map.get("Two"));
66     }
67     
68     public void testNullHandling() {
69         Map JavaDoc map = new CaseInsensitiveMap();
70         map.put("One", "One");
71         map.put("Two", "Two");
72         map.put(null, "Three");
73         assertEquals("Three", (String JavaDoc) map.get(null));
74         map.put(null, "Four");
75         assertEquals("Four", (String JavaDoc) map.get(null));
76         Set JavaDoc 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 JavaDoc map = new HashMap JavaDoc();
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 JavaDoc(20), "Five");
90         Map JavaDoc caseInsensitiveMap = new CaseInsensitiveMap(map);
91         assertTrue(caseInsensitiveMap.size() == 4); // ones collapsed
92
Set JavaDoc 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")); // ones collaped
100
assertEquals(caseInsensitiveMap.get(null), "Four");
101     }
102
103     public void testClone() {
104         CaseInsensitiveMap map = new CaseInsensitiveMap(10);
105         map.put("1", "1");
106         Map JavaDoc cloned = (Map JavaDoc) map.clone();
107         assertEquals(map.size(), cloned.size());
108         assertSame(map.get("1"), cloned.get("1"));
109     }
110     
111     /*
112     public void testCreate() throws Exception {
113         resetEmpty();
114         writeExternalFormToDisk((java.io.Serializable) map, "/home/phil/jakarta-commons/collections/data/test/CaseInsensitiveMap.emptyCollection.version3.obj");
115         resetFull();
116         writeExternalFormToDisk((java.io.Serializable) map, "/home/phil/jakarta-commons/collections/data/test/CaseInsensitiveMap.fullCollection.version3.obj");
117     }
118      */

119 }
120
Popular Tags