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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.47 by jsr166, Tue Feb 21 02:04:17 2012 UTC vs.
Revision 1.66 by jsr166, Mon Oct 17 01:31:30 2016 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
8 < import java.util.Arrays;
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 >
9   import java.util.ArrayList;
10 + import java.util.Arrays;
11   import java.util.Collection;
12 + import java.util.Deque;
13   import java.util.Iterator;
14   import java.util.NoSuchElementException;
15   import java.util.Queue;
# Line 17 | Line 19 | import java.util.concurrent.CountDownLat
19   import java.util.concurrent.Executors;
20   import java.util.concurrent.ExecutorService;
21   import java.util.concurrent.LinkedBlockingDeque;
22 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
22 >
23 > import junit.framework.Test;
24  
25   public class LinkedBlockingDequeTest extends JSR166TestCase {
26  
# Line 34 | Line 37 | public class LinkedBlockingDequeTest ext
37      }
38  
39      public static void main(String[] args) {
40 <        junit.textui.TestRunner.run(suite());
40 >        main(suite(), args);
41      }
42  
43      public static Test suite() {
44 +        class Implementation implements CollectionImplementation {
45 +            public Class<?> klazz() { return LinkedBlockingDeque.class; }
46 +            public Collection emptyCollection() { return new LinkedBlockingDeque(); }
47 +            public Object makeElement(int i) { return i; }
48 +            public boolean isConcurrent() { return true; }
49 +            public boolean permitsNulls() { return false; }
50 +        }
51          return newTestSuite(LinkedBlockingDequeTest.class,
52                              new Unbounded().testSuite(),
53 <                            new Bounded().testSuite());
53 >                            new Bounded().testSuite(),
54 >                            CollectionTest.testSuite(new Implementation()));
55      }
56  
57      /**
58       * Returns a new deque of given size containing consecutive
59 <     * Integers 0 ... n.
59 >     * Integers 0 ... n - 1.
60       */
61      private LinkedBlockingDeque<Integer> populatedDeque(int n) {
62          LinkedBlockingDeque<Integer> q =
# Line 56 | Line 67 | public class LinkedBlockingDequeTest ext
67          assertFalse(q.isEmpty());
68          assertEquals(0, q.remainingCapacity());
69          assertEquals(n, q.size());
70 +        assertEquals((Integer) 0, q.peekFirst());
71 +        assertEquals((Integer) (n - 1), q.peekLast());
72          return q;
73      }
74  
# Line 79 | Line 92 | public class LinkedBlockingDequeTest ext
92      public void testSize() {
93          LinkedBlockingDeque q = populatedDeque(SIZE);
94          for (int i = 0; i < SIZE; ++i) {
95 <            assertEquals(SIZE-i, q.size());
95 >            assertEquals(SIZE - i, q.size());
96              q.removeFirst();
97          }
98          for (int i = 0; i < SIZE; ++i) {
# Line 144 | Line 157 | public class LinkedBlockingDequeTest ext
157       */
158      public void testPollLast() {
159          LinkedBlockingDeque q = populatedDeque(SIZE);
160 <        for (int i = SIZE-1; i >= 0; --i) {
160 >        for (int i = SIZE - 1; i >= 0; --i) {
161              assertEquals(i, q.pollLast());
162          }
163          assertNull(q.pollLast());
# Line 183 | Line 196 | public class LinkedBlockingDequeTest ext
196       */
197      public void testPeekLast() {
198          LinkedBlockingDeque q = populatedDeque(SIZE);
199 <        for (int i = SIZE-1; i >= 0; --i) {
199 >        for (int i = SIZE - 1; i >= 0; --i) {
200              assertEquals(i, q.peekLast());
201              assertEquals(i, q.pollLast());
202              assertTrue(q.peekLast() == null ||
# Line 213 | Line 226 | public class LinkedBlockingDequeTest ext
226       */
227      public void testLastElement() {
228          LinkedBlockingDeque q = populatedDeque(SIZE);
229 <        for (int i = SIZE-1; i >= 0; --i) {
229 >        for (int i = SIZE - 1; i >= 0; --i) {
230              assertEquals(i, q.getLast());
231              assertEquals(i, q.pollLast());
232          }
# Line 273 | Line 286 | public class LinkedBlockingDequeTest ext
286       */
287      public void testRemoveFirstOccurrence() {
288          LinkedBlockingDeque q = populatedDeque(SIZE);
289 <        for (int i = 1; i < SIZE; i+=2) {
289 >        for (int i = 1; i < SIZE; i += 2) {
290              assertTrue(q.removeFirstOccurrence(new Integer(i)));
291          }
292 <        for (int i = 0; i < SIZE; i+=2) {
292 >        for (int i = 0; i < SIZE; i += 2) {
293              assertTrue(q.removeFirstOccurrence(new Integer(i)));
294 <            assertFalse(q.removeFirstOccurrence(new Integer(i+1)));
294 >            assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
295          }
296          assertTrue(q.isEmpty());
297      }
# Line 288 | Line 301 | public class LinkedBlockingDequeTest ext
301       */
302      public void testRemoveLastOccurrence() {
303          LinkedBlockingDeque q = populatedDeque(SIZE);
304 <        for (int i = 1; i < SIZE; i+=2) {
304 >        for (int i = 1; i < SIZE; i += 2) {
305              assertTrue(q.removeLastOccurrence(new Integer(i)));
306          }
307 <        for (int i = 0; i < SIZE; i+=2) {
307 >        for (int i = 0; i < SIZE; i += 2) {
308              assertTrue(q.removeLastOccurrence(new Integer(i)));
309 <            assertFalse(q.removeLastOccurrence(new Integer(i+1)));
309 >            assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
310          }
311          assertTrue(q.isEmpty());
312      }
# Line 364 | Line 377 | public class LinkedBlockingDequeTest ext
377       */
378      public void testConstructor5() {
379          Integer[] ints = new Integer[SIZE];
380 <        for (int i = 0; i < SIZE-1; ++i)
380 >        for (int i = 0; i < SIZE - 1; ++i)
381              ints[i] = i;
382          Collection<Integer> elements = Arrays.asList(ints);
383          try {
# Line 404 | Line 417 | public class LinkedBlockingDequeTest ext
417       * remainingCapacity decreases on add, increases on remove
418       */
419      public void testRemainingCapacity() {
420 <        LinkedBlockingDeque q = populatedDeque(SIZE);
420 >        BlockingQueue q = populatedDeque(SIZE);
421          for (int i = 0; i < SIZE; ++i) {
422              assertEquals(i, q.remainingCapacity());
423 <            assertEquals(SIZE-i, q.size());
424 <            q.remove();
423 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
424 >            assertEquals(i, q.remove());
425          }
426          for (int i = 0; i < SIZE; ++i) {
427 <            assertEquals(SIZE-i, q.remainingCapacity());
428 <            assertEquals(i, q.size());
429 <            q.add(new Integer(i));
427 >            assertEquals(SIZE - i, q.remainingCapacity());
428 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
429 >            assertTrue(q.add(i));
430          }
431      }
432  
# Line 421 | Line 434 | public class LinkedBlockingDequeTest ext
434       * push(null) throws NPE
435       */
436      public void testPushNull() {
437 +        LinkedBlockingDeque q = new LinkedBlockingDeque(1);
438          try {
425            LinkedBlockingDeque q = new LinkedBlockingDeque(1);
439              q.push(null);
440              shouldThrow();
441          } catch (NullPointerException success) {}
# Line 432 | Line 445 | public class LinkedBlockingDequeTest ext
445       * push succeeds if not full; throws ISE if full
446       */
447      public void testPush() {
448 +        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
449 +        for (int i = 0; i < SIZE; ++i) {
450 +            Integer x = new Integer(i);
451 +            q.push(x);
452 +            assertEquals(x, q.peek());
453 +        }
454 +        assertEquals(0, q.remainingCapacity());
455          try {
436            LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
437            for (int i = 0; i < SIZE; ++i) {
438                Integer I = new Integer(i);
439                q.push(I);
440                assertEquals(I, q.peek());
441            }
442            assertEquals(0, q.remainingCapacity());
456              q.push(new Integer(SIZE));
457              shouldThrow();
458          } catch (IllegalStateException success) {}
# Line 510 | Line 523 | public class LinkedBlockingDequeTest ext
523      public void testAddAll3() {
524          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
525          Integer[] ints = new Integer[SIZE];
526 <        for (int i = 0; i < SIZE-1; ++i)
526 >        for (int i = 0; i < SIZE - 1; ++i)
527              ints[i] = new Integer(i);
528          Collection<Integer> elements = Arrays.asList(ints);
529          try {
# Line 555 | Line 568 | public class LinkedBlockingDequeTest ext
568      public void testPut() throws InterruptedException {
569          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
570          for (int i = 0; i < SIZE; ++i) {
571 <            Integer I = new Integer(i);
572 <            q.put(I);
573 <            assertTrue(q.contains(I));
571 >            Integer x = new Integer(i);
572 >            q.put(x);
573 >            assertTrue(q.contains(x));
574          }
575          assertEquals(0, q.remainingCapacity());
576      }
# Line 748 | Line 761 | public class LinkedBlockingDequeTest ext
761          final CountDownLatch aboutToWait = new CountDownLatch(1);
762          Thread t = newStartedThread(new CheckedRunnable() {
763              public void realRun() throws InterruptedException {
764 +                long startTime = System.nanoTime();
765                  for (int i = 0; i < SIZE; ++i) {
752                    long t0 = System.nanoTime();
766                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
754                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
767                  }
756                long t0 = System.nanoTime();
768                  aboutToWait.countDown();
769                  try {
770 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
770 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
771                      shouldThrow();
772                  } catch (InterruptedException success) {
773 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
773 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
774                  }
775              }});
776  
777          aboutToWait.await();
778 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
778 >        waitForThreadToEnterWaitState(t);
779          t.interrupt();
780 <        awaitTermination(t, MEDIUM_DELAY_MS);
780 >        awaitTermination(t);
781          checkEmpty(q);
782      }
783  
# Line 787 | Line 798 | public class LinkedBlockingDequeTest ext
798      public void testPutFirst() throws InterruptedException {
799          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800          for (int i = 0; i < SIZE; ++i) {
801 <            Integer I = new Integer(i);
802 <            q.putFirst(I);
803 <            assertTrue(q.contains(I));
801 >            Integer x = new Integer(i);
802 >            q.putFirst(x);
803 >            assertTrue(q.contains(x));
804          }
805          assertEquals(0, q.remainingCapacity());
806      }
# Line 1047 | Line 1058 | public class LinkedBlockingDequeTest ext
1058       * returning timeout status
1059       */
1060      public void testInterruptedTimedPollFirst() throws InterruptedException {
1061 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1062          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1063          Thread t = newStartedThread(new CheckedRunnable() {
1064              public void realRun() throws InterruptedException {
1065 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1065 >                long startTime = System.nanoTime();
1066                  for (int i = 0; i < SIZE; ++i) {
1067                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1068                  }
1069  
1070                  Thread.currentThread().interrupt();
1071                  try {
1072 <                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
1072 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1073                      shouldThrow();
1074                  } catch (InterruptedException success) {}
1075                  assertFalse(Thread.interrupted());
1076  
1077                  pleaseInterrupt.countDown();
1078                  try {
1079 <                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
1079 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1080                      shouldThrow();
1081                  } catch (InterruptedException success) {}
1082                  assertFalse(Thread.interrupted());
1083 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1084              }});
1085  
1086          await(pleaseInterrupt);
# Line 1134 | Line 1147 | public class LinkedBlockingDequeTest ext
1147      public void testPutLast() throws InterruptedException {
1148          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1149          for (int i = 0; i < SIZE; ++i) {
1150 <            Integer I = new Integer(i);
1151 <            q.putLast(I);
1152 <            assertTrue(q.contains(I));
1150 >            Integer x = new Integer(i);
1151 >            q.putLast(x);
1152 >            assertTrue(q.contains(x));
1153          }
1154          assertEquals(0, q.remainingCapacity());
1155      }
# Line 1243 | Line 1256 | public class LinkedBlockingDequeTest ext
1256      public void testTakeLast() throws InterruptedException {
1257          LinkedBlockingDeque q = populatedDeque(SIZE);
1258          for (int i = 0; i < SIZE; ++i) {
1259 <            assertEquals(SIZE-i-1, q.takeLast());
1259 >            assertEquals(SIZE - i - 1, q.takeLast());
1260          }
1261      }
1262  
# Line 1256 | Line 1269 | public class LinkedBlockingDequeTest ext
1269          Thread t = newStartedThread(new CheckedRunnable() {
1270              public void realRun() throws InterruptedException {
1271                  for (int i = 0; i < SIZE; ++i) {
1272 <                    assertEquals(SIZE-i-1, q.takeLast());
1272 >                    assertEquals(SIZE - i - 1, q.takeLast());
1273                  }
1274  
1275                  Thread.currentThread().interrupt();
# Line 1286 | Line 1299 | public class LinkedBlockingDequeTest ext
1299      public void testTimedPollLast0() throws InterruptedException {
1300          LinkedBlockingDeque q = populatedDeque(SIZE);
1301          for (int i = 0; i < SIZE; ++i) {
1302 <            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1302 >            assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS));
1303          }
1304          assertNull(q.pollLast(0, MILLISECONDS));
1305      }
# Line 1298 | Line 1311 | public class LinkedBlockingDequeTest ext
1311          LinkedBlockingDeque q = populatedDeque(SIZE);
1312          for (int i = 0; i < SIZE; ++i) {
1313              long startTime = System.nanoTime();
1314 <            assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1314 >            assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1315              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1316          }
1317          long startTime = System.nanoTime();
# Line 1312 | Line 1325 | public class LinkedBlockingDequeTest ext
1325       * returning timeout status
1326       */
1327      public void testInterruptedTimedPollLast() throws InterruptedException {
1328 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1329          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1330          Thread t = newStartedThread(new CheckedRunnable() {
1331              public void realRun() throws InterruptedException {
1332 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1332 >                long startTime = System.nanoTime();
1333                  for (int i = 0; i < SIZE; ++i) {
1334 <                    assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1334 >                    assertEquals(SIZE - i - 1,
1335 >                                 q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1336                  }
1337  
1338                  Thread.currentThread().interrupt();
# Line 1333 | Line 1348 | public class LinkedBlockingDequeTest ext
1348                      shouldThrow();
1349                  } catch (InterruptedException success) {}
1350                  assertFalse(Thread.interrupted());
1351 +
1352 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1353              }});
1354  
1355          await(pleaseInterrupt);
1356          assertThreadStaysAlive(t);
1357          t.interrupt();
1358          awaitTermination(t);
1359 +        checkEmpty(q);
1360      }
1361  
1362      /**
# Line 1371 | Line 1389 | public class LinkedBlockingDequeTest ext
1389                      shouldThrow();
1390                  } catch (InterruptedException success) {}
1391                  assertFalse(Thread.interrupted());
1392 +
1393 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1394              }});
1395  
1396          barrier.await();
# Line 1455 | Line 1475 | public class LinkedBlockingDequeTest ext
1475                  assertTrue(changed);
1476  
1477              assertTrue(q.containsAll(p));
1478 <            assertEquals(SIZE-i, q.size());
1478 >            assertEquals(SIZE - i, q.size());
1479              p.remove();
1480          }
1481      }
# Line 1468 | Line 1488 | public class LinkedBlockingDequeTest ext
1488              LinkedBlockingDeque q = populatedDeque(SIZE);
1489              LinkedBlockingDeque p = populatedDeque(i);
1490              assertTrue(q.removeAll(p));
1491 <            assertEquals(SIZE-i, q.size());
1491 >            assertEquals(SIZE - i, q.size());
1492              for (int j = 0; j < i; ++j) {
1493 <                Integer I = (Integer)(p.remove());
1494 <                assertFalse(q.contains(I));
1493 >                Integer x = (Integer)(p.remove());
1494 >                assertFalse(q.contains(x));
1495              }
1496          }
1497      }
# Line 1515 | Line 1535 | public class LinkedBlockingDequeTest ext
1535      public void testIterator() throws InterruptedException {
1536          LinkedBlockingDeque q = populatedDeque(SIZE);
1537          Iterator it = q.iterator();
1538 <        while (it.hasNext()) {
1538 >        int i;
1539 >        for (i = 0; it.hasNext(); i++)
1540 >            assertTrue(q.contains(it.next()));
1541 >        assertEquals(i, SIZE);
1542 >        assertIteratorExhausted(it);
1543 >
1544 >        it = q.iterator();
1545 >        for (i = 0; it.hasNext(); i++)
1546              assertEquals(it.next(), q.take());
1547 <        }
1547 >        assertEquals(i, SIZE);
1548 >        assertIteratorExhausted(it);
1549 >    }
1550 >
1551 >    /**
1552 >     * iterator of empty collection has no elements
1553 >     */
1554 >    public void testEmptyIterator() {
1555 >        Deque c = new LinkedBlockingDeque();
1556 >        assertIteratorExhausted(c.iterator());
1557 >        assertIteratorExhausted(c.descendingIterator());
1558      }
1559  
1560      /**
# Line 1650 | Line 1687 | public class LinkedBlockingDequeTest ext
1687          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1688          q.add(one);
1689          q.add(two);
1653        ExecutorService executor = Executors.newFixedThreadPool(2);
1690          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1691 <        executor.execute(new CheckedRunnable() {
1692 <            public void realRun() throws InterruptedException {
1693 <                assertFalse(q.offer(three));
1694 <                threadsStarted.await();
1695 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1696 <                assertEquals(0, q.remainingCapacity());
1697 <            }});
1698 <
1699 <        executor.execute(new CheckedRunnable() {
1700 <            public void realRun() throws InterruptedException {
1701 <                threadsStarted.await();
1702 <                assertSame(one, q.take());
1703 <            }});
1704 <
1705 <        joinPool(executor);
1691 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1692 >        try (PoolCleaner cleaner = cleaner(executor)) {
1693 >            executor.execute(new CheckedRunnable() {
1694 >                public void realRun() throws InterruptedException {
1695 >                    assertFalse(q.offer(three));
1696 >                    threadsStarted.await();
1697 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1698 >                    assertEquals(0, q.remainingCapacity());
1699 >                }});
1700 >
1701 >            executor.execute(new CheckedRunnable() {
1702 >                public void realRun() throws InterruptedException {
1703 >                    threadsStarted.await();
1704 >                    assertSame(one, q.take());
1705 >                }});
1706 >        }
1707      }
1708  
1709      /**
# Line 1675 | Line 1712 | public class LinkedBlockingDequeTest ext
1712      public void testPollInExecutor() {
1713          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1714          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1715 <        ExecutorService executor = Executors.newFixedThreadPool(2);
1716 <        executor.execute(new CheckedRunnable() {
1717 <            public void realRun() throws InterruptedException {
1718 <                assertNull(q.poll());
1719 <                threadsStarted.await();
1720 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1721 <                checkEmpty(q);
1722 <            }});
1723 <
1724 <        executor.execute(new CheckedRunnable() {
1725 <            public void realRun() throws InterruptedException {
1726 <                threadsStarted.await();
1727 <                q.put(one);
1728 <            }});
1729 <
1730 <        joinPool(executor);
1715 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1716 >        try (PoolCleaner cleaner = cleaner(executor)) {
1717 >            executor.execute(new CheckedRunnable() {
1718 >                public void realRun() throws InterruptedException {
1719 >                    assertNull(q.poll());
1720 >                    threadsStarted.await();
1721 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1722 >                    checkEmpty(q);
1723 >                }});
1724 >
1725 >            executor.execute(new CheckedRunnable() {
1726 >                public void realRun() throws InterruptedException {
1727 >                    threadsStarted.await();
1728 >                    q.put(one);
1729 >                }});
1730 >        }
1731      }
1732  
1733      /**
# Line 1700 | Line 1737 | public class LinkedBlockingDequeTest ext
1737          Queue x = populatedDeque(SIZE);
1738          Queue y = serialClone(x);
1739  
1740 <        assertTrue(x != y);
1740 >        assertNotSame(y, x);
1741          assertEquals(x.size(), y.size());
1742          assertEquals(x.toString(), y.toString());
1743          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 1742 | Line 1779 | public class LinkedBlockingDequeTest ext
1779          final LinkedBlockingDeque q = populatedDeque(SIZE);
1780          Thread t = new Thread(new CheckedRunnable() {
1781              public void realRun() throws InterruptedException {
1782 <                q.put(new Integer(SIZE+1));
1782 >                q.put(new Integer(SIZE + 1));
1783              }});
1784  
1785          t.start();
# Line 1767 | Line 1804 | public class LinkedBlockingDequeTest ext
1804              q.drainTo(l, i);
1805              int k = (i < SIZE) ? i : SIZE;
1806              assertEquals(k, l.size());
1807 <            assertEquals(SIZE-k, q.size());
1807 >            assertEquals(SIZE - k, q.size());
1808              for (int j = 0; j < k; ++j)
1809                  assertEquals(l.get(j), new Integer(j));
1810 <            while (q.poll() != null) ;
1810 >            do {} while (q.poll() != null);
1811 >        }
1812 >    }
1813 >
1814 >    /**
1815 >     * remove(null), contains(null) always return false
1816 >     */
1817 >    public void testNeverContainsNull() {
1818 >        Deque<?>[] qs = {
1819 >            new LinkedBlockingDeque<Object>(),
1820 >            populatedDeque(2),
1821 >        };
1822 >
1823 >        for (Deque<?> q : qs) {
1824 >            assertFalse(q.contains(null));
1825 >            assertFalse(q.remove(null));
1826 >            assertFalse(q.removeFirstOccurrence(null));
1827 >            assertFalse(q.removeLastOccurrence(null));
1828          }
1829      }
1830  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines