01: /*
02: * Copyright 2001-2005 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.Map;
19:
20: import junit.framework.Test;
21:
22: import org.apache.commons.collections.BulkTest;
23:
24: /**
25: * Unit tests.
26: * {@link StaticBucketMap}.
27: *
28: * @version $Revision: 348273 $ $Date: 2005-11-22 22:24:25 +0000 (Tue, 22 Nov 2005) $
29: *
30: * @author Michael A. Smith
31: */
32: public class TestStaticBucketMap extends AbstractTestMap {
33:
34: public TestStaticBucketMap(String name) {
35: super (name);
36: }
37:
38: public static Test suite() {
39: return BulkTest.makeSuite(TestStaticBucketMap.class);
40: }
41:
42: public static void main(String[] args) {
43: String[] testCaseName = { TestStaticBucketMap.class.getName() };
44: junit.textui.TestRunner.main(testCaseName);
45: }
46:
47: public Map makeEmptyMap() {
48: return new StaticBucketMap(30);
49: }
50:
51: public String[] ignoredTests() {
52: String pre = "TestStaticBucketMap.bulkTestMap";
53: String post = ".testCollectionIteratorFailFast";
54: return new String[] { pre + "EntrySet" + post,
55: pre + "KeySet" + post, pre + "Values" + post };
56: }
57:
58: // Bugzilla 37567
59: public void test_get_nullMatchesIncorrectly() {
60: StaticBucketMap map = new StaticBucketMap(17);
61: map.put(null, "A");
62: assertEquals("A", map.get(null));
63: // loop so we find a string that is in the same bucket as the null
64: for (int i = 'A'; i <= 'Z'; i++) {
65: String str = String.valueOf((char) i);
66: assertEquals("String: " + str, null, map.get(str));
67: }
68: }
69:
70: public void test_containsKey_nullMatchesIncorrectly() {
71: StaticBucketMap map = new StaticBucketMap(17);
72: map.put(null, "A");
73: assertEquals(true, map.containsKey(null));
74: // loop so we find a string that is in the same bucket as the null
75: for (int i = 'A'; i <= 'Z'; i++) {
76: String str = String.valueOf((char) i);
77: assertEquals("String: " + str, false, map.containsKey(str));
78: }
79: }
80:
81: public void test_containsValue_nullMatchesIncorrectly() {
82: StaticBucketMap map = new StaticBucketMap(17);
83: map.put("A", null);
84: assertEquals(true, map.containsValue(null));
85: // loop so we find a string that is in the same bucket as the null
86: for (int i = 'A'; i <= 'Z'; i++) {
87: String str = String.valueOf((char) i);
88: assertEquals("String: " + str, false, map
89: .containsValue(str));
90: }
91: }
92:
93: }
|