11 |
|
import java.util.Enumeration; |
12 |
|
import java.io.*; |
13 |
|
|
14 |
< |
public class ConcurrentHashMapTest extends TestCase{ |
14 |
> |
public class ConcurrentHashMapTest extends JSR166TestCase{ |
15 |
|
public static void main(String[] args) { |
16 |
|
junit.textui.TestRunner.run (suite()); |
17 |
|
} |
19 |
|
return new TestSuite(ConcurrentHashMapTest.class); |
20 |
|
} |
21 |
|
|
22 |
– |
static final Integer one = new Integer(1); |
23 |
– |
static final Integer two = new Integer(2); |
24 |
– |
static final Integer three = new Integer(3); |
25 |
– |
static final Integer four = new Integer(4); |
26 |
– |
static final Integer five = new Integer(5); |
27 |
– |
|
22 |
|
private static ConcurrentHashMap map5() { |
23 |
|
ConcurrentHashMap map = new ConcurrentHashMap(5); |
24 |
|
assertTrue(map.isEmpty()); |
33 |
|
} |
34 |
|
|
35 |
|
/** |
36 |
< |
* Test to verify clear correctly removes all key-element pairs from the map |
36 |
> |
* clear removes all key-element pairs from the map |
37 |
|
*/ |
38 |
|
public void testClear(){ |
39 |
|
ConcurrentHashMap map = map5(); |
42 |
|
} |
43 |
|
|
44 |
|
/** |
45 |
< |
* Test to verify contains gives the appropriate value |
45 |
> |
* contains gives the appropriate value |
46 |
|
*/ |
47 |
|
public void testContains(){ |
48 |
|
ConcurrentHashMap map = map5(); |
51 |
|
} |
52 |
|
|
53 |
|
/** |
54 |
< |
* Test to verify containsKey gives the appropriate value |
54 |
> |
* containsKey gives the appropriate value |
55 |
|
*/ |
56 |
|
public void testContainsKey(){ |
57 |
|
ConcurrentHashMap map = map5(); |
69 |
|
} |
70 |
|
|
71 |
|
/** |
72 |
< |
* tes to verify enumeration returns an enumeration containing the correct elements |
72 |
> |
* enumeration returns an enumeration containing the correct |
73 |
> |
* elements |
74 |
|
*/ |
75 |
|
public void testEnumeration(){ |
76 |
|
ConcurrentHashMap map = map5(); |
84 |
|
} |
85 |
|
|
86 |
|
/** |
87 |
< |
* Test to verify get returns the correct element at the given index |
87 |
> |
* Clone creates an equal map |
88 |
> |
*/ |
89 |
> |
public void testClone(){ |
90 |
> |
ConcurrentHashMap map = map5(); |
91 |
> |
ConcurrentHashMap m2 = (ConcurrentHashMap)(map.clone()); |
92 |
> |
assertEquals(map, m2); |
93 |
> |
} |
94 |
> |
|
95 |
> |
/** |
96 |
> |
* get returns the correct element at the given index |
97 |
|
*/ |
98 |
|
public void testGet(){ |
99 |
|
ConcurrentHashMap map = map5(); |
101 |
|
} |
102 |
|
|
103 |
|
/** |
104 |
< |
* Test to verify get on a nonexistant key returns null |
104 |
> |
* get on a nonexistant key returns null |
105 |
|
*/ |
106 |
|
public void testGet2(){ |
107 |
|
ConcurrentHashMap empty = new ConcurrentHashMap(); |
119 |
|
} |
120 |
|
|
121 |
|
/** |
122 |
< |
* Test to verify keys returns an enumeration containing all the keys from the map |
122 |
> |
* keys returns an enumeration containing all the keys from the map |
123 |
|
*/ |
124 |
|
public void testKeys(){ |
125 |
|
ConcurrentHashMap map = map5(); |
133 |
|
} |
134 |
|
|
135 |
|
/** |
136 |
< |
* Test to verify keySet returns a Set containing all the keys |
136 |
> |
* keySet returns a Set containing all the keys |
137 |
|
*/ |
138 |
|
public void testKeySet(){ |
139 |
|
ConcurrentHashMap map = map5(); |
174 |
|
} |
175 |
|
|
176 |
|
/** |
177 |
< |
* Test to verify putAll correctly adds all key-value pairs from the given map |
177 |
> |
* putAll adds all key-value pairs from the given map |
178 |
|
*/ |
179 |
|
public void testPutAll(){ |
180 |
|
ConcurrentHashMap empty = new ConcurrentHashMap(); |
189 |
|
} |
190 |
|
|
191 |
|
/** |
192 |
< |
* Test to verify putIfAbsent works when the given key is not present |
192 |
> |
* putIfAbsent works when the given key is not present |
193 |
|
*/ |
194 |
|
public void testPutIfAbsent(){ |
195 |
|
ConcurrentHashMap map = map5(); |
198 |
|
} |
199 |
|
|
200 |
|
/** |
201 |
< |
* Test to verify putIfAbsent does not add the pair if the key is already present |
201 |
> |
* putIfAbsent does not add the pair if the key is already present |
202 |
|
*/ |
203 |
|
public void testPutIfAbsent2(){ |
204 |
|
ConcurrentHashMap map = map5(); |
206 |
|
} |
207 |
|
|
208 |
|
/** |
209 |
< |
* Test to verify remove removes the correct key-value pair from the map |
209 |
> |
* remove removes the correct key-value pair from the map |
210 |
|
*/ |
211 |
|
public void testRemove(){ |
212 |
|
ConcurrentHashMap map = map5(); |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
< |
* Simple test to verify size returns the correct values |
230 |
> |
* size returns the correct values |
231 |
|
*/ |
232 |
|
public void testSize(){ |
233 |
|
ConcurrentHashMap map = map5(); |