--- jsr166/src/test/tck/ArrayBlockingQueueTest.java 2009/11/02 20:28:31 1.12 +++ jsr166/src/test/tck/ArrayBlockingQueueTest.java 2009/11/21 02:07:26 1.15 @@ -14,10 +14,10 @@ import java.io.*; public class ArrayBlockingQueueTest 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(ArrayBlockingQueueTest.class); + return new TestSuite(ArrayBlockingQueueTest.class); } /** @@ -27,11 +27,11 @@ public class ArrayBlockingQueueTest exte 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))); + for (int i = 0; i < n; i++) + assertTrue(q.offer(new Integer(i))); assertFalse(q.isEmpty()); assertEquals(0, q.remainingCapacity()); - assertEquals(n, q.size()); + assertEquals(n, q.size()); return q; } @@ -155,7 +155,7 @@ public class ArrayBlockingQueueTest exte * offer(null) throws NPE */ public void testOfferNull() { - try { + try { ArrayBlockingQueue q = new ArrayBlockingQueue(1); q.offer(null); shouldThrow(); @@ -166,7 +166,7 @@ public class ArrayBlockingQueueTest exte * add(null) throws NPE */ public void testAddNull() { - try { + try { ArrayBlockingQueue q = new ArrayBlockingQueue(1); q.add(null); shouldThrow(); @@ -186,15 +186,15 @@ public class ArrayBlockingQueueTest exte * add succeeds if not full; throws ISE if full */ public void testAdd() { - try { + try { ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertTrue(q.add(new Integer(i))); } assertEquals(0, q.remainingCapacity()); q.add(new Integer(SIZE)); - } catch (IllegalStateException success){ - } + } catch (IllegalStateException success) { + } } /** @@ -285,15 +285,15 @@ public class ArrayBlockingQueueTest exte * put(null) throws NPE */ public void testPutNull() { - try { + try { ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); q.put(null); shouldThrow(); } - catch (NullPointerException success){ - } + catch (NullPointerException success) { + } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -311,7 +311,7 @@ public class ArrayBlockingQueueTest exte assertEquals(0, q.remainingCapacity()); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -330,7 +330,7 @@ public class ArrayBlockingQueueTest exte } q.put(new Integer(SIZE)); threadShouldThrow(); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { threadAssertEquals(added, SIZE); } }}); @@ -341,7 +341,7 @@ public class ArrayBlockingQueueTest exte t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -362,8 +362,8 @@ public class ArrayBlockingQueueTest exte ++added; q.put(new Object()); ++added; - threadShouldThrow(); - } catch (InterruptedException e){ + threadShouldThrow(); + } catch (InterruptedException e) { threadAssertTrue(added >= 2); } } @@ -374,7 +374,7 @@ public class ArrayBlockingQueueTest exte q.take(); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -391,8 +391,8 @@ public class ArrayBlockingQueueTest exte q.put(new Object()); threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS/2, TimeUnit.MILLISECONDS)); q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); - } catch (InterruptedException success){} + threadShouldThrow(); + } catch (InterruptedException success) {} } }); @@ -401,7 +401,7 @@ public class ArrayBlockingQueueTest exte Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -410,14 +410,14 @@ public class ArrayBlockingQueueTest exte * take retrieves elements in FIFO order */ public void testTake() { - try { + try { ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.take()).intValue()); } - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -429,8 +429,8 @@ public class ArrayBlockingQueueTest exte public void run() { try { q.take(); - threadShouldThrow(); - } catch (InterruptedException success){ } + threadShouldThrow(); + } catch (InterruptedException success) { } } }); try { @@ -438,7 +438,7 @@ public class ArrayBlockingQueueTest exte Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -456,7 +456,7 @@ public class ArrayBlockingQueueTest exte } q.take(); threadShouldThrow(); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); try { @@ -466,7 +466,7 @@ public class ArrayBlockingQueueTest exte t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -479,7 +479,7 @@ public class ArrayBlockingQueueTest exte for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.poll()).intValue()); } - assertNull(q.poll()); + assertNull(q.poll()); } /** @@ -492,9 +492,9 @@ public class ArrayBlockingQueueTest exte assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); } assertNull(q.poll(0, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -507,9 +507,9 @@ public class ArrayBlockingQueueTest exte assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); } assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -525,7 +525,7 @@ public class ArrayBlockingQueueTest exte threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); } threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); try { @@ -535,7 +535,7 @@ public class ArrayBlockingQueueTest exte t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -551,7 +551,7 @@ public class ArrayBlockingQueueTest exte threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); + threadShouldThrow(); } catch (InterruptedException success) { } } }); @@ -561,7 +561,7 @@ public class ArrayBlockingQueueTest exte assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -578,7 +578,7 @@ public class ArrayBlockingQueueTest exte assertTrue(q.peek() == null || i != ((Integer)q.peek()).intValue()); } - assertNull(q.peek()); + assertNull(q.peek()); } /** @@ -608,8 +608,8 @@ public class ArrayBlockingQueueTest exte try { q.remove(); shouldThrow(); - } catch (NoSuchElementException success){ - } + } catch (NoSuchElementException success) { + } } /** @@ -709,13 +709,13 @@ public class ArrayBlockingQueueTest exte */ public void testToArray() { ArrayBlockingQueue q = populatedQueue(SIZE); - Object[] o = q.toArray(); - try { - for(int i = 0; i < o.length; i++) - assertEquals(o[i], q.take()); - } catch (InterruptedException e){ - unexpectedException(); - } + Object[] o = q.toArray(); + try { + for (int i = 0; i < o.length; i++) + assertEquals(o[i], q.take()); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -723,36 +723,36 @@ public class ArrayBlockingQueueTest exte */ public void testToArray2() { ArrayBlockingQueue q = populatedQueue(SIZE); - Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); - try { - for(int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.take()); - } catch (InterruptedException e){ - unexpectedException(); - } + Integer[] ints = new Integer[SIZE]; + ints = (Integer[])q.toArray(ints); + try { + for (int i = 0; i < ints.length; i++) + assertEquals(ints[i], q.take()); + } catch (InterruptedException e) { + unexpectedException(); + } } /** * toArray(null) throws NPE */ public void testToArray_BadArg() { - try { + try { ArrayBlockingQueue 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 { ArrayBlockingQueue 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) {} } @@ -761,14 +761,14 @@ public class ArrayBlockingQueueTest exte */ public void testIterator() { ArrayBlockingQueue q = populatedQueue(SIZE); - Iterator it = q.iterator(); - try { - while(it.hasNext()){ - assertEquals(it.next(), q.take()); - } - } catch (InterruptedException e){ - unexpectedException(); - } + Iterator it = q.iterator(); + try { + while (it.hasNext()) { + assertEquals(it.next(), q.take()); + } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -931,7 +931,7 @@ public class ArrayBlockingQueueTest exte assertEquals(q.size(), r.size()); while (!q.isEmpty()) assertEquals(q.remove(), r.remove()); - } catch(Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -944,7 +944,7 @@ public class ArrayBlockingQueueTest exte try { q.drainTo(null); shouldThrow(); - } catch(NullPointerException success) { + } catch (NullPointerException success) { } } @@ -956,7 +956,7 @@ public class ArrayBlockingQueueTest exte try { q.drainTo(q); shouldThrow(); - } catch(IllegalArgumentException success) { + } catch (IllegalArgumentException success) { } } @@ -993,7 +993,7 @@ public class ArrayBlockingQueueTest exte public void run() { try { q.put(new Integer(SIZE+1)); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { threadUnexpectedException(); } } @@ -1007,7 +1007,7 @@ public class ArrayBlockingQueueTest exte assertEquals(l.get(i), new Integer(i)); t.join(); assertTrue(q.size() + l.size() >= SIZE); - } catch(Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1020,7 +1020,7 @@ public class ArrayBlockingQueueTest exte try { q.drainTo(null, 0); shouldThrow(); - } catch(NullPointerException success) { + } catch (NullPointerException success) { } } @@ -1032,7 +1032,7 @@ public class ArrayBlockingQueueTest exte try { q.drainTo(q, 0); shouldThrow(); - } catch(IllegalArgumentException success) { + } catch (IllegalArgumentException success) { } } @@ -1042,7 +1042,7 @@ public class ArrayBlockingQueueTest exte public void testDrainToN() { ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2); for (int i = 0; i < SIZE + 2; ++i) { - for(int j = 0; j < SIZE; j++) + for (int j = 0; j < SIZE; j++) assertTrue(q.offer(new Integer(j))); ArrayList l = new ArrayList(); q.drainTo(l, i);