--- jsr166/src/test/tck/PriorityBlockingQueueTest.java 2011/05/27 20:07:24 1.44 +++ jsr166/src/test/tck/PriorityBlockingQueueTest.java 2011/05/30 22:43:20 1.45 @@ -7,8 +7,17 @@ */ import junit.framework.*; -import java.util.*; -import java.util.concurrent.*; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.concurrent.PriorityBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.*; @@ -75,7 +84,7 @@ public class PriorityBlockingQueueTest e */ public void testConstructor2() { try { - PriorityBlockingQueue q = new PriorityBlockingQueue(0); + new PriorityBlockingQueue(0); shouldThrow(); } catch (IllegalArgumentException success) {} } @@ -85,7 +94,7 @@ public class PriorityBlockingQueueTest e */ public void testConstructor3() { try { - PriorityBlockingQueue q = new PriorityBlockingQueue(null); + new PriorityBlockingQueue(null); shouldThrow(); } catch (NullPointerException success) {} } @@ -94,9 +103,9 @@ public class PriorityBlockingQueueTest e * Initializing from Collection of null elements throws NPE */ public void testConstructor4() { + Collection elements = Arrays.asList(new Integer[SIZE]); try { - Integer[] ints = new Integer[SIZE]; - PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints)); + new PriorityBlockingQueue(elements); shouldThrow(); } catch (NullPointerException success) {} } @@ -105,11 +114,12 @@ public class PriorityBlockingQueueTest e * Initializing from Collection with some null elements throws NPE */ public void testConstructor5() { + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE-1; ++i) + ints[i] = i; + Collection elements = Arrays.asList(ints); try { - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); - PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints)); + new PriorityBlockingQueue(elements); shouldThrow(); } catch (NullPointerException success) {} } @@ -120,7 +130,7 @@ public class PriorityBlockingQueueTest e public void testConstructor6() { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(i); + ints[i] = i; PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints)); for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll()); @@ -175,28 +185,6 @@ public class PriorityBlockingQueueTest e } /** - * offer(null) throws NPE - */ - public void testOfferNull() { - try { - PriorityBlockingQueue q = new PriorityBlockingQueue(1); - q.offer(null); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** - * add(null) throws NPE - */ - public void testAddNull() { - try { - PriorityBlockingQueue q = new PriorityBlockingQueue(1); - q.add(null); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** * Offer of comparable element succeeds */ public void testOffer() { @@ -230,17 +218,6 @@ public class PriorityBlockingQueueTest e } /** - * addAll(null) throws NPE - */ - public void testAddAll1() { - try { - PriorityBlockingQueue q = new PriorityBlockingQueue(1); - q.addAll(null); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** * addAll(this) throws IAE */ public void testAddAllSelf() { @@ -252,18 +229,6 @@ public class PriorityBlockingQueueTest e } /** - * addAll of a collection with null elements throws NPE - */ - public void testAddAll2() { - try { - PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); - Integer[] ints = new Integer[SIZE]; - q.addAll(Arrays.asList(ints)); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements */ @@ -294,17 +259,6 @@ public class PriorityBlockingQueueTest e } /** - * put(null) throws NPE - */ - public void testPutNull() { - try { - PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); - q.put(null); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** * all elements successfully put are contained */ public void testPut() { @@ -626,17 +580,6 @@ public class PriorityBlockingQueueTest e } /** - * toArray(null) throws NullPointerException - */ - public void testToArray_NullArg() { - PriorityBlockingQueue q = populatedQueue(SIZE); - try { - q.toArray(null); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { @@ -734,28 +677,6 @@ public class PriorityBlockingQueueTest e } /** - * drainTo(null) throws NPE - */ - public void testDrainToNull() { - PriorityBlockingQueue q = populatedQueue(SIZE); - try { - q.drainTo(null); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** - * drainTo(this) throws IAE - */ - public void testDrainToSelf() { - PriorityBlockingQueue q = populatedQueue(SIZE); - try { - q.drainTo(q); - shouldThrow(); - } catch (IllegalArgumentException success) {} - } - - /** * drainTo(c) empties queue into another collection c */ public void testDrainTo() { @@ -800,28 +721,6 @@ public class PriorityBlockingQueueTest e } /** - * drainTo(null, n) throws NPE - */ - public void testDrainToNullN() { - PriorityBlockingQueue q = populatedQueue(SIZE); - try { - q.drainTo(null, 0); - shouldThrow(); - } catch (NullPointerException success) {} - } - - /** - * drainTo(this, n) throws IAE - */ - public void testDrainToSelfN() { - PriorityBlockingQueue q = populatedQueue(SIZE); - try { - q.drainTo(q, 0); - shouldThrow(); - } catch (IllegalArgumentException success) {} - } - - /** * drainTo(c, n) empties first min(n, size) elements of queue into c */ public void testDrainToN() {