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

Comparing jsr166/src/test/tck/ConcurrentSkipListMapTest.java (file contents):
Revision 1.11 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.20 by jsr166, Sat Oct 9 19:30:34 2010 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListMapTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16      public static Test suite() {
17 <        return new TestSuite(ConcurrentSkipListMapTest.class);
17 >        return new TestSuite(ConcurrentSkipListMapTest.class);
18      }
19  
20      /**
21       * Create a map from Integers 1-5 to Strings "A"-"E".
22       */
23      private static ConcurrentSkipListMap map5() {
24 <        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
24 >        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
25          assertTrue(map.isEmpty());
26 <        map.put(one, "A");
27 <        map.put(five, "E");
28 <        map.put(three, "C");
29 <        map.put(two, "B");
30 <        map.put(four, "D");
26 >        map.put(one, "A");
27 >        map.put(five, "E");
28 >        map.put(three, "C");
29 >        map.put(two, "B");
30 >        map.put(four, "D");
31          assertFalse(map.isEmpty());
32          assertEquals(5, map.size());
33 <        return map;
33 >        return map;
34      }
35  
36      /**
37 <     *  clear removes all pairs
37 >     * clear removes all pairs
38       */
39      public void testClear() {
40          ConcurrentSkipListMap map = map5();
41 <        map.clear();
42 <        assertEquals(map.size(), 0);
41 >        map.clear();
42 >        assertEquals(map.size(), 0);
43      }
44  
45      /**
# Line 52 | Line 52 | public class ConcurrentSkipListMapTest e
52      }
53  
54      /**
55 <     *  Maps with same contents are equal
55 >     * Maps with same contents are equal
56       */
57      public void testEquals() {
58          ConcurrentSkipListMap map1 = map5();
59          ConcurrentSkipListMap map2 = map5();
60          assertEquals(map1, map2);
61          assertEquals(map2, map1);
62 <        map1.clear();
62 >        map1.clear();
63          assertFalse(map1.equals(map2));
64          assertFalse(map2.equals(map1));
65      }
66  
67      /**
68 <     *  containsKey returns true for contained key
68 >     * containsKey returns true for contained key
69       */
70      public void testContainsKey() {
71          ConcurrentSkipListMap map = map5();
72 <        assertTrue(map.containsKey(one));
72 >        assertTrue(map.containsKey(one));
73          assertFalse(map.containsKey(zero));
74      }
75  
76      /**
77 <     *  containsValue returns true for held values
77 >     * containsValue returns true for held values
78       */
79      public void testContainsValue() {
80          ConcurrentSkipListMap map = map5();
81 <        assertTrue(map.containsValue("A"));
81 >        assertTrue(map.containsValue("A"));
82          assertFalse(map.containsValue("Z"));
83      }
84  
85      /**
86 <     *  get returns the correct element at the given key,
87 <     *  or null if not present
86 >     * get returns the correct element at the given key,
87 >     * or null if not present
88       */
89      public void testGet() {
90          ConcurrentSkipListMap map = map5();
91 <        assertEquals("A", (String)map.get(one));
91 >        assertEquals("A", (String)map.get(one));
92          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
93          assertNull(empty.get(one));
94      }
95  
96      /**
97 <     *  isEmpty is true of empty map and false for non-empty
97 >     * isEmpty is true of empty map and false for non-empty
98       */
99      public void testIsEmpty() {
100          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
101          ConcurrentSkipListMap map = map5();
102 <        assertTrue(empty.isEmpty());
102 >        assertTrue(empty.isEmpty());
103          assertFalse(map.isEmpty());
104      }
105  
106      /**
107 <     *   firstKey returns first key
107 >     * firstKey returns first key
108       */
109      public void testFirstKey() {
110          ConcurrentSkipListMap map = map5();
111 <        assertEquals(one, map.firstKey());
111 >        assertEquals(one, map.firstKey());
112      }
113  
114      /**
115 <     *   lastKey returns last key
115 >     * lastKey returns last key
116       */
117      public void testLastKey() {
118          ConcurrentSkipListMap map = map5();
119 <        assertEquals(five, map.lastKey());
119 >        assertEquals(five, map.lastKey());
120      }
121  
122  
123      /**
124 <     *  keySet.toArray returns contains all keys
124 >     * keySet.toArray returns contains all keys
125       */
126      public void testKeySetToArray() {
127          ConcurrentSkipListMap map = map5();
128 <        Set s = map.keySet();
128 >        Set s = map.keySet();
129          Object[] ar = s.toArray();
130          assertTrue(s.containsAll(Arrays.asList(ar)));
131 <        assertEquals(5, ar.length);
131 >        assertEquals(5, ar.length);
132          ar[0] = m10;
133          assertFalse(s.containsAll(Arrays.asList(ar)));
134      }
135  
136      /**
137 <     *  descendingkeySet.toArray returns contains all keys
137 >     * descendingkeySet.toArray returns contains all keys
138       */
139      public void testDescendingKeySetToArray() {
140          ConcurrentSkipListMap map = map5();
141 <        Set s = map.descendingKeySet();
141 >        Set s = map.descendingKeySet();
142          Object[] ar = s.toArray();
143 <        assertEquals(5, ar.length);
143 >        assertEquals(5, ar.length);
144          assertTrue(s.containsAll(Arrays.asList(ar)));
145          ar[0] = m10;
146          assertFalse(s.containsAll(Arrays.asList(ar)));
147      }
148  
149      /**
150 <     *   keySet returns a Set containing all the keys
150 >     * keySet returns a Set containing all the keys
151       */
152      public void testKeySet() {
153          ConcurrentSkipListMap map = map5();
154 <        Set s = map.keySet();
155 <        assertEquals(5, s.size());
156 <        assertTrue(s.contains(one));
157 <        assertTrue(s.contains(two));
158 <        assertTrue(s.contains(three));
159 <        assertTrue(s.contains(four));
160 <        assertTrue(s.contains(five));
154 >        Set s = map.keySet();
155 >        assertEquals(5, s.size());
156 >        assertTrue(s.contains(one));
157 >        assertTrue(s.contains(two));
158 >        assertTrue(s.contains(three));
159 >        assertTrue(s.contains(four));
160 >        assertTrue(s.contains(five));
161      }
162  
163      /**
164 <     *   keySet is ordered
164 >     * keySet is ordered
165       */
166      public void testKeySetOrder() {
167          ConcurrentSkipListMap map = map5();
168 <        Set s = map.keySet();
168 >        Set s = map.keySet();
169          Iterator i = s.iterator();
170          Integer last = (Integer)i.next();
171          assertEquals(last, one);
# Line 184 | Line 184 | public class ConcurrentSkipListMapTest e
184       */
185      public void testKeySetDescendingIteratorOrder() {
186          ConcurrentSkipListMap map = map5();
187 <        NavigableSet s = map.navigableKeySet();
187 >        NavigableSet s = map.navigableKeySet();
188          Iterator i = s.descendingIterator();
189          Integer last = (Integer)i.next();
190          assertEquals(last, five);
# Line 199 | Line 199 | public class ConcurrentSkipListMapTest e
199      }
200  
201      /**
202 <     *   descendingKeySet is ordered
202 >     * descendingKeySet is ordered
203       */
204      public void testDescendingKeySetOrder() {
205          ConcurrentSkipListMap map = map5();
206 <        Set s = map.descendingKeySet();
206 >        Set s = map.descendingKeySet();
207          Iterator i = s.iterator();
208          Integer last = (Integer)i.next();
209          assertEquals(last, five);
# Line 218 | Line 218 | public class ConcurrentSkipListMapTest e
218      }
219  
220      /**
221 <     *  descending iterator of descendingKeySet is ordered
221 >     * descending iterator of descendingKeySet is ordered
222       */
223      public void testDescendingKeySetDescendingIteratorOrder() {
224          ConcurrentSkipListMap map = map5();
225 <        NavigableSet s = map.descendingKeySet();
225 >        NavigableSet s = map.descendingKeySet();
226          Iterator i = s.descendingIterator();
227          Integer last = (Integer)i.next();
228          assertEquals(last, one);
# Line 237 | Line 237 | public class ConcurrentSkipListMapTest e
237      }
238  
239      /**
240 <     *  Values.toArray contains all values
240 >     * Values.toArray contains all values
241       */
242      public void testValuesToArray() {
243          ConcurrentSkipListMap map = map5();
244 <        Collection v = map.values();
244 >        Collection v = map.values();
245          Object[] ar = v.toArray();
246          ArrayList s = new ArrayList(Arrays.asList(ar));
247 <        assertEquals(5, ar.length);
248 <        assertTrue(s.contains("A"));
249 <        assertTrue(s.contains("B"));
250 <        assertTrue(s.contains("C"));
251 <        assertTrue(s.contains("D"));
252 <        assertTrue(s.contains("E"));
247 >        assertEquals(5, ar.length);
248 >        assertTrue(s.contains("A"));
249 >        assertTrue(s.contains("B"));
250 >        assertTrue(s.contains("C"));
251 >        assertTrue(s.contains("D"));
252 >        assertTrue(s.contains("E"));
253      }
254  
255      /**
# Line 257 | Line 257 | public class ConcurrentSkipListMapTest e
257       */
258      public void testValues() {
259          ConcurrentSkipListMap map = map5();
260 <        Collection s = map.values();
261 <        assertEquals(5, s.size());
262 <        assertTrue(s.contains("A"));
263 <        assertTrue(s.contains("B"));
264 <        assertTrue(s.contains("C"));
265 <        assertTrue(s.contains("D"));
266 <        assertTrue(s.contains("E"));
260 >        Collection s = map.values();
261 >        assertEquals(5, s.size());
262 >        assertTrue(s.contains("A"));
263 >        assertTrue(s.contains("B"));
264 >        assertTrue(s.contains("C"));
265 >        assertTrue(s.contains("D"));
266 >        assertTrue(s.contains("E"));
267      }
268  
269      /**
# Line 271 | Line 271 | public class ConcurrentSkipListMapTest e
271       */
272      public void testEntrySet() {
273          ConcurrentSkipListMap map = map5();
274 <        Set s = map.entrySet();
275 <        assertEquals(5, s.size());
274 >        Set s = map.entrySet();
275 >        assertEquals(5, s.size());
276          Iterator it = s.iterator();
277          while (it.hasNext()) {
278              Map.Entry e = (Map.Entry) it.next();
# Line 290 | Line 290 | public class ConcurrentSkipListMapTest e
290       */
291      public void testDescendingEntrySet() {
292          ConcurrentSkipListMap map = map5();
293 <        Set s = map.descendingMap().entrySet();
294 <        assertEquals(5, s.size());
293 >        Set s = map.descendingMap().entrySet();
294 >        assertEquals(5, s.size());
295          Iterator it = s.iterator();
296          while (it.hasNext()) {
297              Map.Entry e = (Map.Entry) it.next();
# Line 305 | Line 305 | public class ConcurrentSkipListMapTest e
305      }
306  
307      /**
308 <     *  entrySet.toArray contains all entries
308 >     * entrySet.toArray contains all entries
309       */
310      public void testEntrySetToArray() {
311          ConcurrentSkipListMap map = map5();
312 <        Set s = map.entrySet();
312 >        Set s = map.entrySet();
313          Object[] ar = s.toArray();
314          assertEquals(5, ar.length);
315          for (int i = 0; i < 5; ++i) {
# Line 319 | Line 319 | public class ConcurrentSkipListMapTest e
319      }
320  
321      /**
322 <     *  descendingEntrySet.toArray contains all entries
322 >     * descendingEntrySet.toArray contains all entries
323       */
324      public void testDescendingEntrySetToArray() {
325          ConcurrentSkipListMap map = map5();
326 <        Set s = map.descendingMap().entrySet();
326 >        Set s = map.descendingMap().entrySet();
327          Object[] ar = s.toArray();
328          assertEquals(5, ar.length);
329          for (int i = 0; i < 5; ++i) {
# Line 333 | Line 333 | public class ConcurrentSkipListMapTest e
333      }
334  
335      /**
336 <     *   putAll  adds all key-value pairs from the given map
336 >     * putAll adds all key-value pairs from the given map
337       */
338      public void testPutAll() {
339          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
340          ConcurrentSkipListMap map = map5();
341 <        empty.putAll(map);
342 <        assertEquals(5, empty.size());
343 <        assertTrue(empty.containsKey(one));
344 <        assertTrue(empty.containsKey(two));
345 <        assertTrue(empty.containsKey(three));
346 <        assertTrue(empty.containsKey(four));
347 <        assertTrue(empty.containsKey(five));
341 >        empty.putAll(map);
342 >        assertEquals(5, empty.size());
343 >        assertTrue(empty.containsKey(one));
344 >        assertTrue(empty.containsKey(two));
345 >        assertTrue(empty.containsKey(three));
346 >        assertTrue(empty.containsKey(four));
347 >        assertTrue(empty.containsKey(five));
348      }
349  
350      /**
351 <     *   putIfAbsent works when the given key is not present
351 >     * putIfAbsent works when the given key is not present
352       */
353      public void testPutIfAbsent() {
354          ConcurrentSkipListMap map = map5();
355 <        map.putIfAbsent(six, "Z");
355 >        map.putIfAbsent(six, "Z");
356          assertTrue(map.containsKey(six));
357      }
358  
359      /**
360 <     *   putIfAbsent does not add the pair if the key is already present
360 >     * putIfAbsent does not add the pair if the key is already present
361       */
362      public void testPutIfAbsent2() {
363          ConcurrentSkipListMap map = map5();
# Line 365 | Line 365 | public class ConcurrentSkipListMapTest e
365      }
366  
367      /**
368 <     *   replace fails when the given key is not present
368 >     * replace fails when the given key is not present
369       */
370      public void testReplace() {
371          ConcurrentSkipListMap map = map5();
372 <        assertNull(map.replace(six, "Z"));
372 >        assertNull(map.replace(six, "Z"));
373          assertFalse(map.containsKey(six));
374      }
375  
376      /**
377 <     *   replace succeeds if the key is already present
377 >     * replace succeeds if the key is already present
378       */
379      public void testReplace2() {
380          ConcurrentSkipListMap map = map5();
# Line 389 | Line 389 | public class ConcurrentSkipListMapTest e
389      public void testReplaceValue() {
390          ConcurrentSkipListMap map = map5();
391          assertEquals("A", map.get(one));
392 <        assertFalse(map.replace(one, "Z", "Z"));
392 >        assertFalse(map.replace(one, "Z", "Z"));
393          assertEquals("A", map.get(one));
394      }
395  
# Line 399 | Line 399 | public class ConcurrentSkipListMapTest e
399      public void testReplaceValue2() {
400          ConcurrentSkipListMap map = map5();
401          assertEquals("A", map.get(one));
402 <        assertTrue(map.replace(one, "A", "Z"));
402 >        assertTrue(map.replace(one, "A", "Z"));
403          assertEquals("Z", map.get(one));
404      }
405  
406  
407      /**
408 <     *   remove removes the correct key-value pair from the map
408 >     * remove removes the correct key-value pair from the map
409       */
410      public void testRemove() {
411          ConcurrentSkipListMap map = map5();
412 <        map.remove(five);
413 <        assertEquals(4, map.size());
414 <        assertFalse(map.containsKey(five));
412 >        map.remove(five);
413 >        assertEquals(4, map.size());
414 >        assertFalse(map.containsKey(five));
415      }
416  
417      /**
# Line 419 | Line 419 | public class ConcurrentSkipListMapTest e
419       */
420      public void testRemove2() {
421          ConcurrentSkipListMap map = map5();
422 <        assertTrue(map.containsKey(five));
422 >        assertTrue(map.containsKey(five));
423          assertEquals("E", map.get(five));
424 <        map.remove(five, "E");
425 <        assertEquals(4, map.size());
426 <        assertFalse(map.containsKey(five));
427 <        map.remove(four, "A");
428 <        assertEquals(4, map.size());
429 <        assertTrue(map.containsKey(four));
430 <
424 >        map.remove(five, "E");
425 >        assertEquals(4, map.size());
426 >        assertFalse(map.containsKey(five));
427 >        map.remove(four, "A");
428 >        assertEquals(4, map.size());
429 >        assertTrue(map.containsKey(four));
430      }
431  
432      /**
# Line 446 | Line 445 | public class ConcurrentSkipListMapTest e
445  
446          Map.Entry e4 = map.lowerEntry(zero);
447          assertNull(e4);
449
448      }
449  
450      /**
# Line 465 | Line 463 | public class ConcurrentSkipListMapTest e
463  
464          Map.Entry e4 = map.higherEntry(six);
465          assertNull(e4);
468
466      }
467  
468      /**
# Line 484 | Line 481 | public class ConcurrentSkipListMapTest e
481  
482          Map.Entry e4 = map.floorEntry(zero);
483          assertNull(e4);
487
484      }
485  
486      /**
# Line 503 | Line 499 | public class ConcurrentSkipListMapTest e
499  
500          Map.Entry e4 = map.ceilingEntry(six);
501          assertNull(e4);
506
502      }
503  
504      /**
505       * lowerEntry, higherEntry, ceilingEntry, and floorEntry return
506 <     * imutable entries
506 >     * immutable entries
507       */
508      public void testEntryImmutablity() {
509          ConcurrentSkipListMap map = map5();
# Line 516 | Line 511 | public class ConcurrentSkipListMapTest e
511          assertEquals(two, e.getKey());
512          try {
513              e.setValue("X");
514 <            fail();
514 >            shouldThrow();
515          } catch (UnsupportedOperationException success) {}
516          e = map.higherEntry(zero);
517          assertEquals(one, e.getKey());
518          try {
519              e.setValue("X");
520 <            fail();
520 >            shouldThrow();
521          } catch (UnsupportedOperationException success) {}
522          e = map.floorEntry(one);
523          assertEquals(one, e.getKey());
524          try {
525              e.setValue("X");
526 <            fail();
526 >            shouldThrow();
527          } catch (UnsupportedOperationException success) {}
528          e = map.ceilingEntry(five);
529          assertEquals(five, e.getKey());
530          try {
531              e.setValue("X");
532 <            fail();
532 >            shouldThrow();
533          } catch (UnsupportedOperationException success) {}
534      }
535  
# Line 556 | Line 551 | public class ConcurrentSkipListMapTest e
551  
552          Object e4 = q.lowerKey(zero);
553          assertNull(e4);
559
554      }
555  
556      /**
# Line 575 | Line 569 | public class ConcurrentSkipListMapTest e
569  
570          Object e4 = q.higherKey(six);
571          assertNull(e4);
578
572      }
573  
574      /**
# Line 594 | Line 587 | public class ConcurrentSkipListMapTest e
587  
588          Object e4 = q.floorKey(zero);
589          assertNull(e4);
597
590      }
591  
592      /**
# Line 613 | Line 605 | public class ConcurrentSkipListMapTest e
605  
606          Object e4 = q.ceilingKey(six);
607          assertNull(e4);
616
608      }
609  
610      /**
# Line 638 | Line 629 | public class ConcurrentSkipListMapTest e
629          try {
630              e.setValue("A");
631              shouldThrow();
632 <        } catch (Exception ok) {
642 <        }
632 >        } catch (UnsupportedOperationException success) {}
633          e = map.pollFirstEntry();
634          assertNull(e);
635      }
# Line 666 | Line 656 | public class ConcurrentSkipListMapTest e
656          try {
657              e.setValue("E");
658              shouldThrow();
659 <        } catch (Exception ok) {
670 <        }
659 >        } catch (UnsupportedOperationException success) {}
660          e = map.pollLastEntry();
661          assertNull(e);
662      }
663  
664      /**
665 <     *   size returns the correct values
665 >     * size returns the correct values
666       */
667      public void testSize() {
668          ConcurrentSkipListMap map = map5();
669          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
670 <        assertEquals(0, empty.size());
671 <        assertEquals(5, map.size());
670 >        assertEquals(0, empty.size());
671 >        assertEquals(5, map.size());
672      }
673  
674      /**
# Line 703 | Line 692 | public class ConcurrentSkipListMapTest e
692              ConcurrentSkipListMap c = map5();
693              c.get(null);
694              shouldThrow();
695 <        } catch (NullPointerException e) {}
695 >        } catch (NullPointerException success) {}
696      }
697  
698      /**
# Line 714 | Line 703 | public class ConcurrentSkipListMapTest e
703              ConcurrentSkipListMap c = map5();
704              c.containsKey(null);
705              shouldThrow();
706 <        } catch (NullPointerException e) {}
706 >        } catch (NullPointerException success) {}
707      }
708  
709      /**
# Line 725 | Line 714 | public class ConcurrentSkipListMapTest e
714              ConcurrentSkipListMap c = new ConcurrentSkipListMap();
715              c.containsValue(null);
716              shouldThrow();
717 <        } catch (NullPointerException e) {}
717 >        } catch (NullPointerException success) {}
718      }
719  
720  
# Line 737 | Line 726 | public class ConcurrentSkipListMapTest e
726              ConcurrentSkipListMap c = map5();
727              c.put(null, "whatever");
728              shouldThrow();
729 <        } catch (NullPointerException e) {}
729 >        } catch (NullPointerException success) {}
730      }
731  
732      /**
# Line 748 | Line 737 | public class ConcurrentSkipListMapTest e
737              ConcurrentSkipListMap c = map5();
738              c.putIfAbsent(null, "whatever");
739              shouldThrow();
740 <        } catch (NullPointerException e) {}
740 >        } catch (NullPointerException success) {}
741      }
742  
743      /**
# Line 759 | Line 748 | public class ConcurrentSkipListMapTest e
748              ConcurrentSkipListMap c = map5();
749              c.replace(null, "whatever");
750              shouldThrow();
751 <        } catch (NullPointerException e) {}
751 >        } catch (NullPointerException success) {}
752      }
753  
754      /**
# Line 770 | Line 759 | public class ConcurrentSkipListMapTest e
759              ConcurrentSkipListMap c = map5();
760              c.replace(null, one, "whatever");
761              shouldThrow();
762 <        } catch (NullPointerException e) {}
762 >        } catch (NullPointerException success) {}
763      }
764  
765      /**
# Line 782 | Line 771 | public class ConcurrentSkipListMapTest e
771              c.put("sadsdf", "asdads");
772              c.remove(null);
773              shouldThrow();
774 <        } catch (NullPointerException e) {}
774 >        } catch (NullPointerException success) {}
775      }
776  
777      /**
# Line 794 | Line 783 | public class ConcurrentSkipListMapTest e
783              c.put("sadsdf", "asdads");
784              c.remove(null, "whatever");
785              shouldThrow();
786 <        } catch (NullPointerException e) {}
786 >        } catch (NullPointerException success) {}
787      }
788  
789      /**
790       * remove(x, null) returns false
791       */
792      public void testRemove3() {
793 <        try {
794 <            ConcurrentSkipListMap c = new ConcurrentSkipListMap();
795 <            c.put("sadsdf", "asdads");
807 <            assertFalse(c.remove("sadsdf", null));
808 <        } catch (NullPointerException e) {
809 <            fail();
810 <        }
793 >        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
794 >        c.put("sadsdf", "asdads");
795 >        assertFalse(c.remove("sadsdf", null));
796      }
797  
798      /**
799       * A deserialized map equals original
800       */
801 <    public void testSerialization() {
801 >    public void testSerialization() throws Exception {
802          ConcurrentSkipListMap q = map5();
803  
804 <        try {
805 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
806 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
807 <            out.writeObject(q);
808 <            out.close();
809 <
810 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
811 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
812 <            ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
813 <            assertEquals(q.size(), r.size());
814 <            assertTrue(q.equals(r));
830 <            assertTrue(r.equals(q));
831 <        } catch (Exception e) {
832 <            e.printStackTrace();
833 <            unexpectedException();
834 <        }
804 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
805 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
806 >        out.writeObject(q);
807 >        out.close();
808 >
809 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
810 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
811 >        ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
812 >        assertEquals(q.size(), r.size());
813 >        assertTrue(q.equals(r));
814 >        assertTrue(r.equals(q));
815      }
816  
817  
# Line 872 | Line 852 | public class ConcurrentSkipListMapTest e
852          assertEquals(1, sm.size());
853          assertEquals(three, sm.firstKey());
854          assertEquals(three, sm.lastKey());
855 <        assertTrue(sm.remove(three) != null);
855 >        assertEquals("C", sm.remove(three));
856          assertTrue(sm.isEmpty());
857          assertEquals(3, map.size());
858      }
# Line 905 | Line 885 | public class ConcurrentSkipListMapTest e
885          assertEquals(4, map.size());
886          assertEquals(0, sm.size());
887          assertTrue(sm.isEmpty());
888 <        assertTrue(sm.remove(three) == null);
888 >        assertSame(sm.remove(three), null);
889          assertEquals(4, map.size());
890      }
891  
# Line 987 | Line 967 | public class ConcurrentSkipListMapTest e
967          NavigableMap ssm = sm.tailMap(four, true);
968          assertEquals(four, ssm.firstKey());
969          assertEquals(five, ssm.lastKey());
970 <        assertTrue(ssm.remove(four) != null);
970 >        assertEquals("D", ssm.remove(four));
971          assertEquals(1, ssm.size());
972          assertEquals(3, sm.size());
973          assertEquals(4, map.size());
# Line 999 | Line 979 | public class ConcurrentSkipListMapTest e
979      /**
980       * Submaps of submaps subdivide correctly
981       */
982 <    public void testRecursiveSubMaps() {
983 <        int mapSize = 1000;
984 <        Class cl = ConcurrentSkipListMap.class;
982 >    public void testRecursiveSubMaps() throws Exception {
983 >        int mapSize = 1000;
984 >        Class cl = ConcurrentSkipListMap.class;
985          NavigableMap<Integer, Integer> map = newMap(cl);
986          bs = new BitSet(mapSize);
987  
# Line 1017 | Line 997 | public class ConcurrentSkipListMapTest e
997                     0, mapSize - 1, true);
998      }
999  
1000 <    static NavigableMap<Integer, Integer> newMap(Class cl) {
1001 <        NavigableMap<Integer, Integer> result = null;
1002 <        try {
1023 <            result = (NavigableMap<Integer, Integer>) cl.newInstance();
1024 <        } catch (Exception e) {
1025 <            fail();
1026 <        }
1000 >    static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
1001 >        NavigableMap<Integer, Integer> result =
1002 >            (NavigableMap<Integer, Integer>) cl.newInstance();
1003          assertEquals(result.size(), 0);
1004          assertFalse(result.keySet().iterator().hasNext());
1005          return result;
# Line 1086 | Line 1062 | public class ConcurrentSkipListMapTest e
1062              } else {
1063                  try {
1064                      map.put(key, 2 * key);
1065 <                    fail();
1066 <                } catch (IllegalArgumentException e) {
1091 <                    // expected
1092 <                }
1065 >                    shouldThrow();
1066 >                } catch (IllegalArgumentException success) {}
1067              }
1068          }
1069      }
# Line 1218 | Line 1192 | public class ConcurrentSkipListMapTest e
1192                  // BitSet should support this! Test would run much faster
1193                  while (key >= min) {
1194                      if (bs.get(key))
1195 <                        return(key);
1195 >                        return key;
1196                      key--;
1197                  }
1198                  return -1;
# Line 1284 | Line 1258 | public class ConcurrentSkipListMapTest e
1258              assertEq(rs.last(),  -1);
1259              try {
1260                  map.firstKey();
1261 <                fail();
1262 <            } catch (NoSuchElementException e) {
1289 <                // expected
1290 <            }
1261 >                shouldThrow();
1262 >            } catch (NoSuchElementException success) {}
1263              try {
1264                  map.lastKey();
1265 <                fail();
1266 <            } catch (NoSuchElementException e) {
1295 <                // expected
1296 <            }
1265 >                shouldThrow();
1266 >            } catch (NoSuchElementException success) {}
1267          }
1268      }
1269  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines