--- jsr166/src/test/tck/PriorityBlockingQueueTest.java 2009/11/21 09:28:16 1.18 +++ jsr166/src/test/tck/PriorityBlockingQueueTest.java 2009/11/22 18:57:17 1.24 @@ -25,11 +25,7 @@ public class PriorityBlockingQueueTest e /** Sample Comparator */ static class MyReverseComparator implements Comparator { public int compare(Object x, Object y) { - int i = ((Integer)x).intValue(); - int j = ((Integer)y).intValue(); - if (i < j) return 1; - if (i > j) return -1; - return 0; + return ((Comparable)y).compareTo(x); } } @@ -58,7 +54,7 @@ public class PriorityBlockingQueueTest e } /** - * Constructor throws IAE if capacity argument nonpositive + * Constructor throws IAE if capacity argument nonpositive */ public void testConstructor2() { try { @@ -332,8 +328,8 @@ public class PriorityBlockingQueueTest e public void realRun() { q.put(new Integer(0)); q.put(new Integer(0)); - threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS)); - threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS)); + assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS)); + assertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS)); }}); t.start(); @@ -348,7 +344,7 @@ public class PriorityBlockingQueueTest e public void testTake() throws InterruptedException { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.take()).intValue()); + assertEquals(i, q.take()); } } @@ -372,13 +368,16 @@ public class PriorityBlockingQueueTest e * Take removes existing elements until empty, then blocks interruptibly */ public void testBlockingTake() throws InterruptedException { - Thread t = new Thread(new CheckedInterruptedRunnable() { + final PriorityBlockingQueue q = populatedQueue(SIZE); + Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - threadAssertEquals(i, ((Integer)q.take()).intValue()); + assertEquals(i, q.take()); } - q.take(); + try { + q.take(); + shouldThrow(); + } catch (InterruptedException success) {} }}); t.start(); @@ -394,7 +393,7 @@ public class PriorityBlockingQueueTest e public void testPoll() { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.poll()).intValue()); + assertEquals(i, q.poll()); } assertNull(q.poll()); } @@ -405,7 +404,7 @@ public class PriorityBlockingQueueTest e public void testTimedPoll0() throws InterruptedException { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); + assertEquals(i, q.poll(0, MILLISECONDS)); } assertNull(q.poll(0, MILLISECONDS)); } @@ -416,7 +415,7 @@ public class PriorityBlockingQueueTest e public void testTimedPoll() throws InterruptedException { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); + assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS)); } assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); } @@ -430,10 +429,10 @@ public class PriorityBlockingQueueTest e public void realRun() throws InterruptedException { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); + assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS)); } try { - q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(SMALL_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} }}); @@ -453,16 +452,16 @@ public class PriorityBlockingQueueTest e Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertEquals(0, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + assertSame(zero, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); try { q.poll(LONG_DELAY_MS, MILLISECONDS); - threadShouldThrow(); + shouldThrow(); } catch (InterruptedException success) {} }}); t.start(); Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS)); + assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); t.interrupt(); t.join(); } @@ -474,10 +473,10 @@ public class PriorityBlockingQueueTest e public void testPeek() { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.peek()).intValue()); - q.poll(); + assertEquals(i, q.peek()); + assertEquals(i, q.poll()); assertTrue(q.peek() == null || - i != ((Integer)q.peek()).intValue()); + !q.peek().equals(i)); } assertNull(q.peek()); } @@ -488,8 +487,8 @@ public class PriorityBlockingQueueTest e public void testElement() { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.element()).intValue()); - q.poll(); + assertEquals(i, q.element()); + assertEquals(i, q.poll()); } try { q.element(); @@ -503,7 +502,7 @@ public class PriorityBlockingQueueTest e public void testRemove() { PriorityBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.remove()).intValue()); + assertEquals(i, q.remove()); } try { q.remove(); @@ -629,8 +628,8 @@ public class PriorityBlockingQueueTest e * toArray(null) throws NPE */ public void testToArray_BadArg() { + PriorityBlockingQueue q = populatedQueue(SIZE); try { - PriorityBlockingQueue q = populatedQueue(SIZE); Object o[] = q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} @@ -640,11 +639,11 @@ public class PriorityBlockingQueueTest e * toArray with incompatible array type throws CCE */ public void testToArray1_BadArg() { + PriorityBlockingQueue q = populatedQueue(SIZE); try { - PriorityBlockingQueue q = populatedQueue(SIZE); - Object o[] = q.toArray(new String[10] ); + Object o[] = q.toArray(new String[10]); shouldThrow(); - } catch (ArrayStoreException success) {} + } catch (ArrayStoreException success) {} } /**