516 |
|
assertEquals(two, e.getKey()); |
517 |
|
try { |
518 |
|
e.setValue("X"); |
519 |
< |
fail(); |
519 |
> |
shouldThrow(); |
520 |
|
} catch (UnsupportedOperationException success) {} |
521 |
|
e = map.higherEntry(zero); |
522 |
|
assertEquals(one, e.getKey()); |
523 |
|
try { |
524 |
|
e.setValue("X"); |
525 |
< |
fail(); |
525 |
> |
shouldThrow(); |
526 |
|
} catch (UnsupportedOperationException success) {} |
527 |
|
e = map.floorEntry(one); |
528 |
|
assertEquals(one, e.getKey()); |
529 |
|
try { |
530 |
|
e.setValue("X"); |
531 |
< |
fail(); |
531 |
> |
shouldThrow(); |
532 |
|
} catch (UnsupportedOperationException success) {} |
533 |
|
e = map.ceilingEntry(five); |
534 |
|
assertEquals(five, e.getKey()); |
535 |
|
try { |
536 |
|
e.setValue("X"); |
537 |
< |
fail(); |
537 |
> |
shouldThrow(); |
538 |
|
} catch (UnsupportedOperationException success) {} |
539 |
|
} |
540 |
|
|
638 |
|
try { |
639 |
|
e.setValue("A"); |
640 |
|
shouldThrow(); |
641 |
< |
} catch (Exception ok) { |
642 |
< |
} |
641 |
> |
} catch (UnsupportedOperationException success) {} |
642 |
|
e = map.pollFirstEntry(); |
643 |
|
assertNull(e); |
644 |
|
} |
665 |
|
try { |
666 |
|
e.setValue("E"); |
667 |
|
shouldThrow(); |
668 |
< |
} catch (Exception ok) { |
670 |
< |
} |
668 |
> |
} catch (UnsupportedOperationException success) {} |
669 |
|
e = map.pollLastEntry(); |
670 |
|
assertNull(e); |
671 |
|
} |
701 |
|
ConcurrentSkipListMap c = map5(); |
702 |
|
c.get(null); |
703 |
|
shouldThrow(); |
704 |
< |
} catch (NullPointerException e) {} |
704 |
> |
} catch (NullPointerException success) {} |
705 |
|
} |
706 |
|
|
707 |
|
/** |
712 |
|
ConcurrentSkipListMap c = map5(); |
713 |
|
c.containsKey(null); |
714 |
|
shouldThrow(); |
715 |
< |
} catch (NullPointerException e) {} |
715 |
> |
} catch (NullPointerException success) {} |
716 |
|
} |
717 |
|
|
718 |
|
/** |
723 |
|
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
724 |
|
c.containsValue(null); |
725 |
|
shouldThrow(); |
726 |
< |
} catch (NullPointerException e) {} |
726 |
> |
} catch (NullPointerException success) {} |
727 |
|
} |
728 |
|
|
729 |
|
|
735 |
|
ConcurrentSkipListMap c = map5(); |
736 |
|
c.put(null, "whatever"); |
737 |
|
shouldThrow(); |
738 |
< |
} catch (NullPointerException e) {} |
738 |
> |
} catch (NullPointerException success) {} |
739 |
|
} |
740 |
|
|
741 |
|
/** |
746 |
|
ConcurrentSkipListMap c = map5(); |
747 |
|
c.putIfAbsent(null, "whatever"); |
748 |
|
shouldThrow(); |
749 |
< |
} catch (NullPointerException e) {} |
749 |
> |
} catch (NullPointerException success) {} |
750 |
|
} |
751 |
|
|
752 |
|
/** |
757 |
|
ConcurrentSkipListMap c = map5(); |
758 |
|
c.replace(null, "whatever"); |
759 |
|
shouldThrow(); |
760 |
< |
} catch (NullPointerException e) {} |
760 |
> |
} catch (NullPointerException success) {} |
761 |
|
} |
762 |
|
|
763 |
|
/** |
768 |
|
ConcurrentSkipListMap c = map5(); |
769 |
|
c.replace(null, one, "whatever"); |
770 |
|
shouldThrow(); |
771 |
< |
} catch (NullPointerException e) {} |
771 |
> |
} catch (NullPointerException success) {} |
772 |
|
} |
773 |
|
|
774 |
|
/** |
780 |
|
c.put("sadsdf", "asdads"); |
781 |
|
c.remove(null); |
782 |
|
shouldThrow(); |
783 |
< |
} catch (NullPointerException e) {} |
783 |
> |
} catch (NullPointerException success) {} |
784 |
|
} |
785 |
|
|
786 |
|
/** |
792 |
|
c.put("sadsdf", "asdads"); |
793 |
|
c.remove(null, "whatever"); |
794 |
|
shouldThrow(); |
795 |
< |
} catch (NullPointerException e) {} |
795 |
> |
} catch (NullPointerException success) {} |
796 |
|
} |
797 |
|
|
798 |
|
/** |
799 |
|
* remove(x, null) returns false |
800 |
|
*/ |
801 |
|
public void testRemove3() { |
802 |
< |
try { |
803 |
< |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
804 |
< |
c.put("sadsdf", "asdads"); |
807 |
< |
assertFalse(c.remove("sadsdf", null)); |
808 |
< |
} catch (NullPointerException e) { |
809 |
< |
fail(); |
810 |
< |
} |
802 |
> |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
803 |
> |
c.put("sadsdf", "asdads"); |
804 |
> |
assertFalse(c.remove("sadsdf", null)); |
805 |
|
} |
806 |
|
|
807 |
|
/** |
808 |
|
* A deserialized map equals original |
809 |
|
*/ |
810 |
< |
public void testSerialization() { |
810 |
> |
public void testSerialization() throws Exception { |
811 |
|
ConcurrentSkipListMap q = map5(); |
812 |
|
|
813 |
< |
try { |
814 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
815 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
816 |
< |
out.writeObject(q); |
817 |
< |
out.close(); |
818 |
< |
|
819 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
820 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
821 |
< |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
822 |
< |
assertEquals(q.size(), r.size()); |
823 |
< |
assertTrue(q.equals(r)); |
830 |
< |
assertTrue(r.equals(q)); |
831 |
< |
} catch (Exception e) { |
832 |
< |
e.printStackTrace(); |
833 |
< |
unexpectedException(); |
834 |
< |
} |
813 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
814 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
815 |
> |
out.writeObject(q); |
816 |
> |
out.close(); |
817 |
> |
|
818 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
819 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
820 |
> |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
821 |
> |
assertEquals(q.size(), r.size()); |
822 |
> |
assertTrue(q.equals(r)); |
823 |
> |
assertTrue(r.equals(q)); |
824 |
|
} |
825 |
|
|
826 |
|
|
861 |
|
assertEquals(1, sm.size()); |
862 |
|
assertEquals(three, sm.firstKey()); |
863 |
|
assertEquals(three, sm.lastKey()); |
864 |
< |
assertTrue(sm.remove(three) != null); |
864 |
> |
assertEquals("C", sm.remove(three)); |
865 |
|
assertTrue(sm.isEmpty()); |
866 |
|
assertEquals(3, map.size()); |
867 |
|
} |
894 |
|
assertEquals(4, map.size()); |
895 |
|
assertEquals(0, sm.size()); |
896 |
|
assertTrue(sm.isEmpty()); |
897 |
< |
assertTrue(sm.remove(three) == null); |
897 |
> |
assertSame(sm.remove(three), null); |
898 |
|
assertEquals(4, map.size()); |
899 |
|
} |
900 |
|
|
976 |
|
NavigableMap ssm = sm.tailMap(four, true); |
977 |
|
assertEquals(four, ssm.firstKey()); |
978 |
|
assertEquals(five, ssm.lastKey()); |
979 |
< |
assertTrue(ssm.remove(four) != null); |
979 |
> |
assertEquals("D", ssm.remove(four)); |
980 |
|
assertEquals(1, ssm.size()); |
981 |
|
assertEquals(3, sm.size()); |
982 |
|
assertEquals(4, map.size()); |
988 |
|
/** |
989 |
|
* Submaps of submaps subdivide correctly |
990 |
|
*/ |
991 |
< |
public void testRecursiveSubMaps() { |
991 |
> |
public void testRecursiveSubMaps() throws Exception { |
992 |
|
int mapSize = 1000; |
993 |
|
Class cl = ConcurrentSkipListMap.class; |
994 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
1006 |
|
0, mapSize - 1, true); |
1007 |
|
} |
1008 |
|
|
1009 |
< |
static NavigableMap<Integer, Integer> newMap(Class cl) { |
1010 |
< |
NavigableMap<Integer, Integer> result = null; |
1011 |
< |
try { |
1023 |
< |
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
1024 |
< |
} catch (Exception e) { |
1025 |
< |
fail(); |
1026 |
< |
} |
1009 |
> |
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
1010 |
> |
NavigableMap<Integer, Integer> result = |
1011 |
> |
(NavigableMap<Integer, Integer>) cl.newInstance(); |
1012 |
|
assertEquals(result.size(), 0); |
1013 |
|
assertFalse(result.keySet().iterator().hasNext()); |
1014 |
|
return result; |
1071 |
|
} else { |
1072 |
|
try { |
1073 |
|
map.put(key, 2 * key); |
1074 |
< |
fail(); |
1075 |
< |
} catch (IllegalArgumentException e) { |
1091 |
< |
// expected |
1092 |
< |
} |
1074 |
> |
shouldThrow(); |
1075 |
> |
} catch (IllegalArgumentException success) {} |
1076 |
|
} |
1077 |
|
} |
1078 |
|
} |
1267 |
|
assertEq(rs.last(), -1); |
1268 |
|
try { |
1269 |
|
map.firstKey(); |
1270 |
< |
fail(); |
1271 |
< |
} catch (NoSuchElementException e) { |
1289 |
< |
// expected |
1290 |
< |
} |
1270 |
> |
shouldThrow(); |
1271 |
> |
} catch (NoSuchElementException success) {} |
1272 |
|
try { |
1273 |
|
map.lastKey(); |
1274 |
< |
fail(); |
1275 |
< |
} catch (NoSuchElementException e) { |
1295 |
< |
// expected |
1296 |
< |
} |
1274 |
> |
shouldThrow(); |
1275 |
> |
} catch (NoSuchElementException success) {} |
1276 |
|
} |
1277 |
|
} |
1278 |
|
|