285 |
|
* get returns the correct element at the given key, |
286 |
|
* or null if not present |
287 |
|
*/ |
288 |
+ |
@SuppressWarnings("CollectionIncompatibleType") |
289 |
|
public void testGet() { |
290 |
|
ConcurrentHashMap<Item,String> map = map5(); |
291 |
|
mustEqual("A", map.get(one)); |
292 |
< |
ConcurrentHashMap<Item,String> empty = new ConcurrentHashMap<Item,String>(); |
292 |
> |
ConcurrentHashMap<Item,String> empty = new ConcurrentHashMap<>(); |
293 |
|
assertNull(map.get("anything")); |
294 |
|
assertNull(empty.get("anything")); |
295 |
|
} |
298 |
|
* isEmpty is true of empty map and false for non-empty |
299 |
|
*/ |
300 |
|
public void testIsEmpty() { |
301 |
< |
ConcurrentHashMap<Item,String> empty = new ConcurrentHashMap<Item,String>(); |
301 |
> |
ConcurrentHashMap<Item,String> empty = new ConcurrentHashMap<>(); |
302 |
|
ConcurrentHashMap<Item,String> map = map5(); |
303 |
|
assertTrue(empty.isEmpty()); |
304 |
|
assertFalse(map.isEmpty()); |
367 |
|
ConcurrentHashMap<Item,String> map = map5(); |
368 |
|
Collection<String> v = map.values(); |
369 |
|
String[] ar = v.toArray(new String[0]); |
370 |
< |
ArrayList<String> s = new ArrayList<String>(Arrays.asList(ar)); |
370 |
> |
ArrayList<String> s = new ArrayList<>(Arrays.asList(ar)); |
371 |
|
mustEqual(5, ar.length); |
372 |
|
assertTrue(s.contains("A")); |
373 |
|
assertTrue(s.contains("B")); |
427 |
|
* putAll adds all key-value pairs from the given map |
428 |
|
*/ |
429 |
|
public void testPutAll() { |
430 |
< |
ConcurrentHashMap<Item,String> p = new ConcurrentHashMap<Item,String>(); |
430 |
> |
ConcurrentHashMap<Item,String> p = new ConcurrentHashMap<>(); |
431 |
|
ConcurrentHashMap<Item,String> map = map5(); |
432 |
|
p.putAll(map); |
433 |
|
mustEqual(5, p.size()); |
521 |
|
*/ |
522 |
|
public void testSize() { |
523 |
|
ConcurrentHashMap<Item,String> map = map5(); |
524 |
< |
ConcurrentHashMap<Item,String> empty = new ConcurrentHashMap<Item,String>(); |
524 |
> |
ConcurrentHashMap<Item,String> empty = new ConcurrentHashMap<>(); |
525 |
|
mustEqual(0, empty.size()); |
526 |
|
mustEqual(5, map.size()); |
527 |
|
} |
603 |
|
*/ |
604 |
|
public void testConstructor5() { |
605 |
|
ConcurrentHashMap<Item,String> map1 = map5(); |
606 |
< |
ConcurrentHashMap<Item,String> map2 = new ConcurrentHashMap<Item,String>(map1); |
606 |
> |
ConcurrentHashMap<Item,String> map2 = new ConcurrentHashMap<>(map1); |
607 |
|
assertTrue(map2.equals(map1)); |
608 |
|
map2.put(one, "F"); |
609 |
|
assertFalse(map2.equals(map1)); |
613 |
|
* get(null) throws NPE |
614 |
|
*/ |
615 |
|
public void testGet_NullPointerException() { |
616 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
616 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
617 |
|
try { |
618 |
|
c.get(null); |
619 |
|
shouldThrow(); |
624 |
|
* containsKey(null) throws NPE |
625 |
|
*/ |
626 |
|
public void testContainsKey_NullPointerException() { |
627 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
627 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
628 |
|
try { |
629 |
|
c.containsKey(null); |
630 |
|
shouldThrow(); |
635 |
|
* containsValue(null) throws NPE |
636 |
|
*/ |
637 |
|
public void testContainsValue_NullPointerException() { |
638 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
638 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
639 |
|
try { |
640 |
|
c.containsValue(null); |
641 |
|
shouldThrow(); |
646 |
|
* contains(null) throws NPE |
647 |
|
*/ |
648 |
|
public void testContains_NullPointerException() { |
649 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
649 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
650 |
|
try { |
651 |
|
c.contains(null); |
652 |
|
shouldThrow(); |
657 |
|
* put(null,x) throws NPE |
658 |
|
*/ |
659 |
|
public void testPut1_NullPointerException() { |
660 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
660 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
661 |
|
try { |
662 |
|
c.put(null, "whatever"); |
663 |
|
shouldThrow(); |
668 |
|
* put(x, null) throws NPE |
669 |
|
*/ |
670 |
|
public void testPut2_NullPointerException() { |
671 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
671 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
672 |
|
try { |
673 |
|
c.put(zero, null); |
674 |
|
shouldThrow(); |
679 |
|
* putIfAbsent(null, x) throws NPE |
680 |
|
*/ |
681 |
|
public void testPutIfAbsent1_NullPointerException() { |
682 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
682 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
683 |
|
try { |
684 |
|
c.putIfAbsent(null, "whatever"); |
685 |
|
shouldThrow(); |
690 |
|
* replace(null, x) throws NPE |
691 |
|
*/ |
692 |
|
public void testReplace_NullPointerException() { |
693 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
693 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
694 |
|
try { |
695 |
|
c.replace(null, "whatever"); |
696 |
|
shouldThrow(); |
701 |
|
* replace(null, x, y) throws NPE |
702 |
|
*/ |
703 |
|
public void testReplaceValue_NullPointerException() { |
704 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
704 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
705 |
|
try { |
706 |
|
c.replace(null, "A", "B"); |
707 |
|
shouldThrow(); |
712 |
|
* putIfAbsent(x, null) throws NPE |
713 |
|
*/ |
714 |
|
public void testPutIfAbsent2_NullPointerException() { |
715 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
715 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
716 |
|
try { |
717 |
|
c.putIfAbsent(zero, null); |
718 |
|
shouldThrow(); |
723 |
|
* replace(x, null) throws NPE |
724 |
|
*/ |
725 |
|
public void testReplace2_NullPointerException() { |
726 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
726 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
727 |
|
try { |
728 |
|
c.replace(one, null); |
729 |
|
shouldThrow(); |
734 |
|
* replace(x, null, y) throws NPE |
735 |
|
*/ |
736 |
|
public void testReplaceValue2_NullPointerException() { |
737 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
737 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
738 |
|
try { |
739 |
|
c.replace(one, null, "A"); |
740 |
|
shouldThrow(); |
745 |
|
* replace(x, y, null) throws NPE |
746 |
|
*/ |
747 |
|
public void testReplaceValue3_NullPointerException() { |
748 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
748 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
749 |
|
try { |
750 |
|
c.replace(zero, "A", null); |
751 |
|
shouldThrow(); |
756 |
|
* remove(null) throws NPE |
757 |
|
*/ |
758 |
|
public void testRemove1_NullPointerException() { |
759 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
759 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
760 |
|
c.put(one, "asdads"); |
761 |
|
try { |
762 |
|
c.remove(null); |
768 |
|
* remove(null, x) throws NPE |
769 |
|
*/ |
770 |
|
public void testRemove2_NullPointerException() { |
771 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
771 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
772 |
|
c.put(one, "asdads"); |
773 |
|
try { |
774 |
|
c.remove(null, "whatever"); |
780 |
|
* remove(x, null) returns false |
781 |
|
*/ |
782 |
|
public void testRemove3() { |
783 |
< |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<Item,String>(5); |
783 |
> |
ConcurrentHashMap<Item,String> c = new ConcurrentHashMap<>(5); |
784 |
|
c.put(one, "asdads"); |
785 |
|
assertFalse(c.remove(one, null)); |
786 |
|
} |
804 |
|
@SuppressWarnings("unchecked") |
805 |
|
public void testSetValueWriteThrough() { |
806 |
|
// Adapted from a bug report by Eric Zoerner |
807 |
< |
ConcurrentHashMap<Object,Object> map = new ConcurrentHashMap<Object,Object>(2, 5.0f, 1); |
807 |
> |
ConcurrentHashMap<Object,Object> map = new ConcurrentHashMap<>(2, 5.0f, 1); |
808 |
|
assertTrue(map.isEmpty()); |
809 |
|
for (int i = 0; i < 20; i++) |
810 |
|
map.put(itemFor(i), itemFor(i)); |