318 |
|
map.remove(four, "A"); |
319 |
|
assertEquals(4, map.size()); |
320 |
|
assertTrue(map.containsKey(four)); |
321 |
– |
|
321 |
|
} |
322 |
|
|
323 |
|
/** |
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 |
|
/** |
555 |
|
* A deserialized map equals original |
556 |
|
*/ |
557 |
< |
public void testSerialization() { |
557 |
> |
public void testSerialization() throws Exception { |
558 |
|
ConcurrentHashMap q = map5(); |
559 |
|
|
560 |
< |
try { |
561 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
562 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
563 |
< |
out.writeObject(q); |
564 |
< |
out.close(); |
565 |
< |
|
566 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
567 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
568 |
< |
ConcurrentHashMap r = (ConcurrentHashMap)in.readObject(); |
569 |
< |
assertEquals(q.size(), r.size()); |
570 |
< |
assertTrue(q.equals(r)); |
576 |
< |
assertTrue(r.equals(q)); |
577 |
< |
} catch (Exception e) { |
578 |
< |
e.printStackTrace(); |
579 |
< |
unexpectedException(); |
580 |
< |
} |
560 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
561 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
562 |
> |
out.writeObject(q); |
563 |
> |
out.close(); |
564 |
> |
|
565 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
566 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
567 |
> |
ConcurrentHashMap r = (ConcurrentHashMap)in.readObject(); |
568 |
> |
assertEquals(q.size(), r.size()); |
569 |
> |
assertTrue(q.equals(r)); |
570 |
> |
assertTrue(r.equals(q)); |
571 |
|
} |
572 |
|
|
573 |
|
|