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.10 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.24 by jsr166, Fri May 27 19:21:27 2011 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.*;
# 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
122      /**
123 <     *  keySet.toArray returns contains all keys
123 >     * keySet.toArray returns contains all keys
124       */
125      public void testKeySetToArray() {
126          ConcurrentSkipListMap map = map5();
127 <        Set s = map.keySet();
127 >        Set s = map.keySet();
128          Object[] ar = s.toArray();
129          assertTrue(s.containsAll(Arrays.asList(ar)));
130 <        assertEquals(5, ar.length);
130 >        assertEquals(5, ar.length);
131          ar[0] = m10;
132          assertFalse(s.containsAll(Arrays.asList(ar)));
133      }
134  
135      /**
136 <     *  descendingkeySet.toArray returns contains all keys
136 >     * descendingkeySet.toArray returns contains all keys
137       */
138      public void testDescendingKeySetToArray() {
139          ConcurrentSkipListMap map = map5();
140 <        Set s = map.descendingKeySet();
140 >        Set s = map.descendingKeySet();
141          Object[] ar = s.toArray();
142 <        assertEquals(5, ar.length);
142 >        assertEquals(5, ar.length);
143          assertTrue(s.containsAll(Arrays.asList(ar)));
144          ar[0] = m10;
145          assertFalse(s.containsAll(Arrays.asList(ar)));
146      }
147  
148      /**
149 <     *   keySet returns a Set containing all the keys
149 >     * keySet returns a Set containing all the keys
150       */
151      public void testKeySet() {
152          ConcurrentSkipListMap map = map5();
153 <        Set s = map.keySet();
154 <        assertEquals(5, s.size());
155 <        assertTrue(s.contains(one));
156 <        assertTrue(s.contains(two));
157 <        assertTrue(s.contains(three));
158 <        assertTrue(s.contains(four));
159 <        assertTrue(s.contains(five));
153 >        Set s = map.keySet();
154 >        assertEquals(5, s.size());
155 >        assertTrue(s.contains(one));
156 >        assertTrue(s.contains(two));
157 >        assertTrue(s.contains(three));
158 >        assertTrue(s.contains(four));
159 >        assertTrue(s.contains(five));
160      }
161  
162      /**
163 <     *   keySet is ordered
163 >     * keySet is ordered
164       */
165      public void testKeySetOrder() {
166          ConcurrentSkipListMap map = map5();
167 <        Set s = map.keySet();
167 >        Set s = map.keySet();
168          Iterator i = s.iterator();
169          Integer last = (Integer)i.next();
170          assertEquals(last, one);
# Line 184 | Line 183 | public class ConcurrentSkipListMapTest e
183       */
184      public void testKeySetDescendingIteratorOrder() {
185          ConcurrentSkipListMap map = map5();
186 <        NavigableSet s = map.navigableKeySet();
186 >        NavigableSet s = map.navigableKeySet();
187          Iterator i = s.descendingIterator();
188          Integer last = (Integer)i.next();
189          assertEquals(last, five);
# Line 199 | Line 198 | public class ConcurrentSkipListMapTest e
198      }
199  
200      /**
201 <     *   descendingKeySet is ordered
201 >     * descendingKeySet is ordered
202       */
203      public void testDescendingKeySetOrder() {
204          ConcurrentSkipListMap map = map5();
205 <        Set s = map.descendingKeySet();
205 >        Set s = map.descendingKeySet();
206          Iterator i = s.iterator();
207          Integer last = (Integer)i.next();
208          assertEquals(last, five);
# Line 218 | Line 217 | public class ConcurrentSkipListMapTest e
217      }
218  
219      /**
220 <     *  descending iterator of descendingKeySet is ordered
220 >     * descending iterator of descendingKeySet is ordered
221       */
222      public void testDescendingKeySetDescendingIteratorOrder() {
223          ConcurrentSkipListMap map = map5();
224 <        NavigableSet s = map.descendingKeySet();
224 >        NavigableSet s = map.descendingKeySet();
225          Iterator i = s.descendingIterator();
226          Integer last = (Integer)i.next();
227          assertEquals(last, one);
# Line 237 | Line 236 | public class ConcurrentSkipListMapTest e
236      }
237  
238      /**
239 <     *  Values.toArray contains all values
239 >     * Values.toArray contains all values
240       */
241      public void testValuesToArray() {
242          ConcurrentSkipListMap map = map5();
243 <        Collection v = map.values();
243 >        Collection v = map.values();
244          Object[] ar = v.toArray();
245          ArrayList s = new ArrayList(Arrays.asList(ar));
246 <        assertEquals(5, ar.length);
247 <        assertTrue(s.contains("A"));
248 <        assertTrue(s.contains("B"));
249 <        assertTrue(s.contains("C"));
250 <        assertTrue(s.contains("D"));
251 <        assertTrue(s.contains("E"));
246 >        assertEquals(5, ar.length);
247 >        assertTrue(s.contains("A"));
248 >        assertTrue(s.contains("B"));
249 >        assertTrue(s.contains("C"));
250 >        assertTrue(s.contains("D"));
251 >        assertTrue(s.contains("E"));
252      }
253  
254      /**
# Line 257 | Line 256 | public class ConcurrentSkipListMapTest e
256       */
257      public void testValues() {
258          ConcurrentSkipListMap map = map5();
259 <        Collection s = map.values();
260 <        assertEquals(5, s.size());
261 <        assertTrue(s.contains("A"));
262 <        assertTrue(s.contains("B"));
263 <        assertTrue(s.contains("C"));
264 <        assertTrue(s.contains("D"));
265 <        assertTrue(s.contains("E"));
259 >        Collection s = map.values();
260 >        assertEquals(5, s.size());
261 >        assertTrue(s.contains("A"));
262 >        assertTrue(s.contains("B"));
263 >        assertTrue(s.contains("C"));
264 >        assertTrue(s.contains("D"));
265 >        assertTrue(s.contains("E"));
266      }
267  
268      /**
# Line 271 | Line 270 | public class ConcurrentSkipListMapTest e
270       */
271      public void testEntrySet() {
272          ConcurrentSkipListMap map = map5();
273 <        Set s = map.entrySet();
274 <        assertEquals(5, s.size());
273 >        Set s = map.entrySet();
274 >        assertEquals(5, s.size());
275          Iterator it = s.iterator();
276          while (it.hasNext()) {
277              Map.Entry e = (Map.Entry) it.next();
# Line 290 | Line 289 | public class ConcurrentSkipListMapTest e
289       */
290      public void testDescendingEntrySet() {
291          ConcurrentSkipListMap map = map5();
292 <        Set s = map.descendingMap().entrySet();
293 <        assertEquals(5, s.size());
292 >        Set s = map.descendingMap().entrySet();
293 >        assertEquals(5, s.size());
294          Iterator it = s.iterator();
295          while (it.hasNext()) {
296              Map.Entry e = (Map.Entry) it.next();
# Line 305 | Line 304 | public class ConcurrentSkipListMapTest e
304      }
305  
306      /**
307 <     *  entrySet.toArray contains all entries
307 >     * entrySet.toArray contains all entries
308       */
309      public void testEntrySetToArray() {
310          ConcurrentSkipListMap map = map5();
311 <        Set s = map.entrySet();
311 >        Set s = map.entrySet();
312          Object[] ar = s.toArray();
313          assertEquals(5, ar.length);
314          for (int i = 0; i < 5; ++i) {
# Line 319 | Line 318 | public class ConcurrentSkipListMapTest e
318      }
319  
320      /**
321 <     *  descendingEntrySet.toArray contains all entries
321 >     * descendingEntrySet.toArray contains all entries
322       */
323      public void testDescendingEntrySetToArray() {
324          ConcurrentSkipListMap map = map5();
325 <        Set s = map.descendingMap().entrySet();
325 >        Set s = map.descendingMap().entrySet();
326          Object[] ar = s.toArray();
327          assertEquals(5, ar.length);
328          for (int i = 0; i < 5; ++i) {
# Line 333 | Line 332 | public class ConcurrentSkipListMapTest e
332      }
333  
334      /**
335 <     *   putAll  adds all key-value pairs from the given map
335 >     * putAll adds all key-value pairs from the given map
336       */
337      public void testPutAll() {
338          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
339          ConcurrentSkipListMap map = map5();
340 <        empty.putAll(map);
341 <        assertEquals(5, empty.size());
342 <        assertTrue(empty.containsKey(one));
343 <        assertTrue(empty.containsKey(two));
344 <        assertTrue(empty.containsKey(three));
345 <        assertTrue(empty.containsKey(four));
346 <        assertTrue(empty.containsKey(five));
340 >        empty.putAll(map);
341 >        assertEquals(5, empty.size());
342 >        assertTrue(empty.containsKey(one));
343 >        assertTrue(empty.containsKey(two));
344 >        assertTrue(empty.containsKey(three));
345 >        assertTrue(empty.containsKey(four));
346 >        assertTrue(empty.containsKey(five));
347      }
348  
349      /**
350 <     *   putIfAbsent works when the given key is not present
350 >     * putIfAbsent works when the given key is not present
351       */
352      public void testPutIfAbsent() {
353          ConcurrentSkipListMap map = map5();
354 <        map.putIfAbsent(six, "Z");
354 >        map.putIfAbsent(six, "Z");
355          assertTrue(map.containsKey(six));
356      }
357  
358      /**
359 <     *   putIfAbsent does not add the pair if the key is already present
359 >     * putIfAbsent does not add the pair if the key is already present
360       */
361      public void testPutIfAbsent2() {
362          ConcurrentSkipListMap map = map5();
# Line 365 | Line 364 | public class ConcurrentSkipListMapTest e
364      }
365  
366      /**
367 <     *   replace fails when the given key is not present
367 >     * replace fails when the given key is not present
368       */
369      public void testReplace() {
370          ConcurrentSkipListMap map = map5();
371 <        assertNull(map.replace(six, "Z"));
371 >        assertNull(map.replace(six, "Z"));
372          assertFalse(map.containsKey(six));
373      }
374  
375      /**
376 <     *   replace succeeds if the key is already present
376 >     * replace succeeds if the key is already present
377       */
378      public void testReplace2() {
379          ConcurrentSkipListMap map = map5();
# Line 382 | Line 381 | public class ConcurrentSkipListMapTest e
381          assertEquals("Z", map.get(one));
382      }
383  
385
384      /**
385       * replace value fails when the given key not mapped to expected value
386       */
387      public void testReplaceValue() {
388          ConcurrentSkipListMap map = map5();
389          assertEquals("A", map.get(one));
390 <        assertFalse(map.replace(one, "Z", "Z"));
390 >        assertFalse(map.replace(one, "Z", "Z"));
391          assertEquals("A", map.get(one));
392      }
393  
# Line 399 | Line 397 | public class ConcurrentSkipListMapTest e
397      public void testReplaceValue2() {
398          ConcurrentSkipListMap map = map5();
399          assertEquals("A", map.get(one));
400 <        assertTrue(map.replace(one, "A", "Z"));
400 >        assertTrue(map.replace(one, "A", "Z"));
401          assertEquals("Z", map.get(one));
402      }
403  
406
404      /**
405 <     *   remove removes the correct key-value pair from the map
405 >     * remove removes the correct key-value pair from the map
406       */
407      public void testRemove() {
408          ConcurrentSkipListMap map = map5();
409 <        map.remove(five);
410 <        assertEquals(4, map.size());
411 <        assertFalse(map.containsKey(five));
409 >        map.remove(five);
410 >        assertEquals(4, map.size());
411 >        assertFalse(map.containsKey(five));
412      }
413  
414      /**
# Line 419 | Line 416 | public class ConcurrentSkipListMapTest e
416       */
417      public void testRemove2() {
418          ConcurrentSkipListMap map = map5();
419 <        assertTrue(map.containsKey(five));
419 >        assertTrue(map.containsKey(five));
420          assertEquals("E", map.get(five));
421 <        map.remove(five, "E");
422 <        assertEquals(4, map.size());
423 <        assertFalse(map.containsKey(five));
424 <        map.remove(four, "A");
425 <        assertEquals(4, map.size());
426 <        assertTrue(map.containsKey(four));
430 <
421 >        map.remove(five, "E");
422 >        assertEquals(4, map.size());
423 >        assertFalse(map.containsKey(five));
424 >        map.remove(four, "A");
425 >        assertEquals(4, map.size());
426 >        assertTrue(map.containsKey(four));
427      }
428  
429      /**
# Line 446 | Line 442 | public class ConcurrentSkipListMapTest e
442  
443          Map.Entry e4 = map.lowerEntry(zero);
444          assertNull(e4);
449
445      }
446  
447      /**
# Line 465 | Line 460 | public class ConcurrentSkipListMapTest e
460  
461          Map.Entry e4 = map.higherEntry(six);
462          assertNull(e4);
468
463      }
464  
465      /**
# Line 484 | Line 478 | public class ConcurrentSkipListMapTest e
478  
479          Map.Entry e4 = map.floorEntry(zero);
480          assertNull(e4);
487
481      }
482  
483      /**
# Line 503 | Line 496 | public class ConcurrentSkipListMapTest e
496  
497          Map.Entry e4 = map.ceilingEntry(six);
498          assertNull(e4);
506
499      }
500  
501      /**
502       * lowerEntry, higherEntry, ceilingEntry, and floorEntry return
503 <     * imutable entries
503 >     * immutable entries
504       */
505      public void testEntryImmutablity() {
506          ConcurrentSkipListMap map = map5();
# Line 516 | Line 508 | public class ConcurrentSkipListMapTest e
508          assertEquals(two, e.getKey());
509          try {
510              e.setValue("X");
511 <            fail();
511 >            shouldThrow();
512          } catch (UnsupportedOperationException success) {}
513          e = map.higherEntry(zero);
514          assertEquals(one, e.getKey());
515          try {
516              e.setValue("X");
517 <            fail();
517 >            shouldThrow();
518          } catch (UnsupportedOperationException success) {}
519          e = map.floorEntry(one);
520          assertEquals(one, e.getKey());
521          try {
522              e.setValue("X");
523 <            fail();
523 >            shouldThrow();
524          } catch (UnsupportedOperationException success) {}
525          e = map.ceilingEntry(five);
526          assertEquals(five, e.getKey());
527          try {
528              e.setValue("X");
529 <            fail();
529 >            shouldThrow();
530          } catch (UnsupportedOperationException success) {}
531      }
532  
533  
542
534      /**
535       * lowerKey returns preceding element
536       */
# Line 556 | Line 547 | public class ConcurrentSkipListMapTest e
547  
548          Object e4 = q.lowerKey(zero);
549          assertNull(e4);
559
550      }
551  
552      /**
# Line 575 | Line 565 | public class ConcurrentSkipListMapTest e
565  
566          Object e4 = q.higherKey(six);
567          assertNull(e4);
578
568      }
569  
570      /**
# Line 594 | Line 583 | public class ConcurrentSkipListMapTest e
583  
584          Object e4 = q.floorKey(zero);
585          assertNull(e4);
597
586      }
587  
588      /**
# Line 613 | Line 601 | public class ConcurrentSkipListMapTest e
601  
602          Object e4 = q.ceilingKey(six);
603          assertNull(e4);
616
604      }
605  
606      /**
# Line 638 | Line 625 | public class ConcurrentSkipListMapTest e
625          try {
626              e.setValue("A");
627              shouldThrow();
628 <        } catch (Exception ok) {
642 <        }
628 >        } catch (UnsupportedOperationException success) {}
629          e = map.pollFirstEntry();
630          assertNull(e);
631      }
# Line 666 | Line 652 | public class ConcurrentSkipListMapTest e
652          try {
653              e.setValue("E");
654              shouldThrow();
655 <        } catch (Exception ok) {
670 <        }
655 >        } catch (UnsupportedOperationException success) {}
656          e = map.pollLastEntry();
657          assertNull(e);
658      }
659  
660      /**
661 <     *   size returns the correct values
661 >     * size returns the correct values
662       */
663      public void testSize() {
664          ConcurrentSkipListMap map = map5();
665          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
666 <        assertEquals(0, empty.size());
667 <        assertEquals(5, map.size());
666 >        assertEquals(0, empty.size());
667 >        assertEquals(5, map.size());
668      }
669  
670      /**
# Line 689 | Line 674 | public class ConcurrentSkipListMapTest e
674          ConcurrentSkipListMap map = map5();
675          String s = map.toString();
676          for (int i = 1; i <= 5; ++i) {
677 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
677 >            assertTrue(s.contains(String.valueOf(i)));
678          }
679      }
680  
# Line 703 | Line 688 | public class ConcurrentSkipListMapTest e
688              ConcurrentSkipListMap c = map5();
689              c.get(null);
690              shouldThrow();
691 <        } catch (NullPointerException e){}
691 >        } catch (NullPointerException success) {}
692      }
693  
694      /**
# Line 714 | Line 699 | public class ConcurrentSkipListMapTest e
699              ConcurrentSkipListMap c = map5();
700              c.containsKey(null);
701              shouldThrow();
702 <        } catch (NullPointerException e){}
702 >        } catch (NullPointerException success) {}
703      }
704  
705      /**
# Line 725 | Line 710 | public class ConcurrentSkipListMapTest e
710              ConcurrentSkipListMap c = new ConcurrentSkipListMap();
711              c.containsValue(null);
712              shouldThrow();
713 <        } catch (NullPointerException e){}
713 >        } catch (NullPointerException success) {}
714      }
715  
731
716      /**
717       * put(null,x) throws NPE
718       */
# Line 737 | Line 721 | public class ConcurrentSkipListMapTest e
721              ConcurrentSkipListMap c = map5();
722              c.put(null, "whatever");
723              shouldThrow();
724 <        } catch (NullPointerException e){}
724 >        } catch (NullPointerException success) {}
725      }
726  
727      /**
# Line 748 | Line 732 | public class ConcurrentSkipListMapTest e
732              ConcurrentSkipListMap c = map5();
733              c.putIfAbsent(null, "whatever");
734              shouldThrow();
735 <        } catch (NullPointerException e){}
735 >        } catch (NullPointerException success) {}
736      }
737  
738      /**
# Line 759 | Line 743 | public class ConcurrentSkipListMapTest e
743              ConcurrentSkipListMap c = map5();
744              c.replace(null, "whatever");
745              shouldThrow();
746 <        } catch (NullPointerException e){}
746 >        } catch (NullPointerException success) {}
747      }
748  
749      /**
# Line 770 | Line 754 | public class ConcurrentSkipListMapTest e
754              ConcurrentSkipListMap c = map5();
755              c.replace(null, one, "whatever");
756              shouldThrow();
757 <        } catch (NullPointerException e){}
757 >        } catch (NullPointerException success) {}
758      }
759  
760      /**
# Line 782 | Line 766 | public class ConcurrentSkipListMapTest e
766              c.put("sadsdf", "asdads");
767              c.remove(null);
768              shouldThrow();
769 <        } catch (NullPointerException e){}
769 >        } catch (NullPointerException success) {}
770      }
771  
772      /**
# Line 794 | Line 778 | public class ConcurrentSkipListMapTest e
778              c.put("sadsdf", "asdads");
779              c.remove(null, "whatever");
780              shouldThrow();
781 <        } catch (NullPointerException e){}
781 >        } catch (NullPointerException success) {}
782      }
783  
784      /**
785       * remove(x, null) returns false
786       */
787      public void testRemove3() {
788 <        try {
789 <            ConcurrentSkipListMap c = new ConcurrentSkipListMap();
790 <            c.put("sadsdf", "asdads");
807 <            assertFalse(c.remove("sadsdf", null));
808 <        } catch (NullPointerException e){
809 <            fail();
810 <        }
788 >        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
789 >        c.put("sadsdf", "asdads");
790 >        assertFalse(c.remove("sadsdf", null));
791      }
792  
793      /**
794       * A deserialized map equals original
795       */
796 <    public void testSerialization() {
796 >    public void testSerialization() throws Exception {
797          ConcurrentSkipListMap q = map5();
798  
799 <        try {
800 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
801 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
802 <            out.writeObject(q);
803 <            out.close();
804 <
805 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
806 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
807 <            ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
808 <            assertEquals(q.size(), r.size());
809 <            assertTrue(q.equals(r));
830 <            assertTrue(r.equals(q));
831 <        } catch (Exception e){
832 <            e.printStackTrace();
833 <            unexpectedException();
834 <        }
799 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
800 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
801 >        out.writeObject(q);
802 >        out.close();
803 >
804 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
805 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
806 >        ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
807 >        assertEquals(q.size(), r.size());
808 >        assertTrue(q.equals(r));
809 >        assertTrue(r.equals(q));
810      }
811  
837
838
812      /**
813       * subMap returns map with keys in requested range
814       */
# Line 872 | Line 845 | public class ConcurrentSkipListMapTest e
845          assertEquals(1, sm.size());
846          assertEquals(three, sm.firstKey());
847          assertEquals(three, sm.lastKey());
848 <        assertTrue(sm.remove(three) != null);
848 >        assertEquals("C", sm.remove(three));
849          assertTrue(sm.isEmpty());
850          assertEquals(3, map.size());
851      }
# Line 905 | Line 878 | public class ConcurrentSkipListMapTest e
878          assertEquals(4, map.size());
879          assertEquals(0, sm.size());
880          assertTrue(sm.isEmpty());
881 <        assertTrue(sm.remove(three) == null);
881 >        assertSame(sm.remove(three), null);
882          assertEquals(4, map.size());
883      }
884  
# Line 987 | Line 960 | public class ConcurrentSkipListMapTest e
960          NavigableMap ssm = sm.tailMap(four, true);
961          assertEquals(four, ssm.firstKey());
962          assertEquals(five, ssm.lastKey());
963 <        assertTrue(ssm.remove(four) != null);
963 >        assertEquals("D", ssm.remove(four));
964          assertEquals(1, ssm.size());
965          assertEquals(3, sm.size());
966          assertEquals(4, map.size());
# Line 999 | Line 972 | public class ConcurrentSkipListMapTest e
972      /**
973       * Submaps of submaps subdivide correctly
974       */
975 <    public void testRecursiveSubMaps() {
976 <        int mapSize = 1000;
977 <        Class cl = ConcurrentSkipListMap.class;
975 >    public void testRecursiveSubMaps() throws Exception {
976 >        int mapSize = expensiveTests ? 1000 : 100;
977 >        Class cl = ConcurrentSkipListMap.class;
978          NavigableMap<Integer, Integer> map = newMap(cl);
979          bs = new BitSet(mapSize);
980  
# Line 1017 | Line 990 | public class ConcurrentSkipListMapTest e
990                     0, mapSize - 1, true);
991      }
992  
993 <    static NavigableMap<Integer, Integer> newMap(Class cl) {
994 <        NavigableMap<Integer, Integer> result = null;
995 <        try {
1023 <            result = (NavigableMap<Integer, Integer>) cl.newInstance();
1024 <        } catch (Exception e) {
1025 <            fail();
1026 <        }
993 >    static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
994 >        NavigableMap<Integer, Integer> result =
995 >            (NavigableMap<Integer, Integer>) cl.newInstance();
996          assertEquals(result.size(), 0);
997          assertFalse(result.keySet().iterator().hasNext());
998          return result;
# Line 1086 | Line 1055 | public class ConcurrentSkipListMapTest e
1055              } else {
1056                  try {
1057                      map.put(key, 2 * key);
1058 <                    fail();
1059 <                } catch (IllegalArgumentException e) {
1091 <                    // expected
1092 <                }
1058 >                    shouldThrow();
1059 >                } catch (IllegalArgumentException success) {}
1060              }
1061          }
1062      }
# Line 1187 | Line 1154 | public class ConcurrentSkipListMapTest e
1154       */
1155      void check(NavigableMap<Integer, Integer> map,
1156                        final int min, final int max, final boolean ascending) {
1157 <       class ReferenceSet {
1157 >        class ReferenceSet {
1158              int lower(int key) {
1159                  return ascending ? lowerAscending(key) : higherAscending(key);
1160              }
# Line 1218 | Line 1185 | public class ConcurrentSkipListMapTest e
1185                  // BitSet should support this! Test would run much faster
1186                  while (key >= min) {
1187                      if (bs.get(key))
1188 <                        return(key);
1188 >                        return key;
1189                      key--;
1190                  }
1191                  return -1;
# Line 1284 | Line 1251 | public class ConcurrentSkipListMapTest e
1251              assertEq(rs.last(),  -1);
1252              try {
1253                  map.firstKey();
1254 <                fail();
1255 <            } catch (NoSuchElementException e) {
1289 <                // expected
1290 <            }
1254 >                shouldThrow();
1255 >            } catch (NoSuchElementException success) {}
1256              try {
1257                  map.lastKey();
1258 <                fail();
1259 <            } catch (NoSuchElementException e) {
1295 <                // expected
1296 <            }
1258 >                shouldThrow();
1259 >            } catch (NoSuchElementException success) {}
1260          }
1261      }
1262  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines