--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2014/12/31 19:21:20 1.56 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2015/05/15 18:21:19 1.60 @@ -32,7 +32,7 @@ public class LinkedTransferQueueTest ext } public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { @@ -115,16 +115,16 @@ public class LinkedTransferQueueTest ext * remainingCapacity() always returns Integer.MAX_VALUE */ public void testRemainingCapacity() { - LinkedTransferQueue q = populatedQueue(SIZE); + BlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); assertEquals(SIZE - i, q.size()); - q.remove(); + assertEquals(i, q.remove()); } for (int i = 0; i < SIZE; ++i) { assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); assertEquals(i, q.size()); - q.add(i); + assertTrue(q.add(i)); } } @@ -132,8 +132,8 @@ public class LinkedTransferQueueTest ext * addAll(this) throws IllegalArgumentException */ public void testAddAllSelf() { + LinkedTransferQueue q = populatedQueue(SIZE); try { - LinkedTransferQueue q = populatedQueue(SIZE); q.addAll(q); shouldThrow(); } catch (IllegalArgumentException success) {} @@ -144,12 +144,11 @@ public class LinkedTransferQueueTest ext * NullPointerException after possibly adding some elements */ public void testAddAll3() { + LinkedTransferQueue q = new LinkedTransferQueue(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = i; try { - LinkedTransferQueue q = new LinkedTransferQueue(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE - 1; ++i) { - ints[i] = i; - } q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -500,11 +499,24 @@ public class LinkedTransferQueueTest ext public void testIterator() throws InterruptedException { LinkedTransferQueue q = populatedQueue(SIZE); Iterator it = q.iterator(); - int i = 0; - while (it.hasNext()) { - assertEquals(it.next(), i++); - } + int i; + for (i = 0; it.hasNext(); i++) + assertTrue(q.contains(it.next())); assertEquals(i, SIZE); + assertIteratorExhausted(it); + + it = q.iterator(); + for (i = 0; it.hasNext(); i++) + assertEquals(it.next(), q.take()); + assertEquals(i, SIZE); + assertIteratorExhausted(it); + } + + /** + * iterator of empty collection has no elements + */ + public void testEmptyIterator() { + assertIteratorExhausted(new LinkedTransferQueue().iterator()); } /** @@ -849,8 +861,8 @@ public class LinkedTransferQueueTest ext * tryTransfer(null) throws NullPointerException */ public void testTryTransfer1() { + final LinkedTransferQueue q = new LinkedTransferQueue(); try { - final LinkedTransferQueue q = new LinkedTransferQueue(); q.tryTransfer(null); shouldThrow(); } catch (NullPointerException success) {}