--- jsr166/src/test/tck/LinkedBlockingDequeTest.java 2009/11/02 20:28:31 1.4 +++ jsr166/src/test/tck/LinkedBlockingDequeTest.java 2009/11/21 02:33:20 1.8 @@ -7,15 +7,16 @@ import junit.framework.*; import java.util.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.*; public class LinkedBlockingDequeTest 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(LinkedBlockingDequeTest.class); + return new TestSuite(LinkedBlockingDequeTest.class); } /** @@ -25,11 +26,11 @@ public class LinkedBlockingDequeTest ext private LinkedBlockingDeque populatedDeque(int n) { LinkedBlockingDeque q = new LinkedBlockingDeque(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; } @@ -66,7 +67,7 @@ public class LinkedBlockingDequeTest ext * offer(null) throws NPE */ public void testOfferFirstNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(); q.offerFirst(null); shouldThrow(); @@ -100,7 +101,7 @@ public class LinkedBlockingDequeTest ext for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.pollFirst()).intValue()); } - assertNull(q.pollFirst()); + assertNull(q.pollFirst()); } /** @@ -111,7 +112,7 @@ public class LinkedBlockingDequeTest ext for (int i = SIZE-1; i >= 0; --i) { assertEquals(i, ((Integer)q.pollLast()).intValue()); } - assertNull(q.pollLast()); + assertNull(q.pollLast()); } /** @@ -125,7 +126,7 @@ public class LinkedBlockingDequeTest ext assertTrue(q.peekFirst() == null || i != ((Integer)q.peekFirst()).intValue()); } - assertNull(q.peekFirst()); + assertNull(q.peekFirst()); } /** @@ -139,7 +140,7 @@ public class LinkedBlockingDequeTest ext assertTrue(q.peek() == null || i != ((Integer)q.peek()).intValue()); } - assertNull(q.peek()); + assertNull(q.peek()); } /** @@ -153,7 +154,7 @@ public class LinkedBlockingDequeTest ext assertTrue(q.peekLast() == null || i != ((Integer)q.peekLast()).intValue()); } - assertNull(q.peekLast()); + assertNull(q.peekLast()); } /** @@ -186,7 +187,7 @@ public class LinkedBlockingDequeTest ext shouldThrow(); } catch (NoSuchElementException success) {} - assertNull(q.peekLast()); + assertNull(q.peekLast()); } /** @@ -200,8 +201,8 @@ public class LinkedBlockingDequeTest ext try { q.removeFirst(); shouldThrow(); - } catch (NoSuchElementException success){ - } + } catch (NoSuchElementException success) { + } } /** @@ -215,8 +216,8 @@ public class LinkedBlockingDequeTest ext try { q.remove(); shouldThrow(); - } catch (NoSuchElementException success){ - } + } catch (NoSuchElementException success) { + } } /** @@ -255,8 +256,8 @@ public class LinkedBlockingDequeTest ext public void testAddFirst() { LinkedBlockingDeque q = populatedDeque(3); q.pollLast(); - q.addFirst(four); - assertEquals(four,q.peekFirst()); + q.addFirst(four); + assertEquals(four,q.peekFirst()); } /** @@ -265,8 +266,8 @@ public class LinkedBlockingDequeTest ext public void testAddLast() { LinkedBlockingDeque q = populatedDeque(3); q.pollLast(); - q.addLast(four); - assertEquals(four,q.peekLast()); + q.addLast(four); + assertEquals(four,q.peekLast()); } @@ -378,7 +379,7 @@ public class LinkedBlockingDequeTest ext * offer(null) throws NPE */ public void testOfferNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(1); q.offer(null); shouldThrow(); @@ -389,7 +390,7 @@ public class LinkedBlockingDequeTest ext * add(null) throws NPE */ public void testAddNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(1); q.add(null); shouldThrow(); @@ -400,7 +401,7 @@ public class LinkedBlockingDequeTest ext * push(null) throws NPE */ public void testPushNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(1); q.push(null); shouldThrow(); @@ -411,7 +412,7 @@ public class LinkedBlockingDequeTest ext * push succeeds if not full; throws ISE if full */ public void testPush() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); for (int i = 0; i < SIZE; ++i) { Integer I = new Integer(i); @@ -420,8 +421,8 @@ public class LinkedBlockingDequeTest ext } assertEquals(0, q.remainingCapacity()); q.push(new Integer(SIZE)); - } catch (IllegalStateException success){ - } + } catch (IllegalStateException success) { + } } /** @@ -430,8 +431,8 @@ public class LinkedBlockingDequeTest ext public void testPushWithPeek() { LinkedBlockingDeque q = populatedDeque(3); q.pollLast(); - q.push(four); - assertEquals(four,q.peekFirst()); + q.push(four); + assertEquals(four,q.peekFirst()); } @@ -446,8 +447,8 @@ public class LinkedBlockingDequeTest ext try { q.pop(); shouldThrow(); - } catch (NoSuchElementException success){ - } + } catch (NoSuchElementException success) { + } } @@ -464,15 +465,15 @@ public class LinkedBlockingDequeTest ext * add succeeds if not full; throws ISE if full */ public void testAdd() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(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) { + } } /** @@ -563,15 +564,15 @@ public class LinkedBlockingDequeTest ext * put(null) throws NPE */ public void testPutNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); q.put(null); shouldThrow(); } - catch (NullPointerException success){ - } + catch (NullPointerException success) { + } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -589,7 +590,7 @@ public class LinkedBlockingDequeTest ext assertEquals(0, q.remainingCapacity()); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -608,7 +609,7 @@ public class LinkedBlockingDequeTest ext } q.put(new Integer(SIZE)); threadShouldThrow(); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { threadAssertEquals(added, SIZE); } }}); @@ -619,7 +620,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -640,8 +641,8 @@ public class LinkedBlockingDequeTest ext ++added; q.put(new Object()); ++added; - threadShouldThrow(); - } catch (InterruptedException e){ + threadShouldThrow(); + } catch (InterruptedException e) { threadAssertTrue(added >= 2); } } @@ -652,7 +653,7 @@ public class LinkedBlockingDequeTest ext q.take(); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -667,10 +668,10 @@ public class LinkedBlockingDequeTest ext try { q.put(new Object()); q.put(new Object()); - threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); - } catch (InterruptedException success){} + threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); + q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); + threadShouldThrow(); + } catch (InterruptedException success) {} } }); @@ -679,7 +680,7 @@ public class LinkedBlockingDequeTest ext Thread.sleep(SMALL_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -688,14 +689,14 @@ public class LinkedBlockingDequeTest ext * take retrieves elements in FIFO order */ public void testTake() { - try { + try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.take()).intValue()); } - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -707,8 +708,8 @@ public class LinkedBlockingDequeTest ext public void run() { try { q.take(); - threadShouldThrow(); - } catch (InterruptedException success){ } + threadShouldThrow(); + } catch (InterruptedException success) { } } }); try { @@ -716,7 +717,7 @@ public class LinkedBlockingDequeTest ext Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -734,7 +735,7 @@ public class LinkedBlockingDequeTest ext } q.take(); threadShouldThrow(); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); t.start(); @@ -744,7 +745,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -757,7 +758,7 @@ public class LinkedBlockingDequeTest ext for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.poll()).intValue()); } - assertNull(q.poll()); + assertNull(q.poll()); } /** @@ -767,12 +768,12 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); + assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); } - assertNull(q.poll(0, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + assertNull(q.poll(0, MILLISECONDS)); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -782,12 +783,12 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); + assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); } - assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -800,10 +801,10 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); + threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); } - threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException success){ + threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + } catch (InterruptedException success) { } }}); t.start(); @@ -813,7 +814,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -826,20 +827,20 @@ public class LinkedBlockingDequeTest ext Thread t = new Thread(new Runnable() { public void run() { try { - threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); + threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(LONG_DELAY_MS, MILLISECONDS); + threadShouldThrow(); } catch (InterruptedException success) { } } }); try { t.start(); Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); + assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -849,15 +850,15 @@ public class LinkedBlockingDequeTest ext * putFirst(null) throws NPE */ public void testPutFirstNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); q.putFirst(null); shouldThrow(); } - catch (NullPointerException success){ - } + catch (NullPointerException success) { + } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -875,7 +876,7 @@ public class LinkedBlockingDequeTest ext assertEquals(0, q.remainingCapacity()); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -894,7 +895,7 @@ public class LinkedBlockingDequeTest ext } q.putFirst(new Integer(SIZE)); threadShouldThrow(); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { threadAssertEquals(added, SIZE); } }}); @@ -905,7 +906,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -926,8 +927,8 @@ public class LinkedBlockingDequeTest ext ++added; q.putFirst(new Object()); ++added; - threadShouldThrow(); - } catch (InterruptedException e){ + threadShouldThrow(); + } catch (InterruptedException e) { threadAssertTrue(added >= 2); } } @@ -938,7 +939,7 @@ public class LinkedBlockingDequeTest ext q.take(); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -953,10 +954,10 @@ public class LinkedBlockingDequeTest ext try { q.putFirst(new Object()); q.putFirst(new Object()); - threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); - } catch (InterruptedException success){} + threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS)); + q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS); + threadShouldThrow(); + } catch (InterruptedException success) {} } }); @@ -965,7 +966,7 @@ public class LinkedBlockingDequeTest ext Thread.sleep(SMALL_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -974,14 +975,14 @@ public class LinkedBlockingDequeTest ext * take retrieves elements in FIFO order */ public void testTakeFirst() { - try { + try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.takeFirst()).intValue()); } - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -993,8 +994,8 @@ public class LinkedBlockingDequeTest ext public void run() { try { q.takeFirst(); - threadShouldThrow(); - } catch (InterruptedException success){ } + threadShouldThrow(); + } catch (InterruptedException success) { } } }); try { @@ -1002,7 +1003,7 @@ public class LinkedBlockingDequeTest ext Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1020,7 +1021,7 @@ public class LinkedBlockingDequeTest ext } q.takeFirst(); threadShouldThrow(); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); t.start(); @@ -1030,7 +1031,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1042,12 +1043,12 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue()); + assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue()); } - assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + assertNull(q.pollFirst(0, MILLISECONDS)); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -1057,12 +1058,12 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); + assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); } - assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -1075,10 +1076,10 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); + threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); } - threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException success){ + threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); + } catch (InterruptedException success) { } }}); t.start(); @@ -1088,7 +1089,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1101,20 +1102,20 @@ public class LinkedBlockingDequeTest ext Thread t = new Thread(new Runnable() { public void run() { try { - threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); + threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); + q.pollFirst(LONG_DELAY_MS, MILLISECONDS); + q.pollFirst(LONG_DELAY_MS, MILLISECONDS); + threadShouldThrow(); } catch (InterruptedException success) { } } }); try { t.start(); Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); + assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS)); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1123,15 +1124,15 @@ public class LinkedBlockingDequeTest ext * putLast(null) throws NPE */ public void testPutLastNull() { - try { + try { LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); q.putLast(null); shouldThrow(); } - catch (NullPointerException success){ - } + catch (NullPointerException success) { + } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1149,7 +1150,7 @@ public class LinkedBlockingDequeTest ext assertEquals(0, q.remainingCapacity()); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1168,7 +1169,7 @@ public class LinkedBlockingDequeTest ext } q.putLast(new Integer(SIZE)); threadShouldThrow(); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { threadAssertEquals(added, SIZE); } }}); @@ -1179,7 +1180,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1200,8 +1201,8 @@ public class LinkedBlockingDequeTest ext ++added; q.putLast(new Object()); ++added; - threadShouldThrow(); - } catch (InterruptedException e){ + threadShouldThrow(); + } catch (InterruptedException e) { threadAssertTrue(added >= 2); } } @@ -1212,7 +1213,7 @@ public class LinkedBlockingDequeTest ext q.take(); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1227,10 +1228,10 @@ public class LinkedBlockingDequeTest ext try { q.putLast(new Object()); q.putLast(new Object()); - threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); - } catch (InterruptedException success){} + threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS)); + q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS); + threadShouldThrow(); + } catch (InterruptedException success) {} } }); @@ -1239,7 +1240,7 @@ public class LinkedBlockingDequeTest ext Thread.sleep(SMALL_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1248,14 +1249,14 @@ public class LinkedBlockingDequeTest ext * takeLast retrieves elements in FIFO order */ public void testTakeLast() { - try { + try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue()); } - } catch (InterruptedException e){ - unexpectedException(); - } + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -1267,8 +1268,8 @@ public class LinkedBlockingDequeTest ext public void run() { try { q.takeLast(); - threadShouldThrow(); - } catch (InterruptedException success){ } + threadShouldThrow(); + } catch (InterruptedException success) { } } }); try { @@ -1276,7 +1277,7 @@ public class LinkedBlockingDequeTest ext Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1294,7 +1295,7 @@ public class LinkedBlockingDequeTest ext } q.takeLast(); threadShouldThrow(); - } catch (InterruptedException success){ + } catch (InterruptedException success) { } }}); t.start(); @@ -1304,7 +1305,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1316,12 +1317,12 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue()); + assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue()); } - assertNull(q.pollLast(0, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + assertNull(q.pollLast(0, MILLISECONDS)); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -1331,12 +1332,12 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); + assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); } - assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException e){ - unexpectedException(); - } + assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS)); + } catch (InterruptedException e) { + unexpectedException(); + } } /** @@ -1349,10 +1350,10 @@ public class LinkedBlockingDequeTest ext try { LinkedBlockingDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); + threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); } - threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - } catch (InterruptedException success){ + threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS)); + } catch (InterruptedException success) { } }}); t.start(); @@ -1362,7 +1363,7 @@ public class LinkedBlockingDequeTest ext t.join(); } catch (InterruptedException ie) { - unexpectedException(); + unexpectedException(); } } @@ -1375,20 +1376,20 @@ public class LinkedBlockingDequeTest ext Thread t = new Thread(new Runnable() { public void run() { try { - threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); - q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadShouldThrow(); + threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(LONG_DELAY_MS, MILLISECONDS); + threadShouldThrow(); } catch (InterruptedException success) { } } }); try { t.start(); Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); + assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS)); t.interrupt(); t.join(); - } catch (Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1507,13 +1508,13 @@ public class LinkedBlockingDequeTest ext */ public void testToArray() { LinkedBlockingDeque q = populatedDeque(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(); + } } /** @@ -1521,36 +1522,36 @@ public class LinkedBlockingDequeTest ext */ public void testToArray2() { LinkedBlockingDeque q = populatedDeque(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 { LinkedBlockingDeque q = populatedDeque(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 { LinkedBlockingDeque q = populatedDeque(SIZE); - Object o[] = q.toArray(new String[10] ); - shouldThrow(); - } catch(ArrayStoreException success){} + Object o[] = q.toArray(new String[10] ); + shouldThrow(); + } catch (ArrayStoreException success) {} } @@ -1559,14 +1560,14 @@ public class LinkedBlockingDequeTest ext */ public void testIterator() { LinkedBlockingDeque q = populatedDeque(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(); + } } /** @@ -1633,8 +1634,8 @@ public class LinkedBlockingDequeTest ext public void testDescendingIterator() { LinkedBlockingDeque q = populatedDeque(SIZE); int i = 0; - Iterator it = q.descendingIterator(); - while(it.hasNext()) { + Iterator it = q.descendingIterator(); + while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } @@ -1642,7 +1643,7 @@ public class LinkedBlockingDequeTest ext assertFalse(it.hasNext()); try { it.next(); - } catch(NoSuchElementException success) { + } catch (NoSuchElementException success) { } } @@ -1715,7 +1716,7 @@ public class LinkedBlockingDequeTest ext public void run() { threadAssertFalse(q.offer(three)); try { - threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); + threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); threadAssertEquals(0, q.remainingCapacity()); } catch (InterruptedException e) { @@ -1749,7 +1750,7 @@ public class LinkedBlockingDequeTest ext public void run() { threadAssertNull(q.poll()); try { - threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); + threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); threadAssertTrue(q.isEmpty()); } catch (InterruptedException e) { @@ -1791,7 +1792,7 @@ public class LinkedBlockingDequeTest ext assertEquals(q.size(), r.size()); while (!q.isEmpty()) assertEquals(q.remove(), r.remove()); - } catch(Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1804,7 +1805,7 @@ public class LinkedBlockingDequeTest ext try { q.drainTo(null); shouldThrow(); - } catch(NullPointerException success) { + } catch (NullPointerException success) { } } @@ -1816,7 +1817,7 @@ public class LinkedBlockingDequeTest ext try { q.drainTo(q); shouldThrow(); - } catch(IllegalArgumentException success) { + } catch (IllegalArgumentException success) { } } @@ -1853,7 +1854,7 @@ public class LinkedBlockingDequeTest ext public void run() { try { q.put(new Integer(SIZE+1)); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { threadUnexpectedException(); } } @@ -1867,7 +1868,7 @@ public class LinkedBlockingDequeTest ext assertEquals(l.get(i), new Integer(i)); t.join(); assertTrue(q.size() + l.size() >= SIZE); - } catch(Exception e){ + } catch (Exception e) { unexpectedException(); } } @@ -1880,7 +1881,7 @@ public class LinkedBlockingDequeTest ext try { q.drainTo(null, 0); shouldThrow(); - } catch(NullPointerException success) { + } catch (NullPointerException success) { } } @@ -1892,7 +1893,7 @@ public class LinkedBlockingDequeTest ext try { q.drainTo(q, 0); shouldThrow(); - } catch(IllegalArgumentException success) { + } catch (IllegalArgumentException success) { } } @@ -1902,7 +1903,7 @@ public class LinkedBlockingDequeTest ext public void testDrainToN() { LinkedBlockingDeque q = new LinkedBlockingDeque(); 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);