--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2009/11/21 10:29:50 1.9 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2010/08/25 00:07:03 1.13 @@ -11,7 +11,7 @@ import java.io.*; public class ConcurrentSkipListSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(ConcurrentSkipListSetTest.class); @@ -19,11 +19,7 @@ public class ConcurrentSkipListSetTest e static class MyReverseComparator implements Comparator { public int compare(Object x, Object y) { - int i = ((Integer)x).intValue(); - int j = ((Integer)y).intValue(); - if (i < j) return 1; - if (i > j) return -1; - return 0; + return ((Comparable)y).compareTo(x); } } @@ -245,7 +241,7 @@ public class ConcurrentSkipListSetTest e assertFalse(q.addAll(Arrays.asList(empty))); assertTrue(q.addAll(Arrays.asList(ints))); for (int i = 0; i < SIZE; ++i) - assertEquals(new Integer(i), q.pollFirst()); + assertEquals(i, q.pollFirst()); } /** @@ -254,7 +250,7 @@ public class ConcurrentSkipListSetTest e public void testPollFirst() { ConcurrentSkipListSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst()).intValue()); + assertEquals(i, q.pollFirst()); } assertNull(q.pollFirst()); } @@ -265,7 +261,7 @@ public class ConcurrentSkipListSetTest e public void testPollLast() { ConcurrentSkipListSet q = populatedSet(SIZE); for (int i = SIZE-1; i >= 0; --i) { - assertEquals(i, ((Integer)q.pollLast()).intValue()); + assertEquals(i, q.pollLast()); } assertNull(q.pollFirst()); } @@ -379,7 +375,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.lower(zero); assertNull(e4); - } /** @@ -398,7 +393,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.higher(six); assertNull(e4); - } /** @@ -417,7 +411,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.floor(zero); assertNull(e4); - } /** @@ -436,7 +429,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.ceiling(six); assertNull(e4); - } /** @@ -493,7 +485,7 @@ public class ConcurrentSkipListSetTest e /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.add(new Integer(2)); q.add(new Integer(1)); @@ -664,7 +656,7 @@ public class ConcurrentSkipListSetTest e /** * Subsets of subsets subdivide correctly */ - public void testRecursiveSubSets() { + public void testRecursiveSubSets() throws Exception { int setSize = 1000; Class cl = ConcurrentSkipListSet.class; @@ -683,13 +675,8 @@ public class ConcurrentSkipListSetTest e 0, setSize - 1, true); } - static NavigableSet newSet(Class cl) { - NavigableSet result = null; - try { - result = (NavigableSet) cl.newInstance(); - } catch (Exception e) { - fail(); - } + static NavigableSet newSet(Class cl) throws Exception { + NavigableSet result = (NavigableSet) cl.newInstance(); assertEquals(result.size(), 0); assertFalse(result.iterator().hasNext()); return result; @@ -752,10 +739,8 @@ public class ConcurrentSkipListSetTest e } else { try { set.add(element); - fail(); - } catch (IllegalArgumentException e) { - // expected - } + shouldThrow(); + } catch (IllegalArgumentException success) {} } } } @@ -954,16 +939,12 @@ public class ConcurrentSkipListSetTest e assertEq(rs.last(), -1); try { set.first(); - fail(); - } catch (NoSuchElementException e) { - // expected - } + shouldThrow(); + } catch (NoSuchElementException success) {} try { set.last(); - fail(); - } catch (NoSuchElementException e) { - // expected - } + shouldThrow(); + } catch (NoSuchElementException success) {} } }