--- jsr166/src/test/tck/DelayQueueTest.java 2010/10/28 22:20:47 1.41 +++ jsr166/src/test/tck/DelayQueueTest.java 2011/05/06 11:22:07 1.49 @@ -1,7 +1,7 @@ /* * 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 + * http://creativecommons.org/publicdomain/zero/1.0/ * Other contributors include Andrew Wright, Jeffrey Hayes, * Pat Fisher, Mike Judd. */ @@ -109,8 +109,8 @@ public class DelayQueueTest extends JSR1 * Create a queue of given size containing consecutive * PDelays 0 ... n. */ - private DelayQueue populatedQueue(int n) { - DelayQueue q = new DelayQueue(); + private DelayQueue populatedQueue(int n) { + DelayQueue q = new DelayQueue(); assertTrue(q.isEmpty()); for (int i = n-1; i >= 0; i-=2) assertTrue(q.offer(new PDelay(i))); @@ -318,25 +318,25 @@ public class DelayQueueTest extends JSR1 /** * put(null) throws NPE */ - public void testPutNull() { + public void testPutNull() { try { DelayQueue q = new DelayQueue(); q.put(null); shouldThrow(); } catch (NullPointerException success) {} - } + } /** * all elements successfully put are contained */ - public void testPut() { - DelayQueue q = new DelayQueue(); - for (int i = 0; i < SIZE; ++i) { - PDelay I = new PDelay(i); - q.put(I); - assertTrue(q.contains(I)); - } - assertEquals(SIZE, q.size()); + public void testPut() { + DelayQueue q = new DelayQueue(); + for (int i = 0; i < SIZE; ++i) { + PDelay I = new PDelay(i); + q.put(I); + assertTrue(q.contains(I)); + } + assertEquals(SIZE, q.size()); } /** @@ -353,7 +353,7 @@ public class DelayQueueTest extends JSR1 }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); q.take(); t.interrupt(); t.join(); @@ -373,7 +373,7 @@ public class DelayQueueTest extends JSR1 }}); t.start(); - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); t.interrupt(); t.join(); } @@ -402,11 +402,11 @@ public class DelayQueueTest extends JSR1 try { q.take(); shouldThrow(); - } catch (InterruptedException expected) {} + } catch (InterruptedException success) {} assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); }}); threadStarted.await(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(t.isAlive()); t.interrupt(); awaitTermination(t, MEDIUM_DELAY_MS); @@ -430,7 +430,7 @@ public class DelayQueueTest extends JSR1 }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -487,7 +487,7 @@ public class DelayQueueTest extends JSR1 }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -676,40 +676,41 @@ public class DelayQueueTest extends JSR1 Object[] o = q.toArray(); Arrays.sort(o); for (int i = 0; i < o.length; i++) - assertEquals(o[i], q.take()); + assertSame(o[i], q.take()); } /** * toArray(a) contains all elements */ - public void testToArray2() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); + public void testToArray2() { + DelayQueue q = populatedQueue(SIZE); PDelay[] ints = new PDelay[SIZE]; - ints = (PDelay[])q.toArray(ints); + PDelay[] array = q.toArray(ints); + assertSame(ints, array); Arrays.sort(ints); for (int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.take()); + assertSame(ints[i], q.remove()); } /** - * toArray(null) throws NPE + * toArray(null) throws NullPointerException */ - public void testToArray_BadArg() { + public void testToArray_NullArg() { DelayQueue 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() { DelayQueue q = populatedQueue(SIZE); try { - Object o[] = q.toArray(new String[10]); + q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} } @@ -772,7 +773,7 @@ public class DelayQueueTest extends JSR1 executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); q.put(new PDelay(1)); }});