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.7 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.11 by jsr166, Sun Nov 22 18:57:17 2009 UTC

# Line 19 | Line 19 | public class ConcurrentSkipListSetTest e
19  
20      static class MyReverseComparator implements Comparator {
21          public int compare(Object x, Object y) {
22 <            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;
22 >            return ((Comparable)y).compareTo(x);
23          }
24      }
25  
# Line 72 | Line 68 | public class ConcurrentSkipListSetTest e
68          try {
69              ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null);
70              shouldThrow();
71 <        }
76 <        catch (NullPointerException success) {}
71 >        } catch (NullPointerException success) {}
72      }
73  
74      /**
# Line 84 | Line 79 | public class ConcurrentSkipListSetTest e
79              Integer[] ints = new Integer[SIZE];
80              ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
81              shouldThrow();
82 <        }
88 <        catch (NullPointerException success) {}
82 >        } catch (NullPointerException success) {}
83      }
84  
85      /**
# Line 98 | Line 92 | public class ConcurrentSkipListSetTest e
92                  ints[i] = new Integer(i);
93              ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
94              shouldThrow();
95 <        }
102 <        catch (NullPointerException success) {}
95 >        } catch (NullPointerException success) {}
96      }
97  
98      /**
99       * Set contains all elements of collection used to initialize
100       */
101      public void testConstructor6() {
102 <        try {
103 <            Integer[] ints = new Integer[SIZE];
104 <            for (int i = 0; i < SIZE; ++i)
105 <                ints[i] = new Integer(i);
106 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
107 <            for (int i = 0; i < SIZE; ++i)
115 <                assertEquals(ints[i], q.pollFirst());
116 <        }
117 <        finally {}
102 >        Integer[] ints = new Integer[SIZE];
103 >        for (int i = 0; i < SIZE; ++i)
104 >            ints[i] = new Integer(i);
105 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
106 >        for (int i = 0; i < SIZE; ++i)
107 >            assertEquals(ints[i], q.pollFirst());
108      }
109  
110      /**
111       * The comparator used in constructor is used
112       */
113      public void testConstructor7() {
114 <        try {
115 <            MyReverseComparator cmp = new MyReverseComparator();
116 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp);
117 <            assertEquals(cmp, q.comparator());
118 <            Integer[] ints = new Integer[SIZE];
119 <            for (int i = 0; i < SIZE; ++i)
120 <                ints[i] = new Integer(i);
121 <            q.addAll(Arrays.asList(ints));
122 <            for (int i = SIZE-1; i >= 0; --i)
133 <                assertEquals(ints[i], q.pollFirst());
134 <        }
135 <        finally {}
114 >        MyReverseComparator cmp = new MyReverseComparator();
115 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp);
116 >        assertEquals(cmp, q.comparator());
117 >        Integer[] ints = new Integer[SIZE];
118 >        for (int i = 0; i < SIZE; ++i)
119 >            ints[i] = new Integer(i);
120 >        q.addAll(Arrays.asList(ints));
121 >        for (int i = SIZE-1; i >= 0; --i)
122 >            assertEquals(ints[i], q.pollFirst());
123      }
124  
125      /**
# Line 172 | Line 159 | public class ConcurrentSkipListSetTest e
159              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
160              q.add(null);
161              shouldThrow();
162 <        } catch (NullPointerException success) { }
162 >        } catch (NullPointerException success) {}
163      }
164  
165      /**
# Line 203 | Line 190 | public class ConcurrentSkipListSetTest e
190              q.add(new Object());
191              q.add(new Object());
192              shouldThrow();
193 <        }
207 <        catch (ClassCastException success) {}
193 >        } catch (ClassCastException success) {}
194      }
195  
196      /**
# Line 215 | Line 201 | public class ConcurrentSkipListSetTest e
201              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
202              q.addAll(null);
203              shouldThrow();
204 <        }
219 <        catch (NullPointerException success) {}
204 >        } catch (NullPointerException success) {}
205      }
206      /**
207       * addAll of a collection with null elements throws NPE
# Line 227 | Line 212 | public class ConcurrentSkipListSetTest e
212              Integer[] ints = new Integer[SIZE];
213              q.addAll(Arrays.asList(ints));
214              shouldThrow();
215 <        }
231 <        catch (NullPointerException success) {}
215 >        } catch (NullPointerException success) {}
216      }
217      /**
218       * addAll of a collection with any null elements throws NPE after
# Line 242 | Line 226 | public class ConcurrentSkipListSetTest e
226                  ints[i] = new Integer(i);
227              q.addAll(Arrays.asList(ints));
228              shouldThrow();
229 <        }
246 <        catch (NullPointerException success) {}
229 >        } catch (NullPointerException success) {}
230      }
231  
232      /**
233       * Set contains all elements of successful addAll
234       */
235      public void testAddAll5() {
236 <        try {
237 <            Integer[] empty = new Integer[0];
238 <            Integer[] ints = new Integer[SIZE];
239 <            for (int i = 0; i < SIZE; ++i)
240 <                ints[i] = new Integer(SIZE-1-i);
241 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
242 <            assertFalse(q.addAll(Arrays.asList(empty)));
243 <            assertTrue(q.addAll(Arrays.asList(ints)));
244 <            for (int i = 0; i < SIZE; ++i)
262 <                assertEquals(new Integer(i), q.pollFirst());
263 <        }
264 <        finally {}
236 >        Integer[] empty = new Integer[0];
237 >        Integer[] ints = new Integer[SIZE];
238 >        for (int i = 0; i < SIZE; ++i)
239 >            ints[i] = new Integer(SIZE-1-i);
240 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
241 >        assertFalse(q.addAll(Arrays.asList(empty)));
242 >        assertTrue(q.addAll(Arrays.asList(ints)));
243 >        for (int i = 0; i < SIZE; ++i)
244 >            assertEquals(i, q.pollFirst());
245      }
246  
247      /**
# Line 270 | Line 250 | public class ConcurrentSkipListSetTest e
250      public void testPollFirst() {
251          ConcurrentSkipListSet q = populatedSet(SIZE);
252          for (int i = 0; i < SIZE; ++i) {
253 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
253 >            assertEquals(i, q.pollFirst());
254          }
255          assertNull(q.pollFirst());
256      }
# Line 281 | Line 261 | public class ConcurrentSkipListSetTest e
261      public void testPollLast() {
262          ConcurrentSkipListSet q = populatedSet(SIZE);
263          for (int i = SIZE-1; i >= 0; --i) {
264 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
264 >            assertEquals(i, q.pollLast());
265          }
266          assertNull(q.pollFirst());
267      }
# Line 540 | Line 520 | public class ConcurrentSkipListSetTest e
520      /**
521       * A deserialized serialized set has same elements
522       */
523 <    public void testSerialization() {
523 >    public void testSerialization() throws Exception {
524          ConcurrentSkipListSet q = populatedSet(SIZE);
525 <        try {
526 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
527 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
528 <            out.writeObject(q);
529 <            out.close();
530 <
531 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
532 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
533 <            ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
534 <            assertEquals(q.size(), r.size());
535 <            while (!q.isEmpty())
556 <                assertEquals(q.pollFirst(), r.pollFirst());
557 <        } catch (Exception e) {
558 <            e.printStackTrace();
559 <            unexpectedException();
560 <        }
525 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
526 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
527 >        out.writeObject(q);
528 >        out.close();
529 >
530 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
531 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
532 >        ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
533 >        assertEquals(q.size(), r.size());
534 >        while (!q.isEmpty())
535 >            assertEquals(q.pollFirst(), r.pollFirst());
536      }
537  
538      /**
# Line 685 | Line 660 | public class ConcurrentSkipListSetTest e
660      /**
661       * Subsets of subsets subdivide correctly
662       */
663 <    public void testRecursiveSubSets() {
663 >    public void testRecursiveSubSets() throws Exception {
664          int setSize = 1000;
665          Class cl = ConcurrentSkipListSet.class;
666  
# Line 704 | Line 679 | public class ConcurrentSkipListSetTest e
679                     0, setSize - 1, true);
680      }
681  
682 <    static NavigableSet<Integer> newSet(Class cl) {
683 <        NavigableSet<Integer> result = null;
709 <        try {
710 <            result = (NavigableSet<Integer>) cl.newInstance();
711 <        } catch (Exception e) {
712 <            fail();
713 <        }
682 >    static NavigableSet<Integer> newSet(Class cl) throws Exception {
683 >        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
684          assertEquals(result.size(), 0);
685          assertFalse(result.iterator().hasNext());
686          return result;
# Line 773 | Line 743 | public class ConcurrentSkipListSetTest e
743              } else {
744                  try {
745                      set.add(element);
746 <                    fail();
747 <                } catch (IllegalArgumentException e) {
778 <                    // expected
779 <                }
746 >                    shouldThrow();
747 >                } catch (IllegalArgumentException success) {}
748              }
749          }
750      }
# Line 975 | Line 943 | public class ConcurrentSkipListSetTest e
943              assertEq(rs.last(),  -1);
944              try {
945                  set.first();
946 <                fail();
947 <            } catch (NoSuchElementException e) {
980 <                // expected
981 <            }
946 >                shouldThrow();
947 >            } catch (NoSuchElementException success) {}
948              try {
949                  set.last();
950 <                fail();
951 <            } catch (NoSuchElementException e) {
986 <                // expected
987 <            }
950 >                shouldThrow();
951 >            } catch (NoSuchElementException success) {}
952          }
953      }
954  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines