14 |
|
|
15 |
|
public class ConcurrentHashMapTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run(suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
|
return new TestSuite(ConcurrentHashMapTest.class); |
37 |
|
} |
38 |
|
|
39 |
|
/** |
40 |
< |
* clear removes all pairs |
40 |
> |
* clear removes all pairs |
41 |
|
*/ |
42 |
|
public void testClear() { |
43 |
|
ConcurrentHashMap map = map5(); |
46 |
|
} |
47 |
|
|
48 |
|
/** |
49 |
< |
* Maps with same contents are equal |
49 |
> |
* Maps with same contents are equal |
50 |
|
*/ |
51 |
|
public void testEquals() { |
52 |
|
ConcurrentHashMap map1 = map5(); |
59 |
|
} |
60 |
|
|
61 |
|
/** |
62 |
< |
* contains returns true for contained value |
62 |
> |
* contains returns true for contained value |
63 |
|
*/ |
64 |
|
public void testContains() { |
65 |
|
ConcurrentHashMap map = map5(); |
68 |
|
} |
69 |
|
|
70 |
|
/** |
71 |
< |
* containsKey returns true for contained key |
71 |
> |
* containsKey returns true for contained key |
72 |
|
*/ |
73 |
|
public void testContainsKey() { |
74 |
|
ConcurrentHashMap map = map5(); |
77 |
|
} |
78 |
|
|
79 |
|
/** |
80 |
< |
* containsValue returns true for held values |
80 |
> |
* containsValue returns true for held values |
81 |
|
*/ |
82 |
|
public void testContainsValue() { |
83 |
|
ConcurrentHashMap map = map5(); |
86 |
|
} |
87 |
|
|
88 |
|
/** |
89 |
< |
* enumeration returns an enumeration containing the correct |
90 |
< |
* elements |
89 |
> |
* enumeration returns an enumeration containing the correct |
90 |
> |
* elements |
91 |
|
*/ |
92 |
|
public void testEnumeration() { |
93 |
|
ConcurrentHashMap map = map5(); |
101 |
|
} |
102 |
|
|
103 |
|
/** |
104 |
< |
* get returns the correct element at the given key, |
105 |
< |
* or null if not present |
104 |
> |
* get returns the correct element at the given key, |
105 |
> |
* or null if not present |
106 |
|
*/ |
107 |
|
public void testGet() { |
108 |
|
ConcurrentHashMap map = map5(); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
115 |
< |
* isEmpty is true of empty map and false for non-empty |
115 |
> |
* isEmpty is true of empty map and false for non-empty |
116 |
|
*/ |
117 |
|
public void testIsEmpty() { |
118 |
|
ConcurrentHashMap empty = new ConcurrentHashMap(); |
122 |
|
} |
123 |
|
|
124 |
|
/** |
125 |
< |
* keys returns an enumeration containing all the keys from the map |
125 |
> |
* keys returns an enumeration containing all the keys from the map |
126 |
|
*/ |
127 |
|
public void testKeys() { |
128 |
|
ConcurrentHashMap map = map5(); |
136 |
|
} |
137 |
|
|
138 |
|
/** |
139 |
< |
* keySet returns a Set containing all the keys |
139 |
> |
* keySet returns a Set containing all the keys |
140 |
|
*/ |
141 |
|
public void testKeySet() { |
142 |
|
ConcurrentHashMap map = map5(); |
150 |
|
} |
151 |
|
|
152 |
|
/** |
153 |
< |
* keySet.toArray returns contains all keys |
153 |
> |
* keySet.toArray returns contains all keys |
154 |
|
*/ |
155 |
|
public void testKeySetToArray() { |
156 |
|
ConcurrentHashMap map = map5(); |
163 |
|
} |
164 |
|
|
165 |
|
/** |
166 |
< |
* Values.toArray contains all values |
166 |
> |
* Values.toArray contains all values |
167 |
|
*/ |
168 |
|
public void testValuesToArray() { |
169 |
|
ConcurrentHashMap map = map5(); |
179 |
|
} |
180 |
|
|
181 |
|
/** |
182 |
< |
* entrySet.toArray contains all entries |
182 |
> |
* entrySet.toArray contains all entries |
183 |
|
*/ |
184 |
|
public void testEntrySetToArray() { |
185 |
|
ConcurrentHashMap map = map5(); |
226 |
|
} |
227 |
|
|
228 |
|
/** |
229 |
< |
* putAll adds all key-value pairs from the given map |
229 |
> |
* putAll adds all key-value pairs from the given map |
230 |
|
*/ |
231 |
|
public void testPutAll() { |
232 |
|
ConcurrentHashMap empty = new ConcurrentHashMap(); |
241 |
|
} |
242 |
|
|
243 |
|
/** |
244 |
< |
* putIfAbsent works when the given key is not present |
244 |
> |
* putIfAbsent works when the given key is not present |
245 |
|
*/ |
246 |
|
public void testPutIfAbsent() { |
247 |
|
ConcurrentHashMap map = map5(); |
250 |
|
} |
251 |
|
|
252 |
|
/** |
253 |
< |
* putIfAbsent does not add the pair if the key is already present |
253 |
> |
* putIfAbsent does not add the pair if the key is already present |
254 |
|
*/ |
255 |
|
public void testPutIfAbsent2() { |
256 |
|
ConcurrentHashMap map = map5(); |
258 |
|
} |
259 |
|
|
260 |
|
/** |
261 |
< |
* replace fails when the given key is not present |
261 |
> |
* replace fails when the given key is not present |
262 |
|
*/ |
263 |
|
public void testReplace() { |
264 |
|
ConcurrentHashMap map = map5(); |
267 |
|
} |
268 |
|
|
269 |
|
/** |
270 |
< |
* replace succeeds if the key is already present |
270 |
> |
* replace succeeds if the key is already present |
271 |
|
*/ |
272 |
|
public void testReplace2() { |
273 |
|
ConcurrentHashMap map = map5(); |
298 |
|
|
299 |
|
|
300 |
|
/** |
301 |
< |
* remove removes the correct key-value pair from the map |
301 |
> |
* remove removes the correct key-value pair from the map |
302 |
|
*/ |
303 |
|
public void testRemove() { |
304 |
|
ConcurrentHashMap map = map5(); |
318 |
|
map.remove(four, "A"); |
319 |
|
assertEquals(4, map.size()); |
320 |
|
assertTrue(map.containsKey(four)); |
321 |
– |
|
321 |
|
} |
322 |
|
|
323 |
|
/** |
324 |
< |
* size returns the correct values |
324 |
> |
* size returns the correct values |
325 |
|
*/ |
326 |
|
public void testSize() { |
327 |
|
ConcurrentHashMap map = map5(); |
350 |
|
try { |
351 |
|
new ConcurrentHashMap(-1,0,1); |
352 |
|
shouldThrow(); |
353 |
< |
} catch (IllegalArgumentException e) {} |
353 |
> |
} catch (IllegalArgumentException success) {} |
354 |
|
} |
355 |
|
|
356 |
|
/** |
360 |
|
try { |
361 |
|
new ConcurrentHashMap(1,0,-1); |
362 |
|
shouldThrow(); |
363 |
< |
} catch (IllegalArgumentException e) {} |
363 |
> |
} catch (IllegalArgumentException success) {} |
364 |
|
} |
365 |
|
|
366 |
|
/** |
370 |
|
try { |
371 |
|
new ConcurrentHashMap(-1); |
372 |
|
shouldThrow(); |
373 |
< |
} catch (IllegalArgumentException e) {} |
373 |
> |
} catch (IllegalArgumentException success) {} |
374 |
|
} |
375 |
|
|
376 |
|
/** |
381 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
382 |
|
c.get(null); |
383 |
|
shouldThrow(); |
384 |
< |
} catch (NullPointerException e) {} |
384 |
> |
} catch (NullPointerException success) {} |
385 |
|
} |
386 |
|
|
387 |
|
/** |
392 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
393 |
|
c.containsKey(null); |
394 |
|
shouldThrow(); |
395 |
< |
} catch (NullPointerException e) {} |
395 |
> |
} catch (NullPointerException success) {} |
396 |
|
} |
397 |
|
|
398 |
|
/** |
403 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
404 |
|
c.containsValue(null); |
405 |
|
shouldThrow(); |
406 |
< |
} catch (NullPointerException e) {} |
406 |
> |
} catch (NullPointerException success) {} |
407 |
|
} |
408 |
|
|
409 |
|
/** |
414 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
415 |
|
c.contains(null); |
416 |
|
shouldThrow(); |
417 |
< |
} catch (NullPointerException e) {} |
417 |
> |
} catch (NullPointerException success) {} |
418 |
|
} |
419 |
|
|
420 |
|
/** |
425 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
426 |
|
c.put(null, "whatever"); |
427 |
|
shouldThrow(); |
428 |
< |
} catch (NullPointerException e) {} |
428 |
> |
} catch (NullPointerException success) {} |
429 |
|
} |
430 |
|
|
431 |
|
/** |
436 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
437 |
|
c.put("whatever", null); |
438 |
|
shouldThrow(); |
439 |
< |
} catch (NullPointerException e) {} |
439 |
> |
} catch (NullPointerException success) {} |
440 |
|
} |
441 |
|
|
442 |
|
/** |
447 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
448 |
|
c.putIfAbsent(null, "whatever"); |
449 |
|
shouldThrow(); |
450 |
< |
} catch (NullPointerException e) {} |
450 |
> |
} catch (NullPointerException success) {} |
451 |
|
} |
452 |
|
|
453 |
|
/** |
458 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
459 |
|
c.replace(null, "whatever"); |
460 |
|
shouldThrow(); |
461 |
< |
} catch (NullPointerException e) {} |
461 |
> |
} catch (NullPointerException success) {} |
462 |
|
} |
463 |
|
|
464 |
|
/** |
469 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
470 |
|
c.replace(null, one, "whatever"); |
471 |
|
shouldThrow(); |
472 |
< |
} catch (NullPointerException e) {} |
472 |
> |
} catch (NullPointerException success) {} |
473 |
|
} |
474 |
|
|
475 |
|
/** |
480 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
481 |
|
c.putIfAbsent("whatever", null); |
482 |
|
shouldThrow(); |
483 |
< |
} catch (NullPointerException e) {} |
483 |
> |
} catch (NullPointerException success) {} |
484 |
|
} |
485 |
|
|
486 |
|
|
492 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
493 |
|
c.replace("whatever", null); |
494 |
|
shouldThrow(); |
495 |
< |
} catch (NullPointerException e) {} |
495 |
> |
} catch (NullPointerException success) {} |
496 |
|
} |
497 |
|
|
498 |
|
/** |
503 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
504 |
|
c.replace("whatever", null, "A"); |
505 |
|
shouldThrow(); |
506 |
< |
} catch (NullPointerException e) {} |
506 |
> |
} catch (NullPointerException success) {} |
507 |
|
} |
508 |
|
|
509 |
|
/** |
514 |
|
ConcurrentHashMap c = new ConcurrentHashMap(5); |
515 |
|
c.replace("whatever", one, null); |
516 |
|
shouldThrow(); |
517 |
< |
} catch (NullPointerException e) {} |
517 |
> |
} catch (NullPointerException success) {} |
518 |
|
} |
519 |
|
|
520 |
|
|
527 |
|
c.put("sadsdf", "asdads"); |
528 |
|
c.remove(null); |
529 |
|
shouldThrow(); |
530 |
< |
} catch (NullPointerException e) {} |
530 |
> |
} catch (NullPointerException success) {} |
531 |
|
} |
532 |
|
|
533 |
|
/** |
539 |
|
c.put("sadsdf", "asdads"); |
540 |
|
c.remove(null, "whatever"); |
541 |
|
shouldThrow(); |
542 |
< |
} catch (NullPointerException e) {} |
542 |
> |
} catch (NullPointerException success) {} |
543 |
|
} |
544 |
|
|
545 |
|
/** |
546 |
|
* remove(x, null) returns false |
547 |
|
*/ |
548 |
|
public void testRemove3() { |
549 |
< |
try { |
550 |
< |
ConcurrentHashMap c = new ConcurrentHashMap(5); |
551 |
< |
c.put("sadsdf", "asdads"); |
553 |
< |
assertFalse(c.remove("sadsdf", null)); |
554 |
< |
} catch (NullPointerException e) { |
555 |
< |
fail(); |
556 |
< |
} |
549 |
> |
ConcurrentHashMap c = new ConcurrentHashMap(5); |
550 |
> |
c.put("sadsdf", "asdads"); |
551 |
> |
assertFalse(c.remove("sadsdf", null)); |
552 |
|
} |
553 |
|
|
554 |
|
/** |