--- jsr166/src/test/tck/ArrayBlockingQueueTest.java 2010/10/06 07:49:22 1.32 +++ jsr166/src/test/tck/ArrayBlockingQueueTest.java 2010/11/05 00:17:22 1.41 @@ -41,8 +41,8 @@ public class ArrayBlockingQueueTest exte * Create a queue of given size containing consecutive * Integers 0 ... n. */ - private ArrayBlockingQueue populatedQueue(int n) { - ArrayBlockingQueue q = new ArrayBlockingQueue(n); + private ArrayBlockingQueue populatedQueue(int n) { + ArrayBlockingQueue q = new ArrayBlockingQueue(n); assertTrue(q.isEmpty()); for (int i = 0; i < n; i++) assertTrue(q.offer(new Integer(i))); @@ -161,7 +161,7 @@ public class ArrayBlockingQueueTest exte } /** - * offer(null) throws NPE + * offer(null) throws NPE */ public void testOfferNull() { try { @@ -172,7 +172,7 @@ public class ArrayBlockingQueueTest exte } /** - * add(null) throws NPE + * add(null) throws NPE */ public void testAddNull() { try { @@ -207,7 +207,7 @@ public class ArrayBlockingQueueTest exte } /** - * addAll(null) throws NPE + * addAll(null) throws NPE */ public void testAddAll1() { try { @@ -230,7 +230,7 @@ public class ArrayBlockingQueueTest exte /** - * addAll of a collection with null elements throws NPE + * addAll of a collection with null elements throws NPE */ public void testAddAll2() { try { @@ -286,7 +286,7 @@ public class ArrayBlockingQueueTest exte } /** - * put(null) throws NPE + * put(null) throws NPE */ public void testPutNull() throws InterruptedException { try { @@ -393,22 +393,6 @@ public class ArrayBlockingQueueTest exte } /** - * take blocks interruptibly when empty - */ - public void testTakeFromEmpty() throws InterruptedException { - final ArrayBlockingQueue q = new ArrayBlockingQueue(2); - Thread t = new ThreadShouldThrow(InterruptedException.class) { - public void realRun() throws InterruptedException { - q.take(); - }}; - - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - } - - /** * Take removes existing elements until empty, then blocks interruptibly */ public void testBlockingTake() throws InterruptedException { @@ -443,7 +427,7 @@ public class ArrayBlockingQueueTest exte } /** - * timed pool with zero timeout succeeds when non-empty, else times out + * timed poll with zero timeout succeeds when non-empty, else times out */ public void testTimedPoll0() throws InterruptedException { ArrayBlockingQueue q = populatedQueue(SIZE); @@ -454,7 +438,7 @@ public class ArrayBlockingQueueTest exte } /** - * timed pool with nonzero timeout succeeds when non-empty, else times out + * timed poll with nonzero timeout succeeds when non-empty, else times out */ public void testTimedPoll() throws InterruptedException { ArrayBlockingQueue q = populatedQueue(SIZE); @@ -623,44 +607,45 @@ public class ArrayBlockingQueueTest exte } /** - * toArray contains all elements + * toArray contains all elements in FIFO order */ - public void testToArray() throws InterruptedException { + public void testToArray() { ArrayBlockingQueue q = populatedQueue(SIZE); Object[] o = q.toArray(); for (int i = 0; i < o.length; i++) - assertEquals(o[i], q.take()); + assertSame(o[i], q.poll()); } /** - * toArray(a) contains all elements + * toArray(a) contains all elements in FIFO order */ - public void testToArray2() throws InterruptedException { - ArrayBlockingQueue q = populatedQueue(SIZE); + public void testToArray2() { + ArrayBlockingQueue q = populatedQueue(SIZE); Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); + Integer[] array = q.toArray(ints); + assertSame(ints, array); for (int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.take()); + assertSame(ints[i], q.poll()); } /** - * toArray(null) throws NPE + * toArray(null) throws NullPointerException */ - public void testToArray_BadArg() { + public void testToArray_NullArg() { ArrayBlockingQueue q = populatedQueue(SIZE); try { - Object o[] = q.toArray(null); + q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} } /** - * toArray with incompatible array type throws CCE + * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { ArrayBlockingQueue q = populatedQueue(SIZE); try { - Object o[] = q.toArray(new String[10]); + q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} } @@ -896,7 +881,7 @@ public class ArrayBlockingQueueTest exte } /** - * drainTo(c, n) empties first max {n, size} elements of queue into c + * drainTo(c, n) empties first min(n, size) elements of queue into c */ public void testDrainToN() { ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2); @@ -905,7 +890,7 @@ public class ArrayBlockingQueueTest exte assertTrue(q.offer(new Integer(j))); ArrayList l = new ArrayList(); q.drainTo(l, i); - int k = (i < SIZE)? i : SIZE; + int k = (i < SIZE) ? i : SIZE; assertEquals(l.size(), k); assertEquals(q.size(), SIZE-k); for (int j = 0; j < k; ++j)