ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java (file contents):
Revision 1.9 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.24 by jsr166, Wed Dec 31 19:05:42 2014 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
8 < import java.util.*;
9 < import java.util.concurrent.*;
10 < import java.io.*;
7 > import java.util.ArrayList;
8 > import java.util.Arrays;
9 > import java.util.Collection;
10 > import java.util.Iterator;
11 > import java.util.Map;
12 > import java.util.NavigableMap;
13 > import java.util.Set;
14 > import java.util.SortedMap;
15 > import java.util.concurrent.ConcurrentNavigableMap;
16 > import java.util.concurrent.ConcurrentSkipListMap;
17 >
18 > import junit.framework.Test;
19 > import junit.framework.TestSuite;
20  
21   public class ConcurrentSkipListSubMapTest extends JSR166TestCase {
22      public static void main(String[] args) {
23 <        junit.textui.TestRunner.run (suite());
23 >        junit.textui.TestRunner.run(suite());
24      }
25      public static Test suite() {
26          return new TestSuite(ConcurrentSkipListSubMapTest.class);
27      }
28  
29      /**
30 <     * Create a map from Integers 1-5 to Strings "A"-"E".
30 >     * Returns a new map from Integers 1-5 to Strings "A"-"E".
31       */
32      private static ConcurrentNavigableMap map5() {
33          ConcurrentSkipListMap map = new ConcurrentSkipListMap();
# Line 36 | Line 45 | public class ConcurrentSkipListSubMapTes
45      }
46  
47      /**
48 <     * Create a map from Integers -5 to -1 to Strings "A"-"E".
48 >     * Returns a new map from Integers -5 to -1 to Strings "A"-"E".
49       */
50      private static ConcurrentNavigableMap dmap5() {
51          ConcurrentSkipListMap map = new ConcurrentSkipListMap();
# Line 64 | Line 73 | public class ConcurrentSkipListSubMapTes
73      }
74  
75      /**
76 <     *  clear removes all pairs
76 >     * clear removes all pairs
77       */
78      public void testClear() {
79          ConcurrentNavigableMap map = map5();
80          map.clear();
81 <        assertEquals(map.size(), 0);
81 >        assertEquals(0, map.size());
82      }
83  
75
84      /**
85 <     *  Maps with same contents are equal
85 >     * Maps with same contents are equal
86       */
87      public void testEquals() {
88          ConcurrentNavigableMap map1 = map5();
# Line 87 | Line 95 | public class ConcurrentSkipListSubMapTes
95      }
96  
97      /**
98 <     *  containsKey returns true for contained key
98 >     * containsKey returns true for contained key
99       */
100      public void testContainsKey() {
101          ConcurrentNavigableMap map = map5();
# Line 96 | Line 104 | public class ConcurrentSkipListSubMapTes
104      }
105  
106      /**
107 <     *  containsValue returns true for held values
107 >     * containsValue returns true for held values
108       */
109      public void testContainsValue() {
110          ConcurrentNavigableMap map = map5();
# Line 105 | Line 113 | public class ConcurrentSkipListSubMapTes
113      }
114  
115      /**
116 <     *  get returns the correct element at the given key,
117 <     *  or null if not present
116 >     * get returns the correct element at the given key,
117 >     * or null if not present
118       */
119      public void testGet() {
120          ConcurrentNavigableMap map = map5();
# Line 116 | Line 124 | public class ConcurrentSkipListSubMapTes
124      }
125  
126      /**
127 <     *  isEmpty is true of empty map and false for non-empty
127 >     * isEmpty is true of empty map and false for non-empty
128       */
129      public void testIsEmpty() {
130          ConcurrentNavigableMap empty = map0();
# Line 126 | Line 134 | public class ConcurrentSkipListSubMapTes
134      }
135  
136      /**
137 <     *   firstKey returns first key
137 >     * firstKey returns first key
138       */
139      public void testFirstKey() {
140          ConcurrentNavigableMap map = map5();
# Line 134 | Line 142 | public class ConcurrentSkipListSubMapTes
142      }
143  
144      /**
145 <     *   lastKey returns last key
145 >     * lastKey returns last key
146       */
147      public void testLastKey() {
148          ConcurrentNavigableMap map = map5();
149          assertEquals(five, map.lastKey());
150      }
151  
144
152      /**
153 <     *   keySet returns a Set containing all the keys
153 >     * keySet returns a Set containing all the keys
154       */
155      public void testKeySet() {
156          ConcurrentNavigableMap map = map5();
# Line 157 | Line 164 | public class ConcurrentSkipListSubMapTes
164      }
165  
166      /**
167 <     *   keySet is ordered
167 >     * keySet is ordered
168       */
169      public void testKeySetOrder() {
170          ConcurrentNavigableMap map = map5();
# Line 187 | Line 194 | public class ConcurrentSkipListSubMapTes
194      }
195  
196      /**
197 <     *  keySet.toArray returns contains all keys
197 >     * keySet.toArray returns contains all keys
198       */
199      public void testKeySetToArray() {
200          ConcurrentNavigableMap map = map5();
# Line 200 | Line 207 | public class ConcurrentSkipListSubMapTes
207      }
208  
209      /**
210 <     *  descendingkeySet.toArray returns contains all keys
210 >     * descendingkeySet.toArray returns contains all keys
211       */
212      public void testDescendingKeySetToArray() {
213          ConcurrentNavigableMap map = map5();
# Line 213 | Line 220 | public class ConcurrentSkipListSubMapTes
220      }
221  
222      /**
223 <     *  Values.toArray contains all values
223 >     * Values.toArray contains all values
224       */
225      public void testValuesToArray() {
226          ConcurrentNavigableMap map = map5();
# Line 228 | Line 235 | public class ConcurrentSkipListSubMapTes
235          assertTrue(s.contains("E"));
236      }
237  
231
238      /**
239       * entrySet contains all pairs
240       */
# Line 249 | Line 255 | public class ConcurrentSkipListSubMapTes
255      }
256  
257      /**
258 <     *   putAll  adds all key-value pairs from the given map
258 >     * putAll adds all key-value pairs from the given map
259       */
260      public void testPutAll() {
261          ConcurrentNavigableMap empty = map0();
# Line 264 | Line 270 | public class ConcurrentSkipListSubMapTes
270      }
271  
272      /**
273 <     *   putIfAbsent works when the given key is not present
273 >     * putIfAbsent works when the given key is not present
274       */
275      public void testPutIfAbsent() {
276          ConcurrentNavigableMap map = map5();
# Line 273 | Line 279 | public class ConcurrentSkipListSubMapTes
279      }
280  
281      /**
282 <     *   putIfAbsent does not add the pair if the key is already present
282 >     * putIfAbsent does not add the pair if the key is already present
283       */
284      public void testPutIfAbsent2() {
285          ConcurrentNavigableMap map = map5();
# Line 281 | Line 287 | public class ConcurrentSkipListSubMapTes
287      }
288  
289      /**
290 <     *   replace fails when the given key is not present
290 >     * replace fails when the given key is not present
291       */
292      public void testReplace() {
293          ConcurrentNavigableMap map = map5();
# Line 290 | Line 296 | public class ConcurrentSkipListSubMapTes
296      }
297  
298      /**
299 <     *   replace succeeds if the key is already present
299 >     * replace succeeds if the key is already present
300       */
301      public void testReplace2() {
302          ConcurrentNavigableMap map = map5();
# Line 298 | Line 304 | public class ConcurrentSkipListSubMapTes
304          assertEquals("Z", map.get(one));
305      }
306  
301
307      /**
308       * replace value fails when the given key not mapped to expected value
309       */
# Line 319 | Line 324 | public class ConcurrentSkipListSubMapTes
324          assertEquals("Z", map.get(one));
325      }
326  
322
327      /**
328 <     *   remove removes the correct key-value pair from the map
328 >     * remove removes the correct key-value pair from the map
329       */
330      public void testRemove() {
331          ConcurrentNavigableMap map = map5();
# Line 343 | Line 347 | public class ConcurrentSkipListSubMapTes
347          map.remove(four, "A");
348          assertEquals(4, map.size());
349          assertTrue(map.containsKey(four));
346
350      }
351  
352      /**
# Line 362 | Line 365 | public class ConcurrentSkipListSubMapTes
365  
366          Map.Entry e4 = map.lowerEntry(zero);
367          assertNull(e4);
365
368      }
369  
370      /**
# Line 381 | Line 383 | public class ConcurrentSkipListSubMapTes
383  
384          Map.Entry e4 = map.higherEntry(six);
385          assertNull(e4);
384
386      }
387  
388      /**
# Line 400 | Line 401 | public class ConcurrentSkipListSubMapTes
401  
402          Map.Entry e4 = map.floorEntry(zero);
403          assertNull(e4);
403
404      }
405  
406      /**
# Line 419 | Line 419 | public class ConcurrentSkipListSubMapTes
419  
420          Map.Entry e4 = map.ceilingEntry(six);
421          assertNull(e4);
422
422      }
423  
424      /**
# Line 444 | Line 443 | public class ConcurrentSkipListSubMapTes
443          try {
444              e.setValue("A");
445              shouldThrow();
446 <        } catch (Exception ok) {
448 <        }
446 >        } catch (UnsupportedOperationException success) {}
447          e = map.pollFirstEntry();
448          assertNull(e);
449      }
# Line 472 | Line 470 | public class ConcurrentSkipListSubMapTes
470          try {
471              e.setValue("E");
472              shouldThrow();
473 <        } catch (Exception ok) {
476 <        }
473 >        } catch (UnsupportedOperationException success) {}
474          e = map.pollLastEntry();
475          assertNull(e);
476      }
477  
478      /**
479 <     *   size returns the correct values
479 >     * size returns the correct values
480       */
481      public void testSize() {
482          ConcurrentNavigableMap map = map5();
# Line 495 | Line 492 | public class ConcurrentSkipListSubMapTes
492          ConcurrentNavigableMap map = map5();
493          String s = map.toString();
494          for (int i = 1; i <= 5; ++i) {
495 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
495 >            assertTrue(s.contains(String.valueOf(i)));
496          }
497      }
498  
# Line 509 | Line 506 | public class ConcurrentSkipListSubMapTes
506              ConcurrentNavigableMap c = map5();
507              c.get(null);
508              shouldThrow();
509 <        } catch (NullPointerException e) {}
509 >        } catch (NullPointerException success) {}
510      }
511  
512      /**
# Line 520 | Line 517 | public class ConcurrentSkipListSubMapTes
517              ConcurrentNavigableMap c = map5();
518              c.containsKey(null);
519              shouldThrow();
520 <        } catch (NullPointerException e) {}
520 >        } catch (NullPointerException success) {}
521      }
522  
523      /**
# Line 531 | Line 528 | public class ConcurrentSkipListSubMapTes
528              ConcurrentNavigableMap c = map0();
529              c.containsValue(null);
530              shouldThrow();
531 <        } catch (NullPointerException e) {}
531 >        } catch (NullPointerException success) {}
532      }
533  
537
534      /**
535       * put(null,x) throws NPE
536       */
# Line 543 | Line 539 | public class ConcurrentSkipListSubMapTes
539              ConcurrentNavigableMap c = map5();
540              c.put(null, "whatever");
541              shouldThrow();
542 <        } catch (NullPointerException e) {}
542 >        } catch (NullPointerException success) {}
543      }
544  
545      /**
# Line 554 | Line 550 | public class ConcurrentSkipListSubMapTes
550              ConcurrentNavigableMap c = map5();
551              c.putIfAbsent(null, "whatever");
552              shouldThrow();
553 <        } catch (NullPointerException e) {}
553 >        } catch (NullPointerException success) {}
554      }
555  
556      /**
# Line 565 | Line 561 | public class ConcurrentSkipListSubMapTes
561              ConcurrentNavigableMap c = map5();
562              c.replace(null, "whatever");
563              shouldThrow();
564 <        } catch (NullPointerException e) {}
564 >        } catch (NullPointerException success) {}
565      }
566  
567      /**
# Line 576 | Line 572 | public class ConcurrentSkipListSubMapTes
572              ConcurrentNavigableMap c = map5();
573              c.replace(null, one, "whatever");
574              shouldThrow();
575 <        } catch (NullPointerException e) {}
575 >        } catch (NullPointerException success) {}
576      }
577  
578      /**
# Line 587 | Line 583 | public class ConcurrentSkipListSubMapTes
583              ConcurrentNavigableMap c = map5();
584              c.remove(null);
585              shouldThrow();
586 <        } catch (NullPointerException e) {}
586 >        } catch (NullPointerException success) {}
587      }
588  
589      /**
# Line 598 | Line 594 | public class ConcurrentSkipListSubMapTes
594              ConcurrentNavigableMap c = map5();
595              c.remove(null, "whatever");
596              shouldThrow();
597 <        } catch (NullPointerException e) {}
597 >        } catch (NullPointerException success) {}
598      }
599  
600      /**
601       * A deserialized map equals original
602       */
603 <    public void testSerialization() {
604 <        ConcurrentNavigableMap q = map5();
605 <
606 <        try {
607 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
608 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
609 <            out.writeObject(q);
610 <            out.close();
611 <
616 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
617 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
618 <            ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject();
619 <            assertEquals(q.size(), r.size());
620 <            assertTrue(q.equals(r));
621 <            assertTrue(r.equals(q));
622 <        } catch (Exception e) {
623 <            e.printStackTrace();
624 <            unexpectedException();
625 <        }
603 >    public void testSerialization() throws Exception {
604 >        NavigableMap x = map5();
605 >        NavigableMap y = serialClone(x);
606 >
607 >        assertNotSame(x, y);
608 >        assertEquals(x.size(), y.size());
609 >        assertEquals(x.toString(), y.toString());
610 >        assertEquals(x, y);
611 >        assertEquals(y, x);
612      }
613  
628
629
614      /**
615       * subMap returns map with keys in requested range
616       */
# Line 656 | Line 640 | public class ConcurrentSkipListSubMapTes
640          assertEquals(1, sm.size());
641          assertEquals(three, sm.firstKey());
642          assertEquals(three, sm.lastKey());
643 <        assertTrue(sm.remove(three) != null);
643 >        assertEquals("C", sm.remove(three));
644          assertTrue(sm.isEmpty());
645          assertEquals(3, map.size());
646      }
# Line 684 | Line 668 | public class ConcurrentSkipListSubMapTes
668          assertEquals(4, map.size());
669          assertEquals(0, sm.size());
670          assertTrue(sm.isEmpty());
671 <        assertTrue(sm.remove(three) == null);
671 >        assertSame(sm.remove(three), null);
672          assertEquals(4, map.size());
673      }
674  
# Line 756 | Line 740 | public class ConcurrentSkipListSubMapTes
740          SortedMap ssm = sm.tailMap(four);
741          assertEquals(four, ssm.firstKey());
742          assertEquals(five, ssm.lastKey());
743 <        assertTrue(ssm.remove(four) != null);
743 >        assertEquals("D", ssm.remove(four));
744          assertEquals(1, ssm.size());
745          assertEquals(3, sm.size());
746          assertEquals(4, map.size());
747      }
748  
749      /**
750 <     *  clear removes all pairs
750 >     * clear removes all pairs
751       */
752      public void testDescendingClear() {
753          ConcurrentNavigableMap map = dmap5();
754          map.clear();
755 <        assertEquals(map.size(), 0);
755 >        assertEquals(0, map.size());
756      }
757  
774
758      /**
759 <     *  Maps with same contents are equal
759 >     * Maps with same contents are equal
760       */
761      public void testDescendingEquals() {
762          ConcurrentNavigableMap map1 = dmap5();
# Line 786 | Line 769 | public class ConcurrentSkipListSubMapTes
769      }
770  
771      /**
772 <     *  containsKey returns true for contained key
772 >     * containsKey returns true for contained key
773       */
774      public void testDescendingContainsKey() {
775          ConcurrentNavigableMap map = dmap5();
# Line 795 | Line 778 | public class ConcurrentSkipListSubMapTes
778      }
779  
780      /**
781 <     *  containsValue returns true for held values
781 >     * containsValue returns true for held values
782       */
783      public void testDescendingContainsValue() {
784          ConcurrentNavigableMap map = dmap5();
# Line 804 | Line 787 | public class ConcurrentSkipListSubMapTes
787      }
788  
789      /**
790 <     *  get returns the correct element at the given key,
791 <     *  or null if not present
790 >     * get returns the correct element at the given key,
791 >     * or null if not present
792       */
793      public void testDescendingGet() {
794          ConcurrentNavigableMap map = dmap5();
# Line 815 | Line 798 | public class ConcurrentSkipListSubMapTes
798      }
799  
800      /**
801 <     *  isEmpty is true of empty map and false for non-empty
801 >     * isEmpty is true of empty map and false for non-empty
802       */
803      public void testDescendingIsEmpty() {
804          ConcurrentNavigableMap empty = dmap0();
# Line 825 | Line 808 | public class ConcurrentSkipListSubMapTes
808      }
809  
810      /**
811 <     *   firstKey returns first key
811 >     * firstKey returns first key
812       */
813      public void testDescendingFirstKey() {
814          ConcurrentNavigableMap map = dmap5();
# Line 833 | Line 816 | public class ConcurrentSkipListSubMapTes
816      }
817  
818      /**
819 <     *   lastKey returns last key
819 >     * lastKey returns last key
820       */
821      public void testDescendingLastKey() {
822          ConcurrentNavigableMap map = dmap5();
823          assertEquals(m5, map.lastKey());
824      }
825  
843
826      /**
827 <     *   keySet returns a Set containing all the keys
827 >     * keySet returns a Set containing all the keys
828       */
829      public void testDescendingKeySet() {
830          ConcurrentNavigableMap map = dmap5();
# Line 856 | Line 838 | public class ConcurrentSkipListSubMapTes
838      }
839  
840      /**
841 <     *   keySet is ordered
841 >     * keySet is ordered
842       */
843      public void testDescendingKeySetOrder() {
844          ConcurrentNavigableMap map = dmap5();
# Line 886 | Line 868 | public class ConcurrentSkipListSubMapTes
868      }
869  
870      /**
871 <     *  keySet.toArray returns contains all keys
871 >     * keySet.toArray returns contains all keys
872       */
873      public void testDescendingAscendingKeySetToArray() {
874          ConcurrentNavigableMap map = dmap5();
# Line 899 | Line 881 | public class ConcurrentSkipListSubMapTes
881      }
882  
883      /**
884 <     *  descendingkeySet.toArray returns contains all keys
884 >     * descendingkeySet.toArray returns contains all keys
885       */
886      public void testDescendingDescendingKeySetToArray() {
887          ConcurrentNavigableMap map = dmap5();
# Line 912 | Line 894 | public class ConcurrentSkipListSubMapTes
894      }
895  
896      /**
897 <     *  Values.toArray contains all values
897 >     * Values.toArray contains all values
898       */
899      public void testDescendingValuesToArray() {
900          ConcurrentNavigableMap map = dmap5();
# Line 927 | Line 909 | public class ConcurrentSkipListSubMapTes
909          assertTrue(s.contains("E"));
910      }
911  
930
912      /**
913       * entrySet contains all pairs
914       */
# Line 948 | Line 929 | public class ConcurrentSkipListSubMapTes
929      }
930  
931      /**
932 <     *   putAll  adds all key-value pairs from the given map
932 >     * putAll adds all key-value pairs from the given map
933       */
934      public void testDescendingPutAll() {
935          ConcurrentNavigableMap empty = dmap0();
# Line 963 | Line 944 | public class ConcurrentSkipListSubMapTes
944      }
945  
946      /**
947 <     *   putIfAbsent works when the given key is not present
947 >     * putIfAbsent works when the given key is not present
948       */
949      public void testDescendingPutIfAbsent() {
950          ConcurrentNavigableMap map = dmap5();
# Line 972 | Line 953 | public class ConcurrentSkipListSubMapTes
953      }
954  
955      /**
956 <     *   putIfAbsent does not add the pair if the key is already present
956 >     * putIfAbsent does not add the pair if the key is already present
957       */
958      public void testDescendingPutIfAbsent2() {
959          ConcurrentNavigableMap map = dmap5();
# Line 980 | Line 961 | public class ConcurrentSkipListSubMapTes
961      }
962  
963      /**
964 <     *   replace fails when the given key is not present
964 >     * replace fails when the given key is not present
965       */
966      public void testDescendingReplace() {
967          ConcurrentNavigableMap map = dmap5();
# Line 989 | Line 970 | public class ConcurrentSkipListSubMapTes
970      }
971  
972      /**
973 <     *   replace succeeds if the key is already present
973 >     * replace succeeds if the key is already present
974       */
975      public void testDescendingReplace2() {
976          ConcurrentNavigableMap map = dmap5();
# Line 997 | Line 978 | public class ConcurrentSkipListSubMapTes
978          assertEquals("Z", map.get(m1));
979      }
980  
1000
981      /**
982       * replace value fails when the given key not mapped to expected value
983       */
# Line 1018 | Line 998 | public class ConcurrentSkipListSubMapTes
998          assertEquals("Z", map.get(m1));
999      }
1000  
1021
1001      /**
1002 <     *   remove removes the correct key-value pair from the map
1002 >     * remove removes the correct key-value pair from the map
1003       */
1004      public void testDescendingRemove() {
1005          ConcurrentNavigableMap map = dmap5();
# Line 1042 | Line 1021 | public class ConcurrentSkipListSubMapTes
1021          map.remove(m4, "A");
1022          assertEquals(4, map.size());
1023          assertTrue(map.containsKey(m4));
1045
1024      }
1025  
1026      /**
# Line 1061 | Line 1039 | public class ConcurrentSkipListSubMapTes
1039  
1040          Map.Entry e4 = map.lowerEntry(zero);
1041          assertNull(e4);
1064
1042      }
1043  
1044      /**
# Line 1080 | Line 1057 | public class ConcurrentSkipListSubMapTes
1057  
1058          Map.Entry e4 = map.higherEntry(m6);
1059          assertNull(e4);
1083
1060      }
1061  
1062      /**
# Line 1099 | Line 1075 | public class ConcurrentSkipListSubMapTes
1075  
1076          Map.Entry e4 = map.floorEntry(zero);
1077          assertNull(e4);
1102
1078      }
1079  
1080      /**
# Line 1118 | Line 1093 | public class ConcurrentSkipListSubMapTes
1093  
1094          Map.Entry e4 = map.ceilingEntry(m6);
1095          assertNull(e4);
1121
1096      }
1097  
1098      /**
# Line 1143 | Line 1117 | public class ConcurrentSkipListSubMapTes
1117          try {
1118              e.setValue("A");
1119              shouldThrow();
1120 <        } catch (Exception ok) {
1147 <        }
1120 >        } catch (UnsupportedOperationException success) {}
1121          e = map.pollFirstEntry();
1122          assertNull(e);
1123      }
# Line 1171 | Line 1144 | public class ConcurrentSkipListSubMapTes
1144          try {
1145              e.setValue("E");
1146              shouldThrow();
1147 <        } catch (Exception ok) {
1175 <        }
1147 >        } catch (UnsupportedOperationException success) {}
1148          e = map.pollLastEntry();
1149          assertNull(e);
1150      }
1151  
1152      /**
1153 <     *   size returns the correct values
1153 >     * size returns the correct values
1154       */
1155      public void testDescendingSize() {
1156          ConcurrentNavigableMap map = dmap5();
# Line 1194 | Line 1166 | public class ConcurrentSkipListSubMapTes
1166          ConcurrentNavigableMap map = dmap5();
1167          String s = map.toString();
1168          for (int i = 1; i <= 5; ++i) {
1169 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
1169 >            assertTrue(s.contains(String.valueOf(i)));
1170          }
1171      }
1172  
1173      // Exception testDescendings
1174  
1175      /**
1176 <     * get(null) of nm1mpty map throws NPE
1176 >     * get(null) of empty map throws NPE
1177       */
1178      public void testDescendingGet_NullPointerException() {
1179          try {
1180              ConcurrentNavigableMap c = dmap5();
1181              c.get(null);
1182              shouldThrow();
1183 <        } catch (NullPointerException e) {}
1183 >        } catch (NullPointerException success) {}
1184      }
1185  
1186      /**
1187 <     * containsKey(null) of nm1mpty map throws NPE
1187 >     * containsKey(null) of empty map throws NPE
1188       */
1189      public void testDescendingContainsKey_NullPointerException() {
1190          try {
1191              ConcurrentNavigableMap c = dmap5();
1192              c.containsKey(null);
1193              shouldThrow();
1194 <        } catch (NullPointerException e) {}
1194 >        } catch (NullPointerException success) {}
1195      }
1196  
1197      /**
# Line 1230 | Line 1202 | public class ConcurrentSkipListSubMapTes
1202              ConcurrentNavigableMap c = dmap0();
1203              c.containsValue(null);
1204              shouldThrow();
1205 <        } catch (NullPointerException e) {}
1205 >        } catch (NullPointerException success) {}
1206      }
1207  
1236
1208      /**
1209       * put(null,x) throws NPE
1210       */
# Line 1242 | Line 1213 | public class ConcurrentSkipListSubMapTes
1213              ConcurrentNavigableMap c = dmap5();
1214              c.put(null, "whatever");
1215              shouldThrow();
1216 <        } catch (NullPointerException e) {}
1216 >        } catch (NullPointerException success) {}
1217      }
1218  
1219      /**
# Line 1253 | Line 1224 | public class ConcurrentSkipListSubMapTes
1224              ConcurrentNavigableMap c = dmap5();
1225              c.putIfAbsent(null, "whatever");
1226              shouldThrow();
1227 <        } catch (NullPointerException e) {}
1227 >        } catch (NullPointerException success) {}
1228      }
1229  
1230      /**
# Line 1264 | Line 1235 | public class ConcurrentSkipListSubMapTes
1235              ConcurrentNavigableMap c = dmap5();
1236              c.replace(null, "whatever");
1237              shouldThrow();
1238 <        } catch (NullPointerException e) {}
1238 >        } catch (NullPointerException success) {}
1239      }
1240  
1241      /**
# Line 1275 | Line 1246 | public class ConcurrentSkipListSubMapTes
1246              ConcurrentNavigableMap c = dmap5();
1247              c.replace(null, m1, "whatever");
1248              shouldThrow();
1249 <        } catch (NullPointerException e) {}
1249 >        } catch (NullPointerException success) {}
1250      }
1251  
1252      /**
# Line 1286 | Line 1257 | public class ConcurrentSkipListSubMapTes
1257              ConcurrentNavigableMap c = dmap5();
1258              c.remove(null);
1259              shouldThrow();
1260 <        } catch (NullPointerException e) {}
1260 >        } catch (NullPointerException success) {}
1261      }
1262  
1263      /**
# Line 1297 | Line 1268 | public class ConcurrentSkipListSubMapTes
1268              ConcurrentNavigableMap c = dmap5();
1269              c.remove(null, "whatever");
1270              shouldThrow();
1271 <        } catch (NullPointerException e) {}
1271 >        } catch (NullPointerException success) {}
1272      }
1273  
1274      /**
1275       * A deserialized map equals original
1276       */
1277 <    public void testDescendingSerialization() {
1278 <        ConcurrentNavigableMap q = dmap5();
1279 <
1280 <        try {
1281 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1282 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1283 <            out.writeObject(q);
1284 <            out.close();
1285 <
1315 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1316 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1317 <            ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject();
1318 <            assertEquals(q.size(), r.size());
1319 <            assertTrue(q.equals(r));
1320 <            assertTrue(r.equals(q));
1321 <        } catch (Exception e) {
1322 <            e.printStackTrace();
1323 <            unexpectedException();
1324 <        }
1277 >    public void testDescendingSerialization() throws Exception {
1278 >        NavigableMap x = dmap5();
1279 >        NavigableMap y = serialClone(x);
1280 >
1281 >        assertNotSame(x, y);
1282 >        assertEquals(x.size(), y.size());
1283 >        assertEquals(x.toString(), y.toString());
1284 >        assertEquals(x, y);
1285 >        assertEquals(y, x);
1286      }
1287  
1327
1328
1288      /**
1289       * subMap returns map with keys in requested range
1290       */
# Line 1355 | Line 1314 | public class ConcurrentSkipListSubMapTes
1314          assertEquals(1, sm.size());
1315          assertEquals(m3, sm.firstKey());
1316          assertEquals(m3, sm.lastKey());
1317 <        assertTrue(sm.remove(m3) != null);
1317 >        assertEquals("C", sm.remove(m3));
1318          assertTrue(sm.isEmpty());
1319          assertEquals(3, map.size());
1320      }
# Line 1383 | Line 1342 | public class ConcurrentSkipListSubMapTes
1342          assertEquals(4, map.size());
1343          assertEquals(0, sm.size());
1344          assertTrue(sm.isEmpty());
1345 <        assertTrue(sm.remove(m3) == null);
1345 >        assertSame(sm.remove(m3), null);
1346          assertEquals(4, map.size());
1347      }
1348  
# Line 1455 | Line 1414 | public class ConcurrentSkipListSubMapTes
1414          SortedMap ssm = sm.tailMap(m4);
1415          assertEquals(m4, ssm.firstKey());
1416          assertEquals(m5, ssm.lastKey());
1417 <        assertTrue(ssm.remove(m4) != null);
1417 >        assertEquals("D", ssm.remove(m4));
1418          assertEquals(1, ssm.size());
1419          assertEquals(3, sm.size());
1420          assertEquals(4, map.size());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines