ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/PriorityBlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.4 by dl, Sat Sep 20 00:31:57 2003 UTC vs.
Revision 1.86 by jsr166, Wed Jan 27 01:57:24 2021 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
10 < import java.util.*;
11 < import java.util.concurrent.*;
12 < import java.io.*;
9 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 >
11 > import java.util.ArrayList;
12 > import java.util.Arrays;
13 > import java.util.Collection;
14 > import java.util.Comparator;
15 > import java.util.Iterator;
16 > import java.util.NoSuchElementException;
17 > import java.util.Queue;
18 > import java.util.concurrent.BlockingQueue;
19 > import java.util.concurrent.CountDownLatch;
20 > import java.util.concurrent.Executors;
21 > import java.util.concurrent.ExecutorService;
22 > import java.util.concurrent.PriorityBlockingQueue;
23 > import java.util.concurrent.ThreadLocalRandom;
24 >
25 > import junit.framework.Test;
26  
27   public class PriorityBlockingQueueTest extends JSR166TestCase {
28 +
29 +    public static class Generic extends BlockingQueueTest {
30 +        protected BlockingQueue emptyCollection() {
31 +            return new PriorityBlockingQueue();
32 +        }
33 +    }
34 +
35 +    public static class InitialCapacity extends BlockingQueueTest {
36 +        protected BlockingQueue emptyCollection() {
37 +            ThreadLocalRandom rnd = ThreadLocalRandom.current();
38 +            int initialCapacity = rnd.nextInt(1, SIZE);
39 +            return new PriorityBlockingQueue(initialCapacity);
40 +        }
41 +    }
42 +
43      public static void main(String[] args) {
44 <        junit.textui.TestRunner.run (suite());  
44 >        main(suite(), args);
45      }
46  
47      public static Test suite() {
48 <        return new TestSuite(PriorityBlockingQueueTest.class);
48 >        class Implementation implements CollectionImplementation {
49 >            public Class<?> klazz() { return PriorityBlockingQueue.class; }
50 >            public Collection emptyCollection() {
51 >                return new PriorityBlockingQueue();
52 >            }
53 >            public Object makeElement(int i) { return JSR166TestCase.itemFor(i); }
54 >            public boolean isConcurrent() { return true; }
55 >            public boolean permitsNulls() { return false; }
56 >        }
57 >        class ComparatorImplementation implements CollectionImplementation {
58 >            public Class<?> klazz() { return PriorityBlockingQueue.class; }
59 >            @SuppressWarnings("unchecked")
60 >            public Collection emptyCollection() {
61 >                ThreadLocalRandom rnd = ThreadLocalRandom.current();
62 >                int initialCapacity = rnd.nextInt(1, 10);
63 >                return new PriorityBlockingQueue(
64 >                    initialCapacity, new MyReverseComparator());
65 >            }
66 >            public Object makeElement(int i) { return JSR166TestCase.itemFor(i); }
67 >            public boolean isConcurrent() { return true; }
68 >            public boolean permitsNulls() { return false; }
69 >        }
70 >        return newTestSuite(
71 >            PriorityBlockingQueueTest.class,
72 >            new Generic().testSuite(),
73 >            new InitialCapacity().testSuite(),
74 >            CollectionTest.testSuite(new Implementation()),
75 >            CollectionTest.testSuite(new ComparatorImplementation()));
76      }
77  
22    private static final int NOCAP = Integer.MAX_VALUE;
23
78      /** Sample Comparator */
79 <    static class MyReverseComparator implements Comparator {
79 >    static class MyReverseComparator implements Comparator, java.io.Serializable {
80 >        @SuppressWarnings("unchecked")
81          public int compare(Object x, Object y) {
82 <            int i = ((Integer)x).intValue();
28 <            int j = ((Integer)y).intValue();
29 <            if (i < j) return 1;
30 <            if (i > j) return -1;
31 <            return 0;
82 >            return ((Comparable)y).compareTo(x);
83          }
84      }
85  
35
86      /**
87 <     * Create a queue of given size containing consecutive
88 <     * Integers 0 ... n.
87 >     * Returns a new queue of given size containing consecutive
88 >     * Items 0 ... n - 1.
89       */
90 <    private PriorityBlockingQueue populatedQueue(int n) {
91 <        PriorityBlockingQueue q = new PriorityBlockingQueue(n);
90 >    private static PriorityBlockingQueue<Item> populatedQueue(int n) {
91 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(n);
92          assertTrue(q.isEmpty());
93 <        for(int i = n-1; i >= 0; i-=2)
94 <            assertTrue(q.offer(new Integer(i)));
95 <        for(int i = (n & 1); i < n; i+=2)
96 <            assertTrue(q.offer(new Integer(i)));
93 >        for (int i = n - 1; i >= 0; i -= 2)
94 >            mustOffer(q, i);
95 >        for (int i = (n & 1); i < n; i += 2)
96 >            mustOffer(q, i);
97          assertFalse(q.isEmpty());
98 <        assertEquals(NOCAP, q.remainingCapacity());
99 <        assertEquals(n, q.size());
98 >        mustEqual(Integer.MAX_VALUE, q.remainingCapacity());
99 >        mustEqual(n, q.size());
100 >        mustEqual(0, q.peek());
101          return q;
102      }
103 <
104 <    public void testConstructor1(){
105 <        assertEquals(NOCAP, new PriorityBlockingQueue(SIZE).remainingCapacity());
103 >
104 >    /**
105 >     * A new queue has unbounded capacity
106 >     */
107 >    public void testConstructor1() {
108 >        mustEqual(Integer.MAX_VALUE,
109 >                     new PriorityBlockingQueue<Item>(SIZE).remainingCapacity());
110      }
111  
112 <    public void testConstructor2(){
112 >    /**
113 >     * Constructor throws IllegalArgumentException if capacity argument nonpositive
114 >     */
115 >    public void testConstructor2() {
116          try {
117 <            PriorityBlockingQueue q = new PriorityBlockingQueue(0);
118 <            fail("Cannot make zero-sized");
119 <        }
62 <        catch (IllegalArgumentException success) {}
117 >            new PriorityBlockingQueue<Item>(0);
118 >            shouldThrow();
119 >        } catch (IllegalArgumentException success) {}
120      }
121  
122 <    public void testConstructor3(){
123 <
122 >    /**
123 >     * Initializing from null Collection throws NPE
124 >     */
125 >    public void testConstructor3() {
126          try {
127 <            PriorityBlockingQueue q = new PriorityBlockingQueue(null);
128 <            fail("Cannot make from null collection");
129 <        }
71 <        catch (NullPointerException success) {}
127 >            new PriorityBlockingQueue<Item>(null);
128 >            shouldThrow();
129 >        } catch (NullPointerException success) {}
130      }
131  
132 <    public void testConstructor4(){
132 >    /**
133 >     * Initializing from Collection of null elements throws NPE
134 >     */
135 >    public void testConstructor4() {
136 >        Collection<Item> elements = Arrays.asList(new Item[SIZE]);
137          try {
138 <            Integer[] ints = new Integer[SIZE];
139 <            PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints));
140 <            fail("Cannot make with null elements");
79 <        }
80 <        catch (NullPointerException success) {}
138 >            new PriorityBlockingQueue<Item>(elements);
139 >            shouldThrow();
140 >        } catch (NullPointerException success) {}
141      }
142  
143 <    public void testConstructor5(){
144 <        try {
145 <            Integer[] ints = new Integer[SIZE];
146 <            for (int i = 0; i < SIZE-1; ++i)
147 <                ints[i] = new Integer(i);
148 <            PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints));
149 <            fail("Cannot make with null elements");
150 <        }
151 <        catch (NullPointerException success) {}
143 >    /**
144 >     * Initializing from Collection with some null elements throws NPE
145 >     */
146 >    public void testConstructor5() {
147 >        Item[] items = new Item[2]; items[0] = zero;
148 >        Collection<Item> elements = Arrays.asList(items);
149 >        try {
150 >            new PriorityBlockingQueue<Item>(elements);
151 >            shouldThrow();
152 >        } catch (NullPointerException success) {}
153      }
154  
155 <    public void testConstructor6(){
156 <        try {
157 <            Integer[] ints = new Integer[SIZE];
158 <            for (int i = 0; i < SIZE; ++i)
159 <                ints[i] = new Integer(i);
160 <            PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints));
161 <            for (int i = 0; i < SIZE; ++i)
162 <                assertEquals(ints[i], q.poll());
102 <        }
103 <        finally {}
155 >    /**
156 >     * Queue contains all elements of collection used to initialize
157 >     */
158 >    public void testConstructor6() {
159 >        Item[] items = defaultItems;
160 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(Arrays.asList(items));
161 >        for (int i = 0; i < SIZE; ++i)
162 >            mustEqual(items[i], q.poll());
163      }
164  
165 <    public void testConstructor7(){
166 <        try {
167 <            MyReverseComparator cmp = new MyReverseComparator();
168 <            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE, cmp);
169 <            assertEquals(cmp, q.comparator());
170 <            Integer[] ints = new Integer[SIZE];
171 <            for (int i = 0; i < SIZE; ++i)
172 <                ints[i] = new Integer(i);
173 <            q.addAll(Arrays.asList(ints));
174 <            for (int i = SIZE-1; i >= 0; --i)
175 <                assertEquals(ints[i], q.poll());
176 <        }
118 <        finally {}
165 >    /**
166 >     * The comparator used in constructor is used
167 >     */
168 >    public void testConstructor7() {
169 >        MyReverseComparator cmp = new MyReverseComparator();
170 >        @SuppressWarnings("unchecked")
171 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(SIZE, cmp);
172 >        mustEqual(cmp, q.comparator());
173 >        Item[] items = defaultItems;
174 >        q.addAll(Arrays.asList(items));
175 >        for (int i = SIZE - 1; i >= 0; --i)
176 >            mustEqual(items[i], q.poll());
177      }
178  
179 +    /**
180 +     * isEmpty is true before add, false after
181 +     */
182      public void testEmpty() {
183 <        PriorityBlockingQueue q = new PriorityBlockingQueue(2);
183 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(2);
184          assertTrue(q.isEmpty());
185 <        assertEquals(NOCAP, q.remainingCapacity());
186 <        q.add(new Integer(1));
185 >        mustEqual(Integer.MAX_VALUE, q.remainingCapacity());
186 >        q.add(one);
187          assertFalse(q.isEmpty());
188 <        q.add(new Integer(2));
188 >        q.add(two);
189          q.remove();
190          q.remove();
191          assertTrue(q.isEmpty());
192      }
193  
194 <    public void testRemainingCapacity(){
195 <        PriorityBlockingQueue q = populatedQueue(SIZE);
194 >    /**
195 >     * remainingCapacity() always returns Integer.MAX_VALUE
196 >     */
197 >    public void testRemainingCapacity() {
198 >        BlockingQueue<Item> q = populatedQueue(SIZE);
199          for (int i = 0; i < SIZE; ++i) {
200 <            assertEquals(NOCAP, q.remainingCapacity());
201 <            assertEquals(SIZE-i, q.size());
202 <            q.remove();
200 >            mustEqual(Integer.MAX_VALUE, q.remainingCapacity());
201 >            mustEqual(SIZE - i, q.size());
202 >            mustEqual(i, q.remove());
203          }
204          for (int i = 0; i < SIZE; ++i) {
205 <            assertEquals(NOCAP, q.remainingCapacity());
206 <            assertEquals(i, q.size());
207 <            q.add(new Integer(i));
205 >            mustEqual(Integer.MAX_VALUE, q.remainingCapacity());
206 >            mustEqual(i, q.size());
207 >            mustAdd(q, i);
208          }
209      }
210  
211 <    public void testOfferNull(){
212 <        try {
213 <            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
150 <            q.offer(null);
151 <            fail("should throw NPE");
152 <        } catch (NullPointerException success) { }  
153 <    }
154 <
211 >    /**
212 >     * Offer of comparable element succeeds
213 >     */
214      public void testOffer() {
215 <        PriorityBlockingQueue q = new PriorityBlockingQueue(1);
216 <        assertTrue(q.offer(new Integer(0)));
217 <        assertTrue(q.offer(new Integer(1)));
215 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(1);
216 >        assertTrue(q.offer(zero));
217 >        assertTrue(q.offer(one));
218      }
219  
220 +    /**
221 +     * Offer of non-Comparable throws CCE
222 +     */
223      public void testOfferNonComparable() {
224 +        PriorityBlockingQueue<Object> q = new PriorityBlockingQueue<>(1);
225          try {
163            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
164            q.offer(new Object());
226              q.offer(new Object());
227 <            q.offer(new Object());
228 <            fail("should throw CCE");
227 >            shouldThrow();
228 >        } catch (ClassCastException success) {
229 >            assertTrue(q.isEmpty());
230 >            mustEqual(0, q.size());
231 >            assertNull(q.poll());
232          }
169        catch(ClassCastException success) {}
233      }
234  
235 <    public void testAdd(){
236 <        PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
235 >    /**
236 >     * add of comparable succeeds
237 >     */
238 >    public void testAdd() {
239 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(SIZE);
240          for (int i = 0; i < SIZE; ++i) {
241 <            assertEquals(i, q.size());
242 <            assertTrue(q.add(new Integer(i)));
241 >            mustEqual(i, q.size());
242 >            mustAdd(q, i);
243          }
244      }
245  
246 <    public void testAddAll1(){
246 >    /**
247 >     * addAll(this) throws IllegalArgumentException
248 >     */
249 >    public void testAddAllSelf() {
250 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
251          try {
252 <            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
253 <            q.addAll(null);
254 <            fail("Cannot add null collection");
185 <        }
186 <        catch (NullPointerException success) {}
252 >            q.addAll(q);
253 >            shouldThrow();
254 >        } catch (IllegalArgumentException success) {}
255      }
256 <    public void testAddAll2(){
257 <        try {
258 <            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
259 <            Integer[] ints = new Integer[SIZE];
260 <            q.addAll(Arrays.asList(ints));
261 <            fail("Cannot add null elements");
262 <        }
263 <        catch (NullPointerException success) {}
256 >
257 >    /**
258 >     * addAll of a collection with any null elements throws NPE after
259 >     * possibly adding some elements
260 >     */
261 >    public void testAddAll3() {
262 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(SIZE);
263 >        Item[] items = new Item[2];
264 >        items[0] = zero;
265 >        try {
266 >            q.addAll(Arrays.asList(items));
267 >            shouldThrow();
268 >        } catch (NullPointerException success) {}
269      }
270 <    public void testAddAll3(){
271 <        try {
272 <            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
273 <            Integer[] ints = new Integer[SIZE];
274 <            for (int i = 0; i < SIZE-1; ++i)
275 <                ints[i] = new Integer(i);
276 <            q.addAll(Arrays.asList(ints));
277 <            fail("Cannot add null elements");
278 <        }
279 <        catch (NullPointerException success) {}
270 >
271 >    /**
272 >     * Queue contains all elements of successful addAll
273 >     */
274 >    public void testAddAll5() {
275 >        Item[] empty = new Item[0];
276 >        Item[] items = defaultItems;
277 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(SIZE);
278 >        assertFalse(q.addAll(Arrays.asList(empty)));
279 >        assertTrue(q.addAll(Arrays.asList(items)));
280 >        for (int i = 0; i < SIZE; ++i)
281 >            mustEqual(items[i], q.poll());
282      }
283  
284 <    public void testAddAll5(){
285 <        try {
286 <            Integer[] empty = new Integer[0];
287 <            Integer[] ints = new Integer[SIZE];
288 <            for (int i = SIZE-1; i >= 0; --i)
289 <                ints[i] = new Integer(i);
290 <            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
291 <            assertFalse(q.addAll(Arrays.asList(empty)));
292 <            assertTrue(q.addAll(Arrays.asList(ints)));
218 <            for (int i = 0; i < SIZE; ++i)
219 <                assertEquals(ints[i], q.poll());
220 <        }
221 <        finally {}
222 <    }
223 <
224 <     public void testPutNull() {
225 <        try {
226 <            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
227 <            q.put(null);
228 <            fail("put should throw NPE");
229 <        }
230 <        catch (NullPointerException success){
231 <        }  
232 <     }
233 <
234 <     public void testPut() {
235 <         try {
236 <             PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
237 <             for (int i = 0; i < SIZE; ++i) {
238 <                 Integer I = new Integer(i);
239 <                 q.put(I);
240 <                 assertTrue(q.contains(I));
241 <             }
242 <             assertEquals(SIZE, q.size());
243 <         }
244 <         finally {
284 >    /**
285 >     * all elements successfully put are contained
286 >     */
287 >    public void testPut() {
288 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(SIZE);
289 >        for (int i = 0; i < SIZE; ++i) {
290 >            Item x = itemFor(i);
291 >            q.put(x);
292 >            mustContain(q, x);
293          }
294 +        mustEqual(SIZE, q.size());
295      }
296  
297 <    public void testPutWithTake() {
298 <        final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
299 <        Thread t = new Thread(new Runnable() {
300 <                public void run(){
301 <                    int added = 0;
302 <                    try {
303 <                        q.put(new Integer(0));
304 <                        ++added;
305 <                        q.put(new Integer(0));
306 <                        ++added;
307 <                        q.put(new Integer(0));
308 <                        ++added;
309 <                        q.put(new Integer(0));
310 <                        ++added;
311 <                        threadAssertTrue(added == 4);
263 <                    } finally {
264 <                    }
265 <                }
266 <            });
267 <        try {
268 <            t.start();
269 <            Thread.sleep(SHORT_DELAY_MS);
270 <            q.take();
271 <            t.interrupt();
272 <            t.join();
273 <        } catch (Exception e){
274 <            fail("Unexpected exception");
275 <        }
297 >    /**
298 >     * put doesn't block waiting for take
299 >     */
300 >    public void testPutWithTake() throws InterruptedException {
301 >        final PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(2);
302 >        final int size = 4;
303 >        Thread t = newStartedThread(new CheckedRunnable() {
304 >            public void realRun() {
305 >                for (int i = 0; i < size; i++)
306 >                    q.put(zero);
307 >            }});
308 >
309 >        awaitTermination(t);
310 >        mustEqual(size, q.size());
311 >        q.take();
312      }
313  
314 +    /**
315 +     * Queue is unbounded, so timed offer never times out
316 +     */
317      public void testTimedOffer() {
318 <        final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
319 <        Thread t = new Thread(new Runnable() {
320 <                public void run(){
321 <                    try {
322 <                        q.put(new Integer(0));
323 <                        q.put(new Integer(0));
324 <                        threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
325 <                        threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, TimeUnit.MILLISECONDS));
287 <                    } finally { }
288 <                }
289 <            });
290 <        
291 <        try {
292 <            t.start();
293 <            Thread.sleep(SMALL_DELAY_MS);
294 <            t.interrupt();
295 <            t.join();
296 <        } catch (Exception e){
297 <            fail("Unexpected exception");
298 <        }
299 <    }
318 >        final PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(2);
319 >        Thread t = newStartedThread(new CheckedRunnable() {
320 >            public void realRun() {
321 >                q.put(one);
322 >                q.put(two);
323 >                assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
324 >                assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS));
325 >            }});
326  
327 <    public void testTake(){
302 <        try {
303 <            PriorityBlockingQueue q = populatedQueue(SIZE);
304 <            for (int i = 0; i < SIZE; ++i) {
305 <                assertEquals(i, ((Integer)q.take()).intValue());
306 <            }
307 <        } catch (InterruptedException e){
308 <            fail("Unexpected exception");
309 <        }  
327 >        awaitTermination(t);
328      }
329  
330 <    public void testTakeFromEmpty() {
331 <        final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
332 <        Thread t = new Thread(new Runnable() {
333 <                public void run(){
334 <                    try {
335 <                        q.take();
336 <                        threadFail("Should block");
319 <                    } catch (InterruptedException success){ }                
320 <                }
321 <            });
322 <        try {
323 <            t.start();
324 <            Thread.sleep(SHORT_DELAY_MS);
325 <            t.interrupt();
326 <            t.join();
327 <        } catch (Exception e){
328 <            fail("Unexpected exception");
330 >    /**
331 >     * take retrieves elements in priority order
332 >     */
333 >    public void testTake() throws InterruptedException {
334 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
335 >        for (int i = 0; i < SIZE; ++i) {
336 >            mustEqual(i, q.take());
337          }
338      }
339  
340 <    public void testBlockingTake(){
341 <        Thread t = new Thread(new Runnable() {
342 <                public void run() {
343 <                    try {
344 <                        PriorityBlockingQueue q = populatedQueue(SIZE);
345 <                        for (int i = 0; i < SIZE; ++i) {
346 <                            threadAssertEquals(i, ((Integer)q.take()).intValue());
347 <                        }
348 <                        q.take();
341 <                        threadFail("take should block");
342 <                    } catch (InterruptedException success){
343 <                    }  
344 <                }});
345 <        t.start();
346 <        try {
347 <           Thread.sleep(SHORT_DELAY_MS);
348 <           t.interrupt();
349 <           t.join();
350 <        }
351 <        catch (InterruptedException ie) {
352 <            fail("Unexpected exception");
353 <        }
354 <    }
340 >    /**
341 >     * Take removes existing elements until empty, then blocks interruptibly
342 >     */
343 >    public void testBlockingTake() throws InterruptedException {
344 >        final PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
345 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
346 >        Thread t = newStartedThread(new CheckedRunnable() {
347 >            public void realRun() throws InterruptedException {
348 >                for (int i = 0; i < SIZE; i++) mustEqual(i, q.take());
349  
350 +                Thread.currentThread().interrupt();
351 +                try {
352 +                    q.take();
353 +                    shouldThrow();
354 +                } catch (InterruptedException success) {}
355 +                assertFalse(Thread.interrupted());
356 +
357 +                pleaseInterrupt.countDown();
358 +                try {
359 +                    q.take();
360 +                    shouldThrow();
361 +                } catch (InterruptedException success) {}
362 +                assertFalse(Thread.interrupted());
363 +            }});
364 +
365 +        await(pleaseInterrupt);
366 +        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
367 +        t.interrupt();
368 +        awaitTermination(t);
369 +    }
370  
371 <    public void testPoll(){
372 <        PriorityBlockingQueue q = populatedQueue(SIZE);
371 >    /**
372 >     * poll succeeds unless empty
373 >     */
374 >    public void testPoll() {
375 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
376          for (int i = 0; i < SIZE; ++i) {
377 <            assertEquals(i, ((Integer)q.poll()).intValue());
377 >            mustEqual(i, q.poll());
378          }
379 <        assertNull(q.poll());
379 >        assertNull(q.poll());
380      }
381  
382 <    public void testTimedPoll0() {
383 <        try {
384 <            PriorityBlockingQueue q = populatedQueue(SIZE);
385 <            for (int i = 0; i < SIZE; ++i) {
386 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
387 <            }
388 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
389 <        } catch (InterruptedException e){
390 <            fail("Unexpected exception");
374 <        }  
382 >    /**
383 >     * timed poll with zero timeout succeeds when non-empty, else times out
384 >     */
385 >    public void testTimedPoll0() throws InterruptedException {
386 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
387 >        for (int i = 0; i < SIZE; ++i) {
388 >            mustEqual(i, q.poll(0, MILLISECONDS));
389 >        }
390 >        assertNull(q.poll(0, MILLISECONDS));
391      }
392  
393 <    public void testTimedPoll() {
394 <        try {
395 <            PriorityBlockingQueue q = populatedQueue(SIZE);
396 <            for (int i = 0; i < SIZE; ++i) {
397 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
398 <            }
399 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
400 <        } catch (InterruptedException e){
401 <            fail("Unexpected exception");
402 <        }  
403 <    }
404 <
405 <    public void testInterruptedTimedPoll(){
406 <        Thread t = new Thread(new Runnable() {
391 <                public void run() {
392 <                    try {
393 <                        PriorityBlockingQueue q = populatedQueue(SIZE);
394 <                        for (int i = 0; i < SIZE; ++i) {
395 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
396 <                        }
397 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
398 <                    } catch (InterruptedException success){
399 <                    }  
400 <                }});
401 <        t.start();
402 <        try {
403 <           Thread.sleep(SHORT_DELAY_MS);
404 <           t.interrupt();
405 <           t.join();
406 <        }
407 <        catch (InterruptedException ie) {
408 <            fail("Unexpected exception");
409 <        }
393 >    /**
394 >     * timed poll with nonzero timeout succeeds when non-empty, else times out
395 >     */
396 >    public void testTimedPoll() throws InterruptedException {
397 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
398 >        for (int i = 0; i < SIZE; ++i) {
399 >            long startTime = System.nanoTime();
400 >            mustEqual(i, q.poll(LONG_DELAY_MS, MILLISECONDS));
401 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
402 >        }
403 >        long startTime = System.nanoTime();
404 >        assertNull(q.poll(timeoutMillis(), MILLISECONDS));
405 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
406 >        checkEmpty(q);
407      }
408  
409 <    public void testTimedPollWithOffer(){
410 <        final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
411 <        Thread t = new Thread(new Runnable() {
412 <                public void run(){
413 <                    try {
414 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
415 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
416 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
417 <                        threadFail("Should block");
418 <                    } catch (InterruptedException success) { }                
419 <                }
420 <            });
421 <        try {
422 <            t.start();
423 <            Thread.sleep(SMALL_DELAY_MS);
424 <            assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
425 <            t.interrupt();
426 <            t.join();
430 <        } catch (Exception e){
431 <            fail("Unexpected exception");
432 <        }
433 <    }  
409 >    /**
410 >     * Interrupted timed poll throws InterruptedException instead of
411 >     * returning timeout status
412 >     */
413 >    public void testInterruptedTimedPoll() throws InterruptedException {
414 >        final BlockingQueue<Item> q = populatedQueue(SIZE);
415 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
416 >        Thread t = newStartedThread(new CheckedRunnable() {
417 >            public void realRun() throws InterruptedException {
418 >                for (int i = 0; i < SIZE; i++)
419 >                    mustEqual(i, q.poll(LONG_DELAY_MS, MILLISECONDS));
420 >
421 >                Thread.currentThread().interrupt();
422 >                try {
423 >                    q.poll(randomTimeout(), randomTimeUnit());
424 >                    shouldThrow();
425 >                } catch (InterruptedException success) {}
426 >                assertFalse(Thread.interrupted());
427  
428 +                pleaseInterrupt.countDown();
429 +                try {
430 +                    q.poll(LONGER_DELAY_MS, MILLISECONDS);
431 +                    shouldThrow();
432 +                } catch (InterruptedException success) {}
433 +                assertFalse(Thread.interrupted());
434 +            }});
435 +
436 +        await(pleaseInterrupt);
437 +        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
438 +        t.interrupt();
439 +        awaitTermination(t);
440 +    }
441  
442 <    public void testPeek(){
443 <        PriorityBlockingQueue q = populatedQueue(SIZE);
442 >    /**
443 >     * peek returns next element, or null if empty
444 >     */
445 >    public void testPeek() {
446 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
447          for (int i = 0; i < SIZE; ++i) {
448 <            assertEquals(i, ((Integer)q.peek()).intValue());
449 <            q.poll();
448 >            mustEqual(i, q.peek());
449 >            mustEqual(i, q.poll());
450              assertTrue(q.peek() == null ||
451 <                       i != ((Integer)q.peek()).intValue());
451 >                       !q.peek().equals(i));
452          }
453 <        assertNull(q.peek());
453 >        assertNull(q.peek());
454      }
455  
456 <    public void testElement(){
457 <        PriorityBlockingQueue q = populatedQueue(SIZE);
456 >    /**
457 >     * element returns next element, or throws NSEE if empty
458 >     */
459 >    public void testElement() {
460 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
461          for (int i = 0; i < SIZE; ++i) {
462 <            assertEquals(i, ((Integer)q.element()).intValue());
463 <            q.poll();
462 >            mustEqual(i, q.element());
463 >            mustEqual(i, q.poll());
464          }
465          try {
466              q.element();
467 <            fail("no such element");
468 <        }
457 <        catch (NoSuchElementException success) {}
467 >            shouldThrow();
468 >        } catch (NoSuchElementException success) {}
469      }
470  
471 <    public void testRemove(){
472 <        PriorityBlockingQueue q = populatedQueue(SIZE);
471 >    /**
472 >     * remove removes next element, or throws NSEE if empty
473 >     */
474 >    public void testRemove() {
475 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
476          for (int i = 0; i < SIZE; ++i) {
477 <            assertEquals(i, ((Integer)q.remove()).intValue());
477 >            mustEqual(i, q.remove());
478          }
479          try {
480              q.remove();
481 <            fail("remove should throw");
482 <        } catch (NoSuchElementException success){
469 <        }  
481 >            shouldThrow();
482 >        } catch (NoSuchElementException success) {}
483      }
484  
485 <    public void testRemoveElement(){
486 <        PriorityBlockingQueue q = populatedQueue(SIZE);
487 <        for (int i = 1; i < SIZE; i+=2) {
488 <            assertTrue(q.remove(new Integer(i)));
489 <        }
477 <        for (int i = 0; i < SIZE; i+=2) {
478 <            assertTrue(q.remove(new Integer(i)));
479 <            assertFalse(q.remove(new Integer(i+1)));
480 <        }
481 <        assertTrue(q.isEmpty());
482 <    }
483 <        
484 <    public void testContains(){
485 <        PriorityBlockingQueue q = populatedQueue(SIZE);
485 >    /**
486 >     * contains(x) reports true when elements added but not yet removed
487 >     */
488 >    public void testContains() {
489 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
490          for (int i = 0; i < SIZE; ++i) {
491 <            assertTrue(q.contains(new Integer(i)));
491 >            mustContain(q, i);
492              q.poll();
493 <            assertFalse(q.contains(new Integer(i)));
493 >            mustNotContain(q, i);
494          }
495      }
496  
497 <    public void testClear(){
498 <        PriorityBlockingQueue q = populatedQueue(SIZE);
497 >    /**
498 >     * clear removes all elements
499 >     */
500 >    public void testClear() {
501 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
502          q.clear();
503          assertTrue(q.isEmpty());
504 <        assertEquals(0, q.size());
505 <        assertEquals(NOCAP, q.remainingCapacity());
499 <        q.add(new Integer(1));
504 >        mustEqual(0, q.size());
505 >        q.add(one);
506          assertFalse(q.isEmpty());
507 +        mustContain(q, one);
508          q.clear();
509          assertTrue(q.isEmpty());
510      }
511  
512 <    public void testContainsAll(){
513 <        PriorityBlockingQueue q = populatedQueue(SIZE);
514 <        PriorityBlockingQueue p = new PriorityBlockingQueue(SIZE);
512 >    /**
513 >     * containsAll(c) is true when c contains a subset of elements
514 >     */
515 >    public void testContainsAll() {
516 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
517 >        PriorityBlockingQueue<Item> p = new PriorityBlockingQueue<>(SIZE);
518          for (int i = 0; i < SIZE; ++i) {
519              assertTrue(q.containsAll(p));
520              assertFalse(p.containsAll(q));
521 <            p.add(new Integer(i));
521 >            mustAdd(p, i);
522          }
523          assertTrue(p.containsAll(q));
524      }
525  
526 <    public void testRetainAll(){
527 <        PriorityBlockingQueue q = populatedQueue(SIZE);
528 <        PriorityBlockingQueue p = populatedQueue(SIZE);
526 >    /**
527 >     * retainAll(c) retains only those elements of c and reports true if changed
528 >     */
529 >    public void testRetainAll() {
530 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
531 >        PriorityBlockingQueue<Item> p = populatedQueue(SIZE);
532          for (int i = 0; i < SIZE; ++i) {
533              boolean changed = q.retainAll(p);
534              if (i == 0)
# Line 524 | Line 537 | public class PriorityBlockingQueueTest e
537                  assertTrue(changed);
538  
539              assertTrue(q.containsAll(p));
540 <            assertEquals(SIZE-i, q.size());
540 >            mustEqual(SIZE - i, q.size());
541              p.remove();
542          }
543      }
544  
545 <    public void testRemoveAll(){
545 >    /**
546 >     * removeAll(c) removes only those elements of c and reports true if changed
547 >     */
548 >    public void testRemoveAll() {
549          for (int i = 1; i < SIZE; ++i) {
550 <            PriorityBlockingQueue q = populatedQueue(SIZE);
551 <            PriorityBlockingQueue p = populatedQueue(i);
550 >            PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
551 >            PriorityBlockingQueue<Item> p = populatedQueue(i);
552              assertTrue(q.removeAll(p));
553 <            assertEquals(SIZE-i, q.size());
553 >            mustEqual(SIZE - i, q.size());
554              for (int j = 0; j < i; ++j) {
555 <                Integer I = (Integer)(p.remove());
556 <                assertFalse(q.contains(I));
555 >                Item x = p.remove();
556 >                mustNotContain(q, x);
557              }
558          }
559      }
560  
561 <    public void testToArray(){
562 <        PriorityBlockingQueue q = populatedQueue(SIZE);
563 <        Object[] o = q.toArray();
564 <        Arrays.sort(o);
565 <        try {
566 <        for(int i = 0; i < o.length; i++)
567 <            assertEquals(o[i], q.take());
568 <        } catch (InterruptedException e){
569 <            fail("Unexpected exception");
570 <        }    
571 <    }
572 <
573 <    public void testToArray2(){
574 <        PriorityBlockingQueue q = populatedQueue(SIZE);
575 <        Integer[] ints = new Integer[SIZE];
576 <        ints = (Integer[])q.toArray(ints);
577 <        Arrays.sort(ints);
578 <        try {
579 <            for(int i = 0; i < ints.length; i++)
580 <                assertEquals(ints[i], q.take());
581 <        } catch (InterruptedException e){
582 <            fail("Unexpected exception");
583 <        }    
584 <    }
585 <    
586 <    public void testIterator(){
571 <        PriorityBlockingQueue q = populatedQueue(SIZE);
572 <        int i = 0;
573 <        Iterator it = q.iterator();
574 <        while(it.hasNext()) {
575 <            assertTrue(q.contains(it.next()));
576 <            ++i;
577 <        }
578 <        assertEquals(i, SIZE);
579 <    }
580 <
581 <    public void testIteratorRemove () {
582 <
583 <        final PriorityBlockingQueue q = new PriorityBlockingQueue(3);
584 <
585 <        q.add(new Integer(2));
586 <        q.add(new Integer(1));
587 <        q.add(new Integer(3));
561 >    /**
562 >     * toArray contains all elements
563 >     */
564 >    public void testToArray() throws InterruptedException {
565 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
566 >        Object[] a = q.toArray();
567 >        assertSame(Object[].class, a.getClass());
568 >        Arrays.sort(a);
569 >        for (Object o : a)
570 >            assertSame(o, q.take());
571 >        assertTrue(q.isEmpty());
572 >    }
573 >
574 >    /**
575 >     * toArray(a) contains all elements
576 >     */
577 >    public void testToArray2() throws InterruptedException {
578 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
579 >        Item[] items = new Item[SIZE];
580 >        Item[] array = q.toArray(items);
581 >        assertSame(items, array);
582 >        Arrays.sort(items);
583 >        for (Item o : items)
584 >            assertSame(o, q.take());
585 >        assertTrue(q.isEmpty());
586 >    }
587  
588 <        Iterator it = q.iterator();
588 >    /**
589 >     * toArray(incompatible array type) throws ArrayStoreException
590 >     */
591 >    public void testToArray1_BadArg() {
592 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
593 >        try {
594 >            q.toArray(new String[10]);
595 >            shouldThrow();
596 >        } catch (ArrayStoreException success) {}
597 >    }
598 >
599 >    /**
600 >     * iterator iterates through all elements
601 >     */
602 >    public void testIterator() {
603 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
604 >        Iterator<? extends Item> it = q.iterator();
605 >        int i;
606 >        for (i = 0; it.hasNext(); i++)
607 >            mustContain(q, it.next());
608 >        mustEqual(i, SIZE);
609 >        assertIteratorExhausted(it);
610 >    }
611 >
612 >    /**
613 >     * iterator of empty collection has no elements
614 >     */
615 >    public void testEmptyIterator() {
616 >        assertIteratorExhausted(new PriorityBlockingQueue<>().iterator());
617 >    }
618 >
619 >    /**
620 >     * iterator.remove removes current element
621 >     */
622 >    public void testIteratorRemove() {
623 >        final PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(3);
624 >        q.add(two);
625 >        q.add(one);
626 >        q.add(three);
627 >
628 >        Iterator<? extends Item> it = q.iterator();
629          it.next();
630          it.remove();
631  
632          it = q.iterator();
633 <        assertEquals(it.next(), new Integer(2));
634 <        assertEquals(it.next(), new Integer(3));
633 >        mustEqual(it.next(), two);
634 >        mustEqual(it.next(), three);
635          assertFalse(it.hasNext());
636      }
637  
638 <
639 <    public void testToString(){
640 <        PriorityBlockingQueue q = populatedQueue(SIZE);
638 >    /**
639 >     * toString contains toStrings of elements
640 >     */
641 >    public void testToString() {
642 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
643          String s = q.toString();
644          for (int i = 0; i < SIZE; ++i) {
645 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
645 >            assertTrue(s.contains(String.valueOf(i)));
646          }
647 <    }        
647 >    }
648  
649 +    /**
650 +     * timed poll transfers elements across Executor tasks
651 +     */
652      public void testPollInExecutor() {
653 +        final PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(2);
654 +        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
655 +        final ExecutorService executor = Executors.newFixedThreadPool(2);
656 +        try (PoolCleaner cleaner = cleaner(executor)) {
657 +            executor.execute(new CheckedRunnable() {
658 +                public void realRun() throws InterruptedException {
659 +                    assertNull(q.poll());
660 +                    threadsStarted.await();
661 +                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
662 +                    checkEmpty(q);
663 +                }});
664  
665 <        final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
665 >            executor.execute(new CheckedRunnable() {
666 >                public void realRun() throws InterruptedException {
667 >                    threadsStarted.await();
668 >                    q.put(one);
669 >                }});
670 >        }
671 >    }
672  
673 <        ExecutorService executor = Executors.newFixedThreadPool(2);
673 >    /**
674 >     * A deserialized/reserialized queue has same elements
675 >     */
676 >    public void testSerialization() throws Exception {
677 >        Queue<Item> x = populatedQueue(SIZE);
678 >        Queue<Item> y = serialClone(x);
679 >
680 >        assertNotSame(x, y);
681 >        mustEqual(x.size(), y.size());
682 >        while (!x.isEmpty()) {
683 >            assertFalse(y.isEmpty());
684 >            mustEqual(x.remove(), y.remove());
685 >        }
686 >        assertTrue(y.isEmpty());
687 >    }
688  
689 <        executor.execute(new Runnable() {
690 <            public void run() {
691 <                threadAssertNull(q.poll());
692 <                try {
693 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
694 <                    threadAssertTrue(q.isEmpty());
695 <                }
696 <                catch (InterruptedException e) {
697 <                    threadFail("should not be interrupted");
698 <                }
699 <            }
700 <        });
689 >    /**
690 >     * drainTo(c) empties queue into another collection c
691 >     */
692 >    public void testDrainTo() {
693 >        PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
694 >        ArrayList<Item> l = new ArrayList<>();
695 >        q.drainTo(l);
696 >        mustEqual(0, q.size());
697 >        mustEqual(SIZE, l.size());
698 >        for (int i = 0; i < SIZE; ++i)
699 >            mustEqual(l.get(i), i);
700 >        q.add(zero);
701 >        q.add(one);
702 >        assertFalse(q.isEmpty());
703 >        mustContain(q, one);
704 >        l.clear();
705 >        q.drainTo(l);
706 >        mustEqual(0, q.size());
707 >        mustEqual(2, l.size());
708 >        for (int i = 0; i < 2; ++i)
709 >            mustEqual(l.get(i), i);
710 >    }
711  
712 <        executor.execute(new Runnable() {
713 <            public void run() {
714 <                try {
715 <                    Thread.sleep(SMALL_DELAY_MS);
716 <                    q.put(new Integer(1));
717 <                }
718 <                catch (InterruptedException e) {
719 <                    threadFail("should not be interrupted");
720 <                }
636 <            }
637 <        });
638 <        
639 <        joinPool(executor);
712 >    /**
713 >     * drainTo empties queue
714 >     */
715 >    public void testDrainToWithActivePut() throws InterruptedException {
716 >        final PriorityBlockingQueue<Item> q = populatedQueue(SIZE);
717 >        Thread t = new Thread(new CheckedRunnable() {
718 >            public void realRun() {
719 >                q.put(new Item(SIZE + 1));
720 >            }});
721  
722 +        t.start();
723 +        ArrayList<Item> l = new ArrayList<>();
724 +        q.drainTo(l);
725 +        assertTrue(l.size() >= SIZE);
726 +        for (int i = 0; i < SIZE; ++i)
727 +            mustEqual(l.get(i), i);
728 +        t.join();
729 +        assertTrue(q.size() + l.size() >= SIZE);
730      }
731  
732 <    public void testSerialization() {
733 <        PriorityBlockingQueue q = populatedQueue(SIZE);
734 <        try {
735 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
736 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
737 <            out.writeObject(q);
738 <            out.close();
739 <
740 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
741 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
742 <            PriorityBlockingQueue r = (PriorityBlockingQueue)in.readObject();
743 <            assertEquals(q.size(), r.size());
744 <            while (!q.isEmpty())
745 <                assertEquals(q.remove(), r.remove());
746 <        } catch(Exception e){
747 <            fail("unexpected exception");
732 >    /**
733 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
734 >     */
735 >    public void testDrainToN() {
736 >        PriorityBlockingQueue<Item> q = new PriorityBlockingQueue<>(SIZE * 2);
737 >        for (int i = 0; i < SIZE + 2; ++i) {
738 >            for (int j = 0; j < SIZE; j++)
739 >                mustOffer(q, j);
740 >            ArrayList<Item> l = new ArrayList<>();
741 >            q.drainTo(l, i);
742 >            int k = (i < SIZE) ? i : SIZE;
743 >            mustEqual(k, l.size());
744 >            mustEqual(SIZE - k, q.size());
745 >            for (int j = 0; j < k; ++j)
746 >                mustEqual(l.get(j), j);
747 >            do {} while (q.poll() != null);
748 >        }
749 >    }
750 >
751 >    /**
752 >     * remove(null), contains(null) always return false
753 >     */
754 >    public void testNeverContainsNull() {
755 >        Collection<?>[] qs = {
756 >            new PriorityBlockingQueue<>(),
757 >            populatedQueue(2),
758 >        };
759 >
760 >        for (Collection<?> q : qs) {
761 >            assertFalse(q.contains(null));
762 >            assertFalse(q.remove(null));
763          }
764      }
765  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines