--- jsr166/src/test/tck/LinkedBlockingQueueTest.java 2003/10/05 23:00:40 1.6 +++ jsr166/src/test/tck/LinkedBlockingQueueTest.java 2004/10/31 14:55:14 1.10 @@ -1,8 +1,9 @@ /* - * Written by members of JCP JSR-166 Expert Group and released to the - * public domain. Use, modify, and redistribute this code in any way - * without acknowledgement. Other contributors include Andrew Wright, - * Jeffrey Hayes, Pat Fischer, Mike Judd. + * Written by Doug Lea with assistance from members of JCP JSR-166 + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ import junit.framework.*; @@ -637,6 +638,7 @@ public class LinkedBlockingQueueTest ext assertEquals(SIZE, q.remainingCapacity()); q.add(one); assertFalse(q.isEmpty()); + assertTrue(q.contains(one)); q.clear(); assertTrue(q.isEmpty()); } @@ -731,7 +733,7 @@ public class LinkedBlockingQueueTest ext } /** - * toArray with incompatable array type throws CCE + * toArray with incompatible array type throws CCE */ public void testToArray1_BadArg() { try { @@ -955,6 +957,17 @@ public class LinkedBlockingQueueTest ext assertEquals(l.size(), SIZE); for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i)); + q.add(zero); + q.add(one); + assertFalse(q.isEmpty()); + assertTrue(q.contains(zero)); + assertTrue(q.contains(one)); + l.clear(); + q.drainTo(l); + assertEquals(q.size(), 0); + assertEquals(l.size(), 2); + for (int i = 0; i < 2; ++i) + assertEquals(l.get(i), new Integer(i)); } /** @@ -979,7 +992,7 @@ public class LinkedBlockingQueueTest ext for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i)); t.join(); - assertTrue(q.size() + l.size() == SIZE+1); + assertTrue(q.size() + l.size() >= SIZE); } catch(Exception e){ unexpectedException(); } @@ -1013,15 +1026,18 @@ public class LinkedBlockingQueueTest ext * drainTo(c, n) empties first max {n, size} elements of queue into c */ public void testDrainToN() { + LinkedBlockingQueue q = new LinkedBlockingQueue(); for (int i = 0; i < SIZE + 2; ++i) { - LinkedBlockingQueue q = populatedQueue(SIZE); + for(int j = 0; j < SIZE; j++) + assertTrue(q.offer(new Integer(j))); ArrayList l = new ArrayList(); q.drainTo(l, i); int k = (i < SIZE)? i : SIZE; - assertEquals(q.size(), SIZE-k); assertEquals(l.size(), k); + assertEquals(q.size(), SIZE-k); for (int j = 0; j < k; ++j) assertEquals(l.get(j), new Integer(j)); + while (q.poll() != null) ; } }