--- jsr166/src/test/tck/LinkedListTest.java 2009/11/16 05:30:07 1.12 +++ jsr166/src/test/tck/LinkedListTest.java 2009/11/21 10:25:05 1.15 @@ -12,11 +12,11 @@ import java.util.concurrent.*; public class LinkedListTest 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(LinkedListTest.class); + return new TestSuite(LinkedListTest.class); } /** @@ -26,10 +26,10 @@ public class LinkedListTest extends JSR1 private LinkedList populatedQueue(int n) { LinkedList q = new LinkedList(); assertTrue(q.isEmpty()); - for (int i = 0; i < n; ++i) - assertTrue(q.offer(new Integer(i))); + for (int i = 0; i < n; ++i) + assertTrue(q.offer(new Integer(i))); assertFalse(q.isEmpty()); - assertEquals(n, q.size()); + assertEquals(n, q.size()); return q; } @@ -47,24 +47,19 @@ public class LinkedListTest extends JSR1 try { LinkedList q = new LinkedList((Collection)null); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** * Queue contains all elements of collection used to initialize - */ public void testConstructor6() { - try { - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(i); - LinkedList q = new LinkedList(Arrays.asList(ints)); - for (int i = 0; i < SIZE; ++i) - assertEquals(ints[i], q.poll()); - } - finally {} + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(i); + LinkedList q = new LinkedList(Arrays.asList(ints)); + for (int i = 0; i < SIZE; ++i) + assertEquals(ints[i], q.poll()); } /** @@ -100,12 +95,8 @@ public class LinkedListTest extends JSR1 * offer(null) succeeds */ public void testOfferNull() { - try { - LinkedList q = new LinkedList(); - q.offer(null); - } catch (NullPointerException ie) { - unexpectedException(); - } + LinkedList q = new LinkedList(); + q.offer(null); } /** @@ -136,54 +127,50 @@ public class LinkedListTest extends JSR1 LinkedList q = new LinkedList(); q.addAll(null); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** * Queue contains all elements, in traversal order, of successful addAll */ public void testAddAll5() { - try { - Integer[] empty = new Integer[0]; - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(i); - LinkedList q = new LinkedList(); - assertFalse(q.addAll(Arrays.asList(empty))); - assertTrue(q.addAll(Arrays.asList(ints))); - for (int i = 0; i < SIZE; ++i) - assertEquals(ints[i], q.poll()); - } - finally {} + Integer[] empty = new Integer[0]; + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(i); + LinkedList q = new LinkedList(); + assertFalse(q.addAll(Arrays.asList(empty))); + assertTrue(q.addAll(Arrays.asList(ints))); + for (int i = 0; i < SIZE; ++i) + assertEquals(ints[i], q.poll()); } /** * addAll with too large an index throws IOOBE */ public void testAddAll2_IndexOutOfBoundsException() { - try { - LinkedList l = new LinkedList(); - l.add(new Object()); - LinkedList m = new LinkedList(); - m.add(new Object()); - l.addAll(4,m); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} + LinkedList l = new LinkedList(); + l.add(new Object()); + LinkedList m = new LinkedList(); + m.add(new Object()); + try { + l.addAll(4,m); + shouldThrow(); + } catch (IndexOutOfBoundsException success) {} } /** * addAll with negative index throws IOOBE */ public void testAddAll4_BadIndex() { - try { - LinkedList l = new LinkedList(); - l.add(new Object()); - LinkedList m = new LinkedList(); - m.add(new Object()); - l.addAll(-1,m); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} + LinkedList l = new LinkedList(); + l.add(new Object()); + LinkedList m = new LinkedList(); + m.add(new Object()); + try { + l.addAll(-1,m); + shouldThrow(); + } catch (IndexOutOfBoundsException success) {} } /** @@ -194,7 +181,7 @@ public class LinkedListTest extends JSR1 for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.poll()).intValue()); } - assertNull(q.poll()); + assertNull(q.poll()); } /** @@ -208,7 +195,7 @@ public class LinkedListTest extends JSR1 assertTrue(q.peek() == null || i != ((Integer)q.peek()).intValue()); } - assertNull(q.peek()); + assertNull(q.peek()); } /** @@ -223,8 +210,7 @@ public class LinkedListTest extends JSR1 try { q.element(); shouldThrow(); - } - catch (NoSuchElementException success) {} + } catch (NoSuchElementException success) {} } /** @@ -238,8 +224,7 @@ public class LinkedListTest extends JSR1 try { q.remove(); shouldThrow(); - } catch (NoSuchElementException success) { - } + } catch (NoSuchElementException success) {} } /** @@ -337,10 +322,10 @@ public class LinkedListTest extends JSR1 */ public void testToArray() { LinkedList q = populatedQueue(SIZE); - Object[] o = q.toArray(); + Object[] o = q.toArray(); Arrays.sort(o); - for (int i = 0; i < o.length; i++) - assertEquals(o[i], q.poll()); + for (int i = 0; i < o.length; i++) + assertEquals(o[i], q.poll()); } /** @@ -348,8 +333,8 @@ public class LinkedListTest extends JSR1 */ public void testToArray2() { LinkedList q = populatedQueue(SIZE); - Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); + Integer[] ints = new Integer[SIZE]; + ints = (Integer[])q.toArray(ints); Arrays.sort(ints); for (int i = 0; i < ints.length; i++) assertEquals(ints[i], q.poll()); @@ -359,24 +344,24 @@ public class LinkedListTest extends JSR1 * toArray(null) throws NPE */ public void testToArray_BadArg() { - try { - LinkedList l = new LinkedList(); - l.add(new Object()); - Object o[] = l.toArray(null); - shouldThrow(); - } catch (NullPointerException success) {} + try { + LinkedList l = new LinkedList(); + l.add(new Object()); + Object o[] = l.toArray(null); + shouldThrow(); + } catch (NullPointerException success) {} } /** * toArray with incompatable aray type throws CCE */ public void testToArray1_BadArg() { - try { - LinkedList l = new LinkedList(); - l.add(new Integer(5)); - Object o[] = l.toArray(new String[10] ); - shouldThrow(); - } catch (ArrayStoreException success) {} + try { + LinkedList l = new LinkedList(); + l.add(new Integer(5)); + Object o[] = l.toArray(new String[10] ); + shouldThrow(); + } catch (ArrayStoreException success) {} } /** @@ -385,7 +370,7 @@ public class LinkedListTest extends JSR1 public void testIterator() { LinkedList q = populatedQueue(SIZE); int i = 0; - Iterator it = q.iterator(); + Iterator it = q.iterator(); while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; @@ -433,7 +418,7 @@ public class LinkedListTest extends JSR1 public void testDescendingIterator() { LinkedList q = populatedQueue(SIZE); int i = 0; - Iterator it = q.descendingIterator(); + Iterator it = q.descendingIterator(); while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; @@ -442,8 +427,8 @@ public class LinkedListTest extends JSR1 assertFalse(it.hasNext()); try { it.next(); - } catch (NoSuchElementException success) { - } + shouldThrow(); + } catch (NoSuchElementException success) {} } /** @@ -497,8 +482,8 @@ public class LinkedListTest extends JSR1 */ public void testAddFirst() { LinkedList q = populatedQueue(3); - q.addFirst(four); - assertEquals(four,q.peek()); + q.addFirst(four); + assertEquals(four,q.peek()); } /** @@ -507,8 +492,8 @@ public class LinkedListTest extends JSR1 public void testPush() { LinkedList q = populatedQueue(3); q.pollLast(); - q.push(four); - assertEquals(four,q.peekFirst()); + q.push(four); + assertEquals(four,q.peekFirst()); } /** @@ -522,8 +507,7 @@ public class LinkedListTest extends JSR1 try { q.pop(); shouldThrow(); - } catch (NoSuchElementException success) { - } + } catch (NoSuchElementException success) {} } /** @@ -552,7 +536,7 @@ public class LinkedListTest extends JSR1 for (int i = SIZE-1; i >= 0; --i) { assertEquals(i, ((Integer)q.pollLast()).intValue()); } - assertNull(q.pollLast()); + assertNull(q.pollLast()); } /** @@ -566,7 +550,7 @@ public class LinkedListTest extends JSR1 assertTrue(q.peekFirst() == null || i != ((Integer)q.peekFirst()).intValue()); } - assertNull(q.peekFirst()); + assertNull(q.peekFirst()); } @@ -581,7 +565,7 @@ public class LinkedListTest extends JSR1 assertTrue(q.peekLast() == null || i != ((Integer)q.peekLast()).intValue()); } - assertNull(q.peekLast()); + assertNull(q.peekLast()); } public void testFirstElement() { @@ -593,8 +577,7 @@ public class LinkedListTest extends JSR1 try { q.getFirst(); shouldThrow(); - } - catch (NoSuchElementException success) {} + } catch (NoSuchElementException success) {} } /** @@ -609,9 +592,8 @@ public class LinkedListTest extends JSR1 try { q.getLast(); shouldThrow(); - } - catch (NoSuchElementException success) {} - assertNull(q.peekLast()); + } catch (NoSuchElementException success) {} + assertNull(q.peekLast()); } /**