--- jsr166/src/test/tck/DelayQueueTest.java 2009/11/02 20:28:31 1.15 +++ jsr166/src/test/tck/DelayQueueTest.java 2009/11/21 02:07:26 1.18 @@ -12,11 +12,11 @@ import java.util.concurrent.*; public class DelayQueueTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } public static Test suite() { - return new TestSuite(DelayQueueTest.class); + return new TestSuite(DelayQueueTest.class); } private static final int NOCAP = Integer.MAX_VALUE; @@ -119,13 +119,13 @@ public class DelayQueueTest extends JSR1 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))); - for(int i = (n & 1); i < n; i+=2) - assertTrue(q.offer(new PDelay(i))); + for (int i = n-1; i >= 0; i-=2) + assertTrue(q.offer(new PDelay(i))); + for (int i = (n & 1); i < n; i+=2) + assertTrue(q.offer(new PDelay(i))); assertFalse(q.isEmpty()); assertEquals(NOCAP, q.remainingCapacity()); - assertEquals(n, q.size()); + assertEquals(n, q.size()); return q; } @@ -225,7 +225,7 @@ public class DelayQueueTest extends JSR1 * offer(null) throws NPE */ public void testOfferNull() { - try { + try { DelayQueue q = new DelayQueue(); q.offer(null); shouldThrow(); @@ -236,7 +236,7 @@ public class DelayQueueTest extends JSR1 * add(null) throws NPE */ public void testAddNull() { - try { + try { DelayQueue q = new DelayQueue(); q.add(null); shouldThrow(); @@ -338,13 +338,13 @@ public class DelayQueueTest extends JSR1 * put(null) throws NPE */ public void testPutNull() { - try { + try { DelayQueue q = new DelayQueue(); q.put(null); shouldThrow(); } - catch (NullPointerException success){ - } + catch (NullPointerException success) { + } } /** @@ -392,7 +392,7 @@ public class DelayQueueTest extends JSR1 q.take(); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -418,7 +418,7 @@ public class DelayQueueTest extends JSR1 Thread.sleep(SMALL_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -427,14 +427,14 @@ public class DelayQueueTest extends JSR1 * take retrieves elements in priority order */ public void testTake() { - try { + try { DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(new PDelay(i), ((PDelay)q.take())); } - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -446,8 +446,8 @@ public class DelayQueueTest extends JSR1 public void run() { try { q.take(); - threadShouldThrow(); - } catch (InterruptedException success){ } + threadShouldThrow(); + } catch (InterruptedException success) { } } }); try { @@ -455,7 +455,7 @@ public class DelayQueueTest extends JSR1 Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -473,7 +473,7 @@ public class DelayQueueTest extends JSR1 } q.take(); threadShouldThrow(); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); t.start(); @@ -483,7 +483,7 @@ public class DelayQueueTest extends JSR1 t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -496,7 +496,7 @@ public class DelayQueueTest extends JSR1 for (int i = 0; i < SIZE; ++i) { assertEquals(new PDelay(i), ((PDelay)q.poll())); } - assertNull(q.poll()); + assertNull(q.poll()); } /** @@ -509,9 +509,9 @@ public class DelayQueueTest extends JSR1 assertEquals(new PDelay(i), ((PDelay)q.poll(0, TimeUnit.MILLISECONDS))); } assertNull(q.poll(0, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -524,9 +524,9 @@ public class DelayQueueTest extends JSR1 assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS))); } assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -542,7 +542,7 @@ public class DelayQueueTest extends JSR1 threadAssertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS))); } threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); t.start(); @@ -552,7 +552,7 @@ public class DelayQueueTest extends JSR1 t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -568,7 +568,7 @@ public class DelayQueueTest extends JSR1 threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadFail("Should block"); + threadFail("Should block"); } catch (InterruptedException success) { } } }); @@ -578,7 +578,7 @@ public class DelayQueueTest extends JSR1 assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -597,7 +597,7 @@ public class DelayQueueTest extends JSR1 else assertTrue(i != ((PDelay)q.peek()).intValue()); } - assertNull(q.peek()); + assertNull(q.peek()); } /** @@ -627,8 +627,8 @@ public class DelayQueueTest extends JSR1 try { q.remove(); shouldThrow(); - } catch (NoSuchElementException success){ - } + } catch (NoSuchElementException success) { + } } /** @@ -729,14 +729,14 @@ public class DelayQueueTest extends JSR1 */ public void testToArray() { DelayQueue q = populatedQueue(SIZE); - Object[] o = q.toArray(); + Object[] o = q.toArray(); Arrays.sort(o); - try { - for(int i = 0; i < o.length; i++) - assertEquals(o[i], q.take()); - } catch (InterruptedException e){ - unexpectedException(); - } + try { + for (int i = 0; i < o.length; i++) + assertEquals(o[i], q.take()); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -744,15 +744,15 @@ public class DelayQueueTest extends JSR1 */ public void testToArray2() { DelayQueue q = populatedQueue(SIZE); - PDelay[] ints = new PDelay[SIZE]; - ints = (PDelay[])q.toArray(ints); + PDelay[] ints = new PDelay[SIZE]; + ints = (PDelay[])q.toArray(ints); Arrays.sort(ints); - try { - for(int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.take()); - } catch (InterruptedException e){ - unexpectedException(); - } + try { + for (int i = 0; i < ints.length; i++) + assertEquals(ints[i], q.take()); + } catch (InterruptedException e) { + unexpectedException(); + } } @@ -760,22 +760,22 @@ public class DelayQueueTest extends JSR1 * toArray(null) throws NPE */ public void testToArray_BadArg() { - try { + try { DelayQueue q = populatedQueue(SIZE); - Object o[] = q.toArray(null); - shouldThrow(); - } catch(NullPointerException success){} + Object o[] = q.toArray(null); + shouldThrow(); + } catch (NullPointerException success) {} } /** * toArray with incompatible array type throws CCE */ public void testToArray1_BadArg() { - try { + try { DelayQueue q = populatedQueue(SIZE); - Object o[] = q.toArray(new String[10] ); - shouldThrow(); - } catch(ArrayStoreException success){} + Object o[] = q.toArray(new String[10] ); + shouldThrow(); + } catch (ArrayStoreException success) {} } /** @@ -784,8 +784,8 @@ public class DelayQueueTest extends JSR1 public void testIterator() { DelayQueue q = populatedQueue(SIZE); int i = 0; - Iterator it = q.iterator(); - while(it.hasNext()) { + Iterator it = q.iterator(); + while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } @@ -880,7 +880,7 @@ public class DelayQueueTest extends JSR1 last = tt; } } - catch(InterruptedException ie) { + catch (InterruptedException ie) { unexpectedException(); } } @@ -925,7 +925,7 @@ public class DelayQueueTest extends JSR1 try { q.drainTo(null); shouldThrow(); - } catch(NullPointerException success) { + } catch (NullPointerException success) { } } @@ -937,7 +937,7 @@ public class DelayQueueTest extends JSR1 try { q.drainTo(q); shouldThrow(); - } catch(IllegalArgumentException success) { + } catch (IllegalArgumentException success) { } } @@ -986,7 +986,7 @@ public class DelayQueueTest extends JSR1 assertTrue(l.size() >= SIZE); t.join(); assertTrue(q.size() + l.size() >= SIZE); - } catch(Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -999,7 +999,7 @@ public class DelayQueueTest extends JSR1 try { q.drainTo(null, 0); shouldThrow(); - } catch(NullPointerException success) { + } catch (NullPointerException success) { } } @@ -1011,7 +1011,7 @@ public class DelayQueueTest extends JSR1 try { q.drainTo(q, 0); shouldThrow(); - } catch(IllegalArgumentException success) { + } catch (IllegalArgumentException success) { } }