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