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

Comparing jsr166/src/test/tck/ConcurrentSkipListSetTest.java (file contents):
Revision 1.6 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.8 by jsr166, Sat Nov 21 10:25:05 2009 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListSetTest 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(ConcurrentSkipListSetTest.class);
17 >        return new TestSuite(ConcurrentSkipListSetTest.class);
18      }
19  
20      static class MyReverseComparator implements Comparator {
# Line 34 | Line 34 | public class ConcurrentSkipListSetTest e
34      private ConcurrentSkipListSet populatedSet(int n) {
35          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
36          assertTrue(q.isEmpty());
37 <        for (int i = n-1; i >= 0; i-=2)
38 <            assertTrue(q.add(new Integer(i)));
39 <        for (int i = (n & 1); i < n; i+=2)
40 <            assertTrue(q.add(new Integer(i)));
37 >        for (int i = n-1; i >= 0; i-=2)
38 >            assertTrue(q.add(new Integer(i)));
39 >        for (int i = (n & 1); i < n; i+=2)
40 >            assertTrue(q.add(new Integer(i)));
41          assertFalse(q.isEmpty());
42 <        assertEquals(n, q.size());
42 >        assertEquals(n, q.size());
43          return q;
44      }
45  
# Line 54 | Line 54 | public class ConcurrentSkipListSetTest e
54          q.add(three);
55          q.add(four);
56          q.add(five);
57 <        assertEquals(5, q.size());
57 >        assertEquals(5, q.size());
58          return q;
59      }
60  
# Line 72 | Line 72 | public class ConcurrentSkipListSetTest e
72          try {
73              ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null);
74              shouldThrow();
75 <        }
76 <        catch (NullPointerException success) {}
75 >        } catch (NullPointerException success) {}
76      }
77  
78      /**
# Line 84 | Line 83 | public class ConcurrentSkipListSetTest e
83              Integer[] ints = new Integer[SIZE];
84              ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
85              shouldThrow();
86 <        }
88 <        catch (NullPointerException success) {}
86 >        } catch (NullPointerException success) {}
87      }
88  
89      /**
# Line 98 | Line 96 | public class ConcurrentSkipListSetTest e
96                  ints[i] = new Integer(i);
97              ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
98              shouldThrow();
99 <        }
102 <        catch (NullPointerException success) {}
99 >        } catch (NullPointerException success) {}
100      }
101  
102      /**
103       * Set contains all elements of collection used to initialize
104       */
105      public void testConstructor6() {
106 <        try {
107 <            Integer[] ints = new Integer[SIZE];
108 <            for (int i = 0; i < SIZE; ++i)
109 <                ints[i] = new Integer(i);
110 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
111 <            for (int i = 0; i < SIZE; ++i)
115 <                assertEquals(ints[i], q.pollFirst());
116 <        }
117 <        finally {}
106 >        Integer[] ints = new Integer[SIZE];
107 >        for (int i = 0; i < SIZE; ++i)
108 >            ints[i] = new Integer(i);
109 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
110 >        for (int i = 0; i < SIZE; ++i)
111 >            assertEquals(ints[i], q.pollFirst());
112      }
113  
114      /**
# Line 168 | Line 162 | public class ConcurrentSkipListSetTest e
162       * add(null) throws NPE
163       */
164      public void testAddNull() {
165 <        try {
165 >        try {
166              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
167              q.add(null);
168              shouldThrow();
169 <        } catch (NullPointerException success) { }
169 >        } catch (NullPointerException success) {}
170      }
171  
172      /**
# Line 203 | Line 197 | public class ConcurrentSkipListSetTest e
197              q.add(new Object());
198              q.add(new Object());
199              shouldThrow();
200 <        }
207 <        catch (ClassCastException success) {}
200 >        } catch (ClassCastException success) {}
201      }
202  
203      /**
# Line 215 | Line 208 | public class ConcurrentSkipListSetTest e
208              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
209              q.addAll(null);
210              shouldThrow();
211 <        }
219 <        catch (NullPointerException success) {}
211 >        } catch (NullPointerException success) {}
212      }
213      /**
214       * addAll of a collection with null elements throws NPE
# Line 227 | Line 219 | public class ConcurrentSkipListSetTest e
219              Integer[] ints = new Integer[SIZE];
220              q.addAll(Arrays.asList(ints));
221              shouldThrow();
222 <        }
231 <        catch (NullPointerException success) {}
222 >        } catch (NullPointerException success) {}
223      }
224      /**
225       * addAll of a collection with any null elements throws NPE after
# Line 242 | Line 233 | public class ConcurrentSkipListSetTest e
233                  ints[i] = new Integer(i);
234              q.addAll(Arrays.asList(ints));
235              shouldThrow();
236 <        }
246 <        catch (NullPointerException success) {}
236 >        } catch (NullPointerException success) {}
237      }
238  
239      /**
# Line 272 | Line 262 | public class ConcurrentSkipListSetTest e
262          for (int i = 0; i < SIZE; ++i) {
263              assertEquals(i, ((Integer)q.pollFirst()).intValue());
264          }
265 <        assertNull(q.pollFirst());
265 >        assertNull(q.pollFirst());
266      }
267  
268      /**
# Line 283 | Line 273 | public class ConcurrentSkipListSetTest e
273          for (int i = SIZE-1; i >= 0; --i) {
274              assertEquals(i, ((Integer)q.pollLast()).intValue());
275          }
276 <        assertNull(q.pollFirst());
276 >        assertNull(q.pollFirst());
277      }
278  
279  
# Line 460 | Line 450 | public class ConcurrentSkipListSetTest e
450       */
451      public void testToArray() {
452          ConcurrentSkipListSet q = populatedSet(SIZE);
453 <        Object[] o = q.toArray();
453 >        Object[] o = q.toArray();
454          Arrays.sort(o);
455 <        for (int i = 0; i < o.length; i++)
456 <            assertEquals(o[i], q.pollFirst());
455 >        for (int i = 0; i < o.length; i++)
456 >            assertEquals(o[i], q.pollFirst());
457      }
458  
459      /**
# Line 471 | Line 461 | public class ConcurrentSkipListSetTest e
461       */
462      public void testToArray2() {
463          ConcurrentSkipListSet q = populatedSet(SIZE);
464 <        Integer[] ints = new Integer[SIZE];
465 <        ints = (Integer[])q.toArray(ints);
464 >        Integer[] ints = new Integer[SIZE];
465 >        ints = (Integer[])q.toArray(ints);
466          Arrays.sort(ints);
467          for (int i = 0; i < ints.length; i++)
468              assertEquals(ints[i], q.pollFirst());
# Line 484 | Line 474 | public class ConcurrentSkipListSetTest e
474      public void testIterator() {
475          ConcurrentSkipListSet q = populatedSet(SIZE);
476          int i = 0;
477 <        Iterator it = q.iterator();
477 >        Iterator it = q.iterator();
478          while (it.hasNext()) {
479              assertTrue(q.contains(it.next()));
480              ++i;
# Line 498 | Line 488 | public class ConcurrentSkipListSetTest e
488      public void testEmptyIterator() {
489          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
490          int i = 0;
491 <        Iterator it = q.iterator();
491 >        Iterator it = q.iterator();
492          while (it.hasNext()) {
493              assertTrue(q.contains(it.next()));
494              ++i;
# Line 540 | Line 530 | public class ConcurrentSkipListSetTest e
530      /**
531       * A deserialized serialized set has same elements
532       */
533 <    public void testSerialization() {
533 >    public void testSerialization() throws Exception {
534          ConcurrentSkipListSet q = populatedSet(SIZE);
535 <        try {
536 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
537 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
538 <            out.writeObject(q);
539 <            out.close();
540 <
541 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
542 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
543 <            ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
544 <            assertEquals(q.size(), r.size());
545 <            while (!q.isEmpty())
556 <                assertEquals(q.pollFirst(), r.pollFirst());
557 <        } catch (Exception e) {
558 <            e.printStackTrace();
559 <            unexpectedException();
560 <        }
535 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
536 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
537 >        out.writeObject(q);
538 >        out.close();
539 >
540 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
541 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
542 >        ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
543 >        assertEquals(q.size(), r.size());
544 >        while (!q.isEmpty())
545 >            assertEquals(q.pollFirst(), r.pollFirst());
546      }
547  
548      /**
# Line 686 | Line 671 | public class ConcurrentSkipListSetTest e
671       * Subsets of subsets subdivide correctly
672       */
673      public void testRecursiveSubSets() {
674 <        int setSize = 1000;
675 <        Class cl = ConcurrentSkipListSet.class;
674 >        int setSize = 1000;
675 >        Class cl = ConcurrentSkipListSet.class;
676  
677          NavigableSet<Integer> set = newSet(cl);
678          bs = new BitSet(setSize);
# Line 706 | Line 691 | public class ConcurrentSkipListSetTest e
691  
692      static NavigableSet<Integer> newSet(Class cl) {
693          NavigableSet<Integer> result = null;
694 <        try {
694 >        try {
695              result = (NavigableSet<Integer>) cl.newInstance();
696 <        } catch (Exception e) {
696 >        } catch (Exception e) {
697              fail();
698 <        }
698 >        }
699          assertEquals(result.size(), 0);
700          assertFalse(result.iterator().hasNext());
701          return result;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines