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

Comparing jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java (file contents):
Revision 1.7 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.36 by jsr166, Sat Mar 11 18:20:46 2017 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.Arrays;
8 > import java.util.Comparator;
9 > import java.util.Iterator;
10 > import java.util.NavigableSet;
11 > import java.util.SortedSet;
12 > import java.util.concurrent.ConcurrentSkipListSet;
13 >
14 > import junit.framework.Test;
15 > import junit.framework.TestSuite;
16  
17   public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
18      public static void main(String[] args) {
19 <        junit.textui.TestRunner.run (suite());
19 >        main(suite(), args);
20      }
21      public static Test suite() {
22 <        return new TestSuite(ConcurrentSkipListSubSetTest.class);
22 >        return new TestSuite(ConcurrentSkipListSubSetTest.class);
23      }
24  
25      static class MyReverseComparator implements Comparator {
26          public int compare(Object x, Object y) {
27 <            int i = ((Integer)x).intValue();
23 <            int j = ((Integer)y).intValue();
24 <            if (i < j) return 1;
25 <            if (i > j) return -1;
26 <            return 0;
27 >            return ((Comparable)y).compareTo(x);
28          }
29      }
30  
31      /**
32 <     * Create a set of given size containing consecutive
33 <     * Integers 0 ... n.
32 >     * Returns a new set of given size containing consecutive
33 >     * Integers 0 ... n - 1.
34       */
35 <    private NavigableSet populatedSet(int n) {
36 <        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
35 >    private static NavigableSet<Integer> populatedSet(int n) {
36 >        ConcurrentSkipListSet<Integer> q =
37 >            new ConcurrentSkipListSet<Integer>();
38          assertTrue(q.isEmpty());
39  
40 <        for (int i = n-1; i >= 0; i-=2)
41 <            assertTrue(q.add(new Integer(i)));
42 <        for (int i = (n & 1); i < n; i+=2)
43 <            assertTrue(q.add(new Integer(i)));
40 >        for (int i = n - 1; i >= 0; i -= 2)
41 >            assertTrue(q.add(new Integer(i)));
42 >        for (int i = (n & 1); i < n; i += 2)
43 >            assertTrue(q.add(new Integer(i)));
44          assertTrue(q.add(new Integer(-n)));
45          assertTrue(q.add(new Integer(n)));
46          NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
47          assertFalse(s.isEmpty());
48 <        assertEquals(n, s.size());
48 >        assertEquals(n, s.size());
49          return s;
50      }
51  
52      /**
53 <     * Create set of first 5 ints
53 >     * Returns a new set of first 5 ints.
54       */
55 <    private NavigableSet set5() {
55 >    private static NavigableSet set5() {
56          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
57          assertTrue(q.isEmpty());
58          q.add(one);
# Line 61 | Line 63 | public class ConcurrentSkipListSubSetTes
63          q.add(zero);
64          q.add(seven);
65          NavigableSet s = q.subSet(one, true, seven, false);
66 <        assertEquals(5, s.size());
66 >        assertEquals(5, s.size());
67          return s;
68      }
69  
70      /**
71 <     * Create set of first 5 negative ints
71 >     * Returns a new set of first 5 negative ints.
72       */
73 <    private NavigableSet dset5() {
73 >    private static NavigableSet dset5() {
74          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
75          assertTrue(q.isEmpty());
76          q.add(m1);
# Line 77 | Line 79 | public class ConcurrentSkipListSubSetTes
79          q.add(m4);
80          q.add(m5);
81          NavigableSet s = q.descendingSet();
82 <        assertEquals(5, s.size());
82 >        assertEquals(5, s.size());
83          return s;
84      }
85  
86      private static NavigableSet set0() {
87 <        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
87 >        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
88          assertTrue(set.isEmpty());
89          return set.tailSet(m1, true);
90      }
91  
92      private static NavigableSet dset0() {
93 <        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
93 >        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
94          assertTrue(set.isEmpty());
95          return set;
96      }
# Line 100 | Line 102 | public class ConcurrentSkipListSubSetTes
102          assertEquals(0, set0().size());
103      }
104  
103
105      /**
106       * isEmpty is true before add, false after
107       */
# Line 121 | Line 122 | public class ConcurrentSkipListSubSetTes
122      public void testSize() {
123          NavigableSet q = populatedSet(SIZE);
124          for (int i = 0; i < SIZE; ++i) {
125 <            assertEquals(SIZE-i, q.size());
125 >            assertEquals(SIZE - i, q.size());
126              q.pollFirst();
127          }
128          for (int i = 0; i < SIZE; ++i) {
# Line 134 | Line 135 | public class ConcurrentSkipListSubSetTes
135       * add(null) throws NPE
136       */
137      public void testAddNull() {
138 <        try {
139 <            NavigableSet q = set0();
138 >        NavigableSet q = set0();
139 >        try {
140              q.add(null);
141              shouldThrow();
142 <        } catch (NullPointerException success) { }
142 >        } catch (NullPointerException success) {}
143      }
144  
145      /**
# Line 162 | Line 163 | public class ConcurrentSkipListSubSetTes
163       * Add of non-Comparable throws CCE
164       */
165      public void testAddNonComparable() {
166 +        NavigableSet q = set0();
167          try {
166            NavigableSet q = set0();
167            q.add(new Object());
168              q.add(new Object());
169              q.add(new Object());
170              shouldThrow();
171 <        }
172 <        catch (ClassCastException success) {}
171 >        } catch (ClassCastException success) {}
172      }
173  
175
174      /**
175       * addAll(null) throws NPE
176       */
177      public void testAddAll1() {
178 +        NavigableSet q = set0();
179          try {
181            NavigableSet q = set0();
180              q.addAll(null);
181              shouldThrow();
182 <        }
185 <        catch (NullPointerException success) {}
182 >        } catch (NullPointerException success) {}
183      }
184 +
185      /**
186       * addAll of a collection with null elements throws NPE
187       */
188      public void testAddAll2() {
189 +        NavigableSet q = set0();
190 +        Integer[] ints = new Integer[SIZE];
191          try {
192            NavigableSet q = set0();
193            Integer[] ints = new Integer[SIZE];
192              q.addAll(Arrays.asList(ints));
193              shouldThrow();
194 <        }
197 <        catch (NullPointerException success) {}
194 >        } catch (NullPointerException success) {}
195      }
196 +
197      /**
198       * addAll of a collection with any null elements throws NPE after
199       * possibly adding some elements
200       */
201      public void testAddAll3() {
202 +        NavigableSet q = set0();
203 +        Integer[] ints = new Integer[SIZE];
204 +        for (int i = 0; i < SIZE - 1; ++i)
205 +            ints[i] = new Integer(i + SIZE);
206          try {
205            NavigableSet q = set0();
206            Integer[] ints = new Integer[SIZE];
207            for (int i = 0; i < SIZE-1; ++i)
208                ints[i] = new Integer(i+SIZE);
207              q.addAll(Arrays.asList(ints));
208              shouldThrow();
209 <        }
212 <        catch (NullPointerException success) {}
209 >        } catch (NullPointerException success) {}
210      }
211  
212      /**
213       * Set contains all elements of successful addAll
214       */
215      public void testAddAll5() {
216 <        try {
217 <            Integer[] empty = new Integer[0];
218 <            Integer[] ints = new Integer[SIZE];
219 <            for (int i = 0; i < SIZE; ++i)
220 <                ints[i] = new Integer(SIZE-1- i);
221 <            NavigableSet q = set0();
222 <            assertFalse(q.addAll(Arrays.asList(empty)));
223 <            assertTrue(q.addAll(Arrays.asList(ints)));
224 <            for (int i = 0; i < SIZE; ++i)
228 <                assertEquals(new Integer(i), q.pollFirst());
229 <        }
230 <        finally {}
216 >        Integer[] empty = new Integer[0];
217 >        Integer[] ints = new Integer[SIZE];
218 >        for (int i = 0; i < SIZE; ++i)
219 >            ints[i] = new Integer(SIZE - 1 - i);
220 >        NavigableSet q = set0();
221 >        assertFalse(q.addAll(Arrays.asList(empty)));
222 >        assertTrue(q.addAll(Arrays.asList(ints)));
223 >        for (int i = 0; i < SIZE; ++i)
224 >            assertEquals(new Integer(i), q.pollFirst());
225      }
226  
227      /**
# Line 236 | Line 230 | public class ConcurrentSkipListSubSetTes
230      public void testPoll() {
231          NavigableSet q = populatedSet(SIZE);
232          for (int i = 0; i < SIZE; ++i) {
233 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
233 >            assertEquals(i, q.pollFirst());
234          }
235 <        assertNull(q.pollFirst());
235 >        assertNull(q.pollFirst());
236      }
237  
238      /**
# Line 246 | Line 240 | public class ConcurrentSkipListSubSetTes
240       */
241      public void testRemoveElement() {
242          NavigableSet q = populatedSet(SIZE);
243 <        for (int i = 1; i < SIZE; i+=2) {
244 <            assertTrue(q.remove(new Integer(i)));
245 <        }
246 <        for (int i = 0; i < SIZE; i+=2) {
247 <            assertTrue(q.remove(new Integer(i)));
248 <            assertFalse(q.remove(new Integer(i+1)));
243 >        for (int i = 1; i < SIZE; i += 2) {
244 >            assertTrue(q.contains(i));
245 >            assertTrue(q.remove(i));
246 >            assertFalse(q.contains(i));
247 >            assertTrue(q.contains(i - 1));
248 >        }
249 >        for (int i = 0; i < SIZE; i += 2) {
250 >            assertTrue(q.contains(i));
251 >            assertTrue(q.remove(i));
252 >            assertFalse(q.contains(i));
253 >            assertFalse(q.remove(i + 1));
254 >            assertFalse(q.contains(i + 1));
255          }
256          assertTrue(q.isEmpty());
257      }
# Line 310 | Line 310 | public class ConcurrentSkipListSubSetTes
310                  assertTrue(changed);
311  
312              assertTrue(q.containsAll(p));
313 <            assertEquals(SIZE-i, q.size());
313 >            assertEquals(SIZE - i, q.size());
314              p.pollFirst();
315          }
316      }
# Line 323 | Line 323 | public class ConcurrentSkipListSubSetTes
323              NavigableSet q = populatedSet(SIZE);
324              NavigableSet p = populatedSet(i);
325              assertTrue(q.removeAll(p));
326 <            assertEquals(SIZE-i, q.size());
326 >            assertEquals(SIZE - i, q.size());
327              for (int j = 0; j < i; ++j) {
328 <                Integer I = (Integer)(p.pollFirst());
329 <                assertFalse(q.contains(I));
328 >                Integer x = (Integer)(p.pollFirst());
329 >                assertFalse(q.contains(x));
330              }
331          }
332      }
333  
334
335
334      /**
335       * lower returns preceding element
336       */
# Line 349 | Line 347 | public class ConcurrentSkipListSubSetTes
347  
348          Object e4 = q.lower(zero);
349          assertNull(e4);
352
350      }
351  
352      /**
# Line 368 | Line 365 | public class ConcurrentSkipListSubSetTes
365  
366          Object e4 = q.higher(six);
367          assertNull(e4);
371
368      }
369  
370      /**
# Line 387 | Line 383 | public class ConcurrentSkipListSubSetTes
383  
384          Object e4 = q.floor(zero);
385          assertNull(e4);
390
386      }
387  
388      /**
# Line 406 | Line 401 | public class ConcurrentSkipListSubSetTes
401  
402          Object e4 = q.ceiling(six);
403          assertNull(e4);
409
404      }
405  
406      /**
407 <     * toArray contains all elements
407 >     * toArray contains all elements in sorted order
408       */
409      public void testToArray() {
410          NavigableSet q = populatedSet(SIZE);
411 <        Object[] o = q.toArray();
412 <        Arrays.sort(o);
413 <        for (int i = 0; i < o.length; i++)
420 <            assertEquals(o[i], q.pollFirst());
411 >        Object[] o = q.toArray();
412 >        for (int i = 0; i < o.length; i++)
413 >            assertSame(o[i], q.pollFirst());
414      }
415  
416      /**
417 <     * toArray(a) contains all elements
417 >     * toArray(a) contains all elements in sorted order
418       */
419      public void testToArray2() {
420 <        NavigableSet q = populatedSet(SIZE);
421 <        Integer[] ints = new Integer[SIZE];
422 <        ints = (Integer[])q.toArray(ints);
423 <        Arrays.sort(ints);
420 >        NavigableSet<Integer> q = populatedSet(SIZE);
421 >        Integer[] ints = new Integer[SIZE];
422 >        Integer[] array = q.toArray(ints);
423 >        assertSame(ints, array);
424          for (int i = 0; i < ints.length; i++)
425 <            assertEquals(ints[i], q.pollFirst());
425 >            assertSame(ints[i], q.pollFirst());
426      }
427  
428      /**
# Line 437 | Line 430 | public class ConcurrentSkipListSubSetTes
430       */
431      public void testIterator() {
432          NavigableSet q = populatedSet(SIZE);
433 <        int i = 0;
434 <        Iterator it = q.iterator();
435 <        while (it.hasNext()) {
433 >        Iterator it = q.iterator();
434 >        int i;
435 >        for (i = 0; it.hasNext(); i++)
436              assertTrue(q.contains(it.next()));
444            ++i;
445        }
437          assertEquals(i, SIZE);
438 +        assertIteratorExhausted(it);
439      }
440  
441      /**
442       * iterator of empty set has no elements
443       */
444      public void testEmptyIterator() {
445 <        NavigableSet q = set0();
454 <        int i = 0;
455 <        Iterator it = q.iterator();
456 <        while (it.hasNext()) {
457 <            assertTrue(q.contains(it.next()));
458 <            ++i;
459 <        }
460 <        assertEquals(i, 0);
445 >        assertIteratorExhausted(set0().iterator());
446      }
447  
448      /**
449       * iterator.remove removes current element
450       */
451 <    public void testIteratorRemove () {
451 >    public void testIteratorRemove() {
452          final NavigableSet q = set0();
453          q.add(new Integer(2));
454          q.add(new Integer(1));
# Line 479 | Line 464 | public class ConcurrentSkipListSubSetTes
464          assertFalse(it.hasNext());
465      }
466  
482
467      /**
468       * toString contains toStrings of elements
469       */
# Line 487 | Line 471 | public class ConcurrentSkipListSubSetTes
471          NavigableSet q = populatedSet(SIZE);
472          String s = q.toString();
473          for (int i = 0; i < SIZE; ++i) {
474 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
474 >            assertTrue(s.contains(String.valueOf(i)));
475          }
476      }
477  
478      /**
479       * A deserialized serialized set has same elements
480       */
481 <    public void testSerialization() {
482 <        NavigableSet q = populatedSet(SIZE);
483 <        try {
484 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
485 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
486 <            out.writeObject(q);
487 <            out.close();
488 <
489 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
490 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
491 <            NavigableSet r = (NavigableSet)in.readObject();
508 <            assertEquals(q.size(), r.size());
509 <            while (!q.isEmpty())
510 <                assertEquals(q.pollFirst(), r.pollFirst());
511 <        } catch (Exception e) {
512 <            e.printStackTrace();
513 <            unexpectedException();
481 >    public void testSerialization() throws Exception {
482 >        NavigableSet x = populatedSet(SIZE);
483 >        NavigableSet y = serialClone(x);
484 >
485 >        assertNotSame(y, x);
486 >        assertEquals(x.size(), y.size());
487 >        assertEquals(x, y);
488 >        assertEquals(y, x);
489 >        while (!x.isEmpty()) {
490 >            assertFalse(y.isEmpty());
491 >            assertEquals(x.pollFirst(), y.pollFirst());
492          }
493 +        assertTrue(y.isEmpty());
494      }
495  
496      /**
# Line 639 | Line 618 | public class ConcurrentSkipListSubSetTes
618      public void testDescendingSize() {
619          NavigableSet q = populatedSet(SIZE);
620          for (int i = 0; i < SIZE; ++i) {
621 <            assertEquals(SIZE-i, q.size());
621 >            assertEquals(SIZE - i, q.size());
622              q.pollFirst();
623          }
624          for (int i = 0; i < SIZE; ++i) {
# Line 652 | Line 631 | public class ConcurrentSkipListSubSetTes
631       * add(null) throws NPE
632       */
633      public void testDescendingAddNull() {
634 <        try {
635 <            NavigableSet q = dset0();
634 >        NavigableSet q = dset0();
635 >        try {
636              q.add(null);
637              shouldThrow();
638 <        } catch (NullPointerException success) { }
638 >        } catch (NullPointerException success) {}
639      }
640  
641      /**
# Line 680 | Line 659 | public class ConcurrentSkipListSubSetTes
659       * Add of non-Comparable throws CCE
660       */
661      public void testDescendingAddNonComparable() {
662 +        NavigableSet q = dset0();
663          try {
684            NavigableSet q = dset0();
685            q.add(new Object());
664              q.add(new Object());
665              q.add(new Object());
666              shouldThrow();
667 <        }
690 <        catch (ClassCastException success) {}
667 >        } catch (ClassCastException success) {}
668      }
669  
693
670      /**
671       * addAll(null) throws NPE
672       */
673      public void testDescendingAddAll1() {
674 +        NavigableSet q = dset0();
675          try {
699            NavigableSet q = dset0();
676              q.addAll(null);
677              shouldThrow();
678 <        }
703 <        catch (NullPointerException success) {}
678 >        } catch (NullPointerException success) {}
679      }
680 +
681      /**
682       * addAll of a collection with null elements throws NPE
683       */
684      public void testDescendingAddAll2() {
685 +        NavigableSet q = dset0();
686 +        Integer[] ints = new Integer[SIZE];
687          try {
710            NavigableSet q = dset0();
711            Integer[] ints = new Integer[SIZE];
688              q.addAll(Arrays.asList(ints));
689              shouldThrow();
690 <        }
715 <        catch (NullPointerException success) {}
690 >        } catch (NullPointerException success) {}
691      }
692 +
693      /**
694       * addAll of a collection with any null elements throws NPE after
695       * possibly adding some elements
696       */
697      public void testDescendingAddAll3() {
698 +        NavigableSet q = dset0();
699 +        Integer[] ints = new Integer[SIZE];
700 +        for (int i = 0; i < SIZE - 1; ++i)
701 +            ints[i] = new Integer(i + SIZE);
702          try {
723            NavigableSet q = dset0();
724            Integer[] ints = new Integer[SIZE];
725            for (int i = 0; i < SIZE-1; ++i)
726                ints[i] = new Integer(i+SIZE);
703              q.addAll(Arrays.asList(ints));
704              shouldThrow();
705 <        }
730 <        catch (NullPointerException success) {}
705 >        } catch (NullPointerException success) {}
706      }
707  
708      /**
709       * Set contains all elements of successful addAll
710       */
711      public void testDescendingAddAll5() {
712 <        try {
713 <            Integer[] empty = new Integer[0];
714 <            Integer[] ints = new Integer[SIZE];
715 <            for (int i = 0; i < SIZE; ++i)
716 <                ints[i] = new Integer(SIZE-1- i);
717 <            NavigableSet q = dset0();
718 <            assertFalse(q.addAll(Arrays.asList(empty)));
719 <            assertTrue(q.addAll(Arrays.asList(ints)));
720 <            for (int i = 0; i < SIZE; ++i)
746 <                assertEquals(new Integer(i), q.pollFirst());
747 <        }
748 <        finally {}
712 >        Integer[] empty = new Integer[0];
713 >        Integer[] ints = new Integer[SIZE];
714 >        for (int i = 0; i < SIZE; ++i)
715 >            ints[i] = new Integer(SIZE - 1 - i);
716 >        NavigableSet q = dset0();
717 >        assertFalse(q.addAll(Arrays.asList(empty)));
718 >        assertTrue(q.addAll(Arrays.asList(ints)));
719 >        for (int i = 0; i < SIZE; ++i)
720 >            assertEquals(new Integer(i), q.pollFirst());
721      }
722  
723      /**
# Line 754 | Line 726 | public class ConcurrentSkipListSubSetTes
726      public void testDescendingPoll() {
727          NavigableSet q = populatedSet(SIZE);
728          for (int i = 0; i < SIZE; ++i) {
729 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
729 >            assertEquals(i, q.pollFirst());
730          }
731 <        assertNull(q.pollFirst());
731 >        assertNull(q.pollFirst());
732      }
733  
734      /**
# Line 764 | Line 736 | public class ConcurrentSkipListSubSetTes
736       */
737      public void testDescendingRemoveElement() {
738          NavigableSet q = populatedSet(SIZE);
739 <        for (int i = 1; i < SIZE; i+=2) {
739 >        for (int i = 1; i < SIZE; i += 2) {
740              assertTrue(q.remove(new Integer(i)));
741          }
742 <        for (int i = 0; i < SIZE; i+=2) {
742 >        for (int i = 0; i < SIZE; i += 2 ) {
743              assertTrue(q.remove(new Integer(i)));
744 <            assertFalse(q.remove(new Integer(i+1)));
744 >            assertFalse(q.remove(new Integer(i + 1)));
745          }
746          assertTrue(q.isEmpty());
747      }
# Line 828 | Line 800 | public class ConcurrentSkipListSubSetTes
800                  assertTrue(changed);
801  
802              assertTrue(q.containsAll(p));
803 <            assertEquals(SIZE-i, q.size());
803 >            assertEquals(SIZE - i, q.size());
804              p.pollFirst();
805          }
806      }
# Line 841 | Line 813 | public class ConcurrentSkipListSubSetTes
813              NavigableSet q = populatedSet(SIZE);
814              NavigableSet p = populatedSet(i);
815              assertTrue(q.removeAll(p));
816 <            assertEquals(SIZE-i, q.size());
816 >            assertEquals(SIZE - i, q.size());
817              for (int j = 0; j < i; ++j) {
818 <                Integer I = (Integer)(p.pollFirst());
819 <                assertFalse(q.contains(I));
818 >                Integer x = (Integer)(p.pollFirst());
819 >                assertFalse(q.contains(x));
820              }
821          }
822      }
823  
852
853
824      /**
825       * lower returns preceding element
826       */
# Line 867 | Line 837 | public class ConcurrentSkipListSubSetTes
837  
838          Object e4 = q.lower(zero);
839          assertNull(e4);
870
840      }
841  
842      /**
# Line 886 | Line 855 | public class ConcurrentSkipListSubSetTes
855  
856          Object e4 = q.higher(m6);
857          assertNull(e4);
889
858      }
859  
860      /**
# Line 905 | Line 873 | public class ConcurrentSkipListSubSetTes
873  
874          Object e4 = q.floor(zero);
875          assertNull(e4);
908
876      }
877  
878      /**
# Line 924 | Line 891 | public class ConcurrentSkipListSubSetTes
891  
892          Object e4 = q.ceiling(m6);
893          assertNull(e4);
927
894      }
895  
896      /**
# Line 932 | Line 898 | public class ConcurrentSkipListSubSetTes
898       */
899      public void testDescendingToArray() {
900          NavigableSet q = populatedSet(SIZE);
901 <        Object[] o = q.toArray();
901 >        Object[] o = q.toArray();
902          Arrays.sort(o);
903 <        for (int i = 0; i < o.length; i++)
904 <            assertEquals(o[i], q.pollFirst());
903 >        for (int i = 0; i < o.length; i++)
904 >            assertEquals(o[i], q.pollFirst());
905      }
906  
907      /**
# Line 943 | Line 909 | public class ConcurrentSkipListSubSetTes
909       */
910      public void testDescendingToArray2() {
911          NavigableSet q = populatedSet(SIZE);
912 <        Integer[] ints = new Integer[SIZE];
913 <        ints = (Integer[])q.toArray(ints);
912 >        Integer[] ints = new Integer[SIZE];
913 >        assertSame(ints, q.toArray(ints));
914          Arrays.sort(ints);
915          for (int i = 0; i < ints.length; i++)
916              assertEquals(ints[i], q.pollFirst());
# Line 956 | Line 922 | public class ConcurrentSkipListSubSetTes
922      public void testDescendingIterator() {
923          NavigableSet q = populatedSet(SIZE);
924          int i = 0;
925 <        Iterator it = q.iterator();
925 >        Iterator it = q.iterator();
926          while (it.hasNext()) {
927              assertTrue(q.contains(it.next()));
928              ++i;
# Line 970 | Line 936 | public class ConcurrentSkipListSubSetTes
936      public void testDescendingEmptyIterator() {
937          NavigableSet q = dset0();
938          int i = 0;
939 <        Iterator it = q.iterator();
939 >        Iterator it = q.iterator();
940          while (it.hasNext()) {
941              assertTrue(q.contains(it.next()));
942              ++i;
943          }
944 <        assertEquals(i, 0);
944 >        assertEquals(0, i);
945      }
946  
947      /**
948       * iterator.remove removes current element
949       */
950 <    public void testDescendingIteratorRemove () {
950 >    public void testDescendingIteratorRemove() {
951          final NavigableSet q = dset0();
952          q.add(new Integer(2));
953          q.add(new Integer(1));
# Line 997 | Line 963 | public class ConcurrentSkipListSubSetTes
963          assertFalse(it.hasNext());
964      }
965  
1000
966      /**
967       * toString contains toStrings of elements
968       */
# Line 1005 | Line 970 | public class ConcurrentSkipListSubSetTes
970          NavigableSet q = populatedSet(SIZE);
971          String s = q.toString();
972          for (int i = 0; i < SIZE; ++i) {
973 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
973 >            assertTrue(s.contains(String.valueOf(i)));
974          }
975      }
976  
977      /**
978       * A deserialized serialized set has same elements
979       */
980 <    public void testDescendingSerialization() {
981 <        NavigableSet q = populatedSet(SIZE);
982 <        try {
983 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
984 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
985 <            out.writeObject(q);
986 <            out.close();
987 <
988 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
989 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
990 <            NavigableSet r = (NavigableSet)in.readObject();
1026 <            assertEquals(q.size(), r.size());
1027 <            while (!q.isEmpty())
1028 <                assertEquals(q.pollFirst(), r.pollFirst());
1029 <        } catch (Exception e) {
1030 <            e.printStackTrace();
1031 <            unexpectedException();
980 >    public void testDescendingSerialization() throws Exception {
981 >        NavigableSet x = dset5();
982 >        NavigableSet y = serialClone(x);
983 >
984 >        assertNotSame(y, x);
985 >        assertEquals(x.size(), y.size());
986 >        assertEquals(x, y);
987 >        assertEquals(y, x);
988 >        while (!x.isEmpty()) {
989 >            assertFalse(y.isEmpty());
990 >            assertEquals(x.pollFirst(), y.pollFirst());
991          }
992 +        assertTrue(y.isEmpty());
993      }
994  
995      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines