--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2014/12/31 19:21:20 1.56 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2015/06/14 20:58:14 1.62 @@ -24,6 +24,13 @@ import junit.framework.Test; @SuppressWarnings({"unchecked", "rawtypes"}) public class LinkedTransferQueueTest extends JSR166TestCase { + static class Implementation implements CollectionImplementation { + public Class klazz() { return LinkedTransferQueue.class; } + public Collection emptyCollection() { return new LinkedTransferQueue(); } + public Object makeElement(int i) { return i; } + public boolean isConcurrent() { return true; } + public boolean permitsNulls() { return false; } + } public static class Generic extends BlockingQueueTest { protected BlockingQueue emptyCollection() { @@ -32,12 +39,13 @@ public class LinkedTransferQueueTest ext } public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return newTestSuite(LinkedTransferQueueTest.class, - new Generic().testSuite()); + new Generic().testSuite(), + CollectionTest.testSuite(new Implementation())); } /** @@ -78,7 +86,7 @@ public class LinkedTransferQueueTest ext */ public void testConstructor4() { Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) + for (int i = 0; i < SIZE - 1; ++i) ints[i] = i; Collection elements = Arrays.asList(ints); try { @@ -115,16 +123,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 +140,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 +152,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 +507,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 +869,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) {}