--- jsr166/src/test/tck/JSR166TestCase.java 2010/11/22 06:53:32 1.71 +++ jsr166/src/test/tck/JSR166TestCase.java 2010/11/29 07:39:53 1.73 @@ -7,6 +7,8 @@ */ import junit.framework.*; +import java.util.Arrays; +import java.util.NoSuchElementException; import java.util.PropertyPermission; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; @@ -787,6 +789,13 @@ public class JSR166TestCase extends Test }}; } + public Runnable awaiter(final CountDownLatch latch) { + return new CheckedRunnable() { + public void realRun() throws InterruptedException { + latch.await(); + }}; + } + public static class NPETask implements Callable { public String call() { throw new NullPointerException(); } } @@ -1007,4 +1016,31 @@ public class JSR166TestCase extends Test } } + public void checkEmpty(BlockingQueue q) { + try { + assertTrue(q.isEmpty()); + assertEquals(0, q.size()); + assertNull(q.peek()); + assertNull(q.poll()); + assertNull(q.poll(0, MILLISECONDS)); + assertEquals(q.toString(), "[]"); + assertTrue(Arrays.equals(q.toArray(), new Object[0])); + assertFalse(q.iterator().hasNext()); + try { + q.element(); + shouldThrow(); + } catch (NoSuchElementException success) {} + try { + q.iterator().next(); + shouldThrow(); + } catch (NoSuchElementException success) {} + try { + q.remove(); + shouldThrow(); + } catch (NoSuchElementException success) {} + } catch (InterruptedException ie) { + threadUnexpectedException(ie); + } + } + }