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.5 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.14 by jsr166, Sat Nov 21 21:00:34 2009 UTC

# Line 7 | Line 7
7   import junit.framework.*;
8   import java.util.*;
9   import java.util.concurrent.*;
10 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
11   import java.io.*;
12  
13   public class LinkedBlockingDequeTest extends JSR166TestCase {
14      public static void main(String[] args) {
15 <        junit.textui.TestRunner.run (suite());
15 >        junit.textui.TestRunner.run (suite());
16      }
17  
18      public static Test suite() {
19 <        return new TestSuite(LinkedBlockingDequeTest.class);
19 >        return new TestSuite(LinkedBlockingDequeTest.class);
20      }
21  
22      /**
# Line 25 | Line 26 | public class LinkedBlockingDequeTest ext
26      private LinkedBlockingDeque populatedDeque(int n) {
27          LinkedBlockingDeque q = new LinkedBlockingDeque(n);
28          assertTrue(q.isEmpty());
29 <        for (int i = 0; i < n; i++)
30 <            assertTrue(q.offer(new Integer(i)));
29 >        for (int i = 0; i < n; i++)
30 >            assertTrue(q.offer(new Integer(i)));
31          assertFalse(q.isEmpty());
32          assertEquals(0, q.remainingCapacity());
33 <        assertEquals(n, q.size());
33 >        assertEquals(n, q.size());
34          return q;
35      }
36  
# Line 66 | Line 67 | public class LinkedBlockingDequeTest ext
67       * offer(null) throws NPE
68       */
69      public void testOfferFirstNull() {
70 <        try {
70 >        try {
71              LinkedBlockingDeque q = new LinkedBlockingDeque();
72              q.offerFirst(null);
73              shouldThrow();
74 <        } catch (NullPointerException success) {
74 <        }
74 >        } catch (NullPointerException success) {}
75      }
76  
77      /**
# Line 100 | Line 100 | public class LinkedBlockingDequeTest ext
100          for (int i = 0; i < SIZE; ++i) {
101              assertEquals(i, ((Integer)q.pollFirst()).intValue());
102          }
103 <        assertNull(q.pollFirst());
103 >        assertNull(q.pollFirst());
104      }
105  
106      /**
# Line 111 | Line 111 | public class LinkedBlockingDequeTest ext
111          for (int i = SIZE-1; i >= 0; --i) {
112              assertEquals(i, ((Integer)q.pollLast()).intValue());
113          }
114 <        assertNull(q.pollLast());
114 >        assertNull(q.pollLast());
115      }
116  
117      /**
# Line 125 | Line 125 | public class LinkedBlockingDequeTest ext
125              assertTrue(q.peekFirst() == null ||
126                         i != ((Integer)q.peekFirst()).intValue());
127          }
128 <        assertNull(q.peekFirst());
128 >        assertNull(q.peekFirst());
129      }
130  
131      /**
# Line 139 | Line 139 | public class LinkedBlockingDequeTest ext
139              assertTrue(q.peek() == null ||
140                         i != ((Integer)q.peek()).intValue());
141          }
142 <        assertNull(q.peek());
142 >        assertNull(q.peek());
143      }
144  
145      /**
# Line 153 | Line 153 | public class LinkedBlockingDequeTest ext
153              assertTrue(q.peekLast() == null ||
154                         i != ((Integer)q.peekLast()).intValue());
155          }
156 <        assertNull(q.peekLast());
156 >        assertNull(q.peekLast());
157      }
158  
159      /**
# Line 168 | Line 168 | public class LinkedBlockingDequeTest ext
168          try {
169              q.getFirst();
170              shouldThrow();
171 <        }
172 <        catch (NoSuchElementException success) {}
171 >        } catch (NoSuchElementException success) {}
172      }
173  
174      /**
# Line 184 | Line 183 | public class LinkedBlockingDequeTest ext
183          try {
184              q.getLast();
185              shouldThrow();
186 <        }
187 <        catch (NoSuchElementException success) {}
189 <        assertNull(q.peekLast());
186 >        } catch (NoSuchElementException success) {}
187 >        assertNull(q.peekLast());
188      }
189  
190      /**
# Line 200 | Line 198 | public class LinkedBlockingDequeTest ext
198          try {
199              q.removeFirst();
200              shouldThrow();
201 <        } catch (NoSuchElementException success){
204 <        }
201 >        } catch (NoSuchElementException success) {}
202      }
203  
204      /**
# Line 215 | Line 212 | public class LinkedBlockingDequeTest ext
212          try {
213              q.remove();
214              shouldThrow();
215 <        } catch (NoSuchElementException success){
219 <        }
215 >        } catch (NoSuchElementException success) {}
216      }
217  
218      /**
# Line 255 | Line 251 | public class LinkedBlockingDequeTest ext
251      public void testAddFirst() {
252          LinkedBlockingDeque q = populatedDeque(3);
253          q.pollLast();
254 <        q.addFirst(four);
255 <        assertEquals(four,q.peekFirst());
254 >        q.addFirst(four);
255 >        assertEquals(four,q.peekFirst());
256      }
257  
258      /**
# Line 265 | Line 261 | public class LinkedBlockingDequeTest ext
261      public void testAddLast() {
262          LinkedBlockingDeque q = populatedDeque(3);
263          q.pollLast();
264 <        q.addLast(four);
265 <        assertEquals(four,q.peekLast());
264 >        q.addLast(four);
265 >        assertEquals(four,q.peekLast());
266      }
267  
268  
# Line 280 | Line 276 | public class LinkedBlockingDequeTest ext
276      }
277  
278      /**
279 <     * Constructor throws IAE if  capacity argument nonpositive
279 >     * Constructor throws IAE if capacity argument nonpositive
280       */
281      public void testConstructor2() {
282          try {
283              LinkedBlockingDeque q = new LinkedBlockingDeque(0);
284              shouldThrow();
285 <        }
290 <        catch (IllegalArgumentException success) {}
285 >        } catch (IllegalArgumentException success) {}
286      }
287  
288      /**
# Line 297 | Line 292 | public class LinkedBlockingDequeTest ext
292          try {
293              LinkedBlockingDeque q = new LinkedBlockingDeque(null);
294              shouldThrow();
295 <        }
301 <        catch (NullPointerException success) {}
295 >        } catch (NullPointerException success) {}
296      }
297  
298      /**
# Line 309 | Line 303 | public class LinkedBlockingDequeTest ext
303              Integer[] ints = new Integer[SIZE];
304              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
305              shouldThrow();
306 <        }
313 <        catch (NullPointerException success) {}
306 >        } catch (NullPointerException success) {}
307      }
308  
309      /**
# Line 323 | Line 316 | public class LinkedBlockingDequeTest ext
316                  ints[i] = new Integer(i);
317              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
318              shouldThrow();
319 <        }
327 <        catch (NullPointerException success) {}
319 >        } catch (NullPointerException success) {}
320      }
321  
322      /**
323       * Deque contains all elements of collection used to initialize
324       */
325      public void testConstructor6() {
326 <        try {
327 <            Integer[] ints = new Integer[SIZE];
328 <            for (int i = 0; i < SIZE; ++i)
329 <                ints[i] = new Integer(i);
330 <            LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
331 <            for (int i = 0; i < SIZE; ++i)
340 <                assertEquals(ints[i], q.poll());
341 <        }
342 <        finally {}
326 >        Integer[] ints = new Integer[SIZE];
327 >        for (int i = 0; i < SIZE; ++i)
328 >            ints[i] = new Integer(i);
329 >        LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
330 >        for (int i = 0; i < SIZE; ++i)
331 >            assertEquals(ints[i], q.poll());
332      }
333  
334      /**
# Line 378 | Line 367 | public class LinkedBlockingDequeTest ext
367       * offer(null) throws NPE
368       */
369      public void testOfferNull() {
370 <        try {
370 >        try {
371              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
372              q.offer(null);
373              shouldThrow();
374 <        } catch (NullPointerException success) { }
374 >        } catch (NullPointerException success) {}
375      }
376  
377      /**
378       * add(null) throws NPE
379       */
380      public void testAddNull() {
381 <        try {
381 >        try {
382              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
383              q.add(null);
384              shouldThrow();
385 <        } catch (NullPointerException success) { }
385 >        } catch (NullPointerException success) {}
386      }
387  
388      /**
389       * push(null) throws NPE
390       */
391      public void testPushNull() {
392 <        try {
392 >        try {
393              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
394              q.push(null);
395              shouldThrow();
396 <        } catch (NullPointerException success) { }
396 >        } catch (NullPointerException success) {}
397      }
398  
399      /**
400       * push succeeds if not full; throws ISE if full
401       */
402      public void testPush() {
403 <        try {
403 >        try {
404              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
405              for (int i = 0; i < SIZE; ++i) {
406                  Integer I = new Integer(i);
# Line 420 | Line 409 | public class LinkedBlockingDequeTest ext
409              }
410              assertEquals(0, q.remainingCapacity());
411              q.push(new Integer(SIZE));
412 <        } catch (IllegalStateException success){
413 <        }
412 >            shouldThrow();
413 >        } catch (IllegalStateException success) {}
414      }
415  
416      /**
# Line 430 | Line 419 | public class LinkedBlockingDequeTest ext
419      public void testPushWithPeek() {
420          LinkedBlockingDeque q = populatedDeque(3);
421          q.pollLast();
422 <        q.push(four);
423 <        assertEquals(four,q.peekFirst());
422 >        q.push(four);
423 >        assertEquals(four,q.peekFirst());
424      }
425  
426  
# Line 446 | Line 435 | public class LinkedBlockingDequeTest ext
435          try {
436              q.pop();
437              shouldThrow();
438 <        } catch (NoSuchElementException success){
450 <        }
438 >        } catch (NoSuchElementException success) {}
439      }
440  
441  
# Line 464 | Line 452 | public class LinkedBlockingDequeTest ext
452       * add succeeds if not full; throws ISE if full
453       */
454      public void testAdd() {
455 <        try {
455 >        try {
456              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
457              for (int i = 0; i < SIZE; ++i) {
458                  assertTrue(q.add(new Integer(i)));
459              }
460              assertEquals(0, q.remainingCapacity());
461              q.add(new Integer(SIZE));
462 <        } catch (IllegalStateException success){
463 <        }
462 >            shouldThrow();
463 >        } catch (IllegalStateException success) {}
464      }
465  
466      /**
# Line 483 | Line 471 | public class LinkedBlockingDequeTest ext
471              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
472              q.addAll(null);
473              shouldThrow();
474 <        }
487 <        catch (NullPointerException success) {}
474 >        } catch (NullPointerException success) {}
475      }
476  
477      /**
# Line 495 | Line 482 | public class LinkedBlockingDequeTest ext
482              LinkedBlockingDeque q = populatedDeque(SIZE);
483              q.addAll(q);
484              shouldThrow();
485 <        }
499 <        catch (IllegalArgumentException success) {}
485 >        } catch (IllegalArgumentException success) {}
486      }
487  
488      /**
# Line 508 | Line 494 | public class LinkedBlockingDequeTest ext
494              Integer[] ints = new Integer[SIZE];
495              q.addAll(Arrays.asList(ints));
496              shouldThrow();
497 <        }
512 <        catch (NullPointerException success) {}
497 >        } catch (NullPointerException success) {}
498      }
499      /**
500       * addAll of a collection with any null elements throws NPE after
# Line 523 | Line 508 | public class LinkedBlockingDequeTest ext
508                  ints[i] = new Integer(i);
509              q.addAll(Arrays.asList(ints));
510              shouldThrow();
511 <        }
527 <        catch (NullPointerException success) {}
511 >        } catch (NullPointerException success) {}
512      }
513      /**
514       * addAll throws ISE if not enough room
# Line 537 | Line 521 | public class LinkedBlockingDequeTest ext
521                  ints[i] = new Integer(i);
522              q.addAll(Arrays.asList(ints));
523              shouldThrow();
524 <        }
541 <        catch (IllegalStateException success) {}
524 >        } catch (IllegalStateException success) {}
525      }
526      /**
527       * Deque contains all elements, in traversal order, of successful addAll
528       */
529      public void testAddAll5() {
530 <        try {
531 <            Integer[] empty = new Integer[0];
532 <            Integer[] ints = new Integer[SIZE];
533 <            for (int i = 0; i < SIZE; ++i)
534 <                ints[i] = new Integer(i);
535 <            LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
536 <            assertFalse(q.addAll(Arrays.asList(empty)));
537 <            assertTrue(q.addAll(Arrays.asList(ints)));
538 <            for (int i = 0; i < SIZE; ++i)
556 <                assertEquals(ints[i], q.poll());
557 <        }
558 <        finally {}
530 >        Integer[] empty = new Integer[0];
531 >        Integer[] ints = new Integer[SIZE];
532 >        for (int i = 0; i < SIZE; ++i)
533 >            ints[i] = new Integer(i);
534 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
535 >        assertFalse(q.addAll(Arrays.asList(empty)));
536 >        assertTrue(q.addAll(Arrays.asList(ints)));
537 >        for (int i = 0; i < SIZE; ++i)
538 >            assertEquals(ints[i], q.poll());
539      }
540  
541  
542      /**
543       * put(null) throws NPE
544       */
545 <     public void testPutNull() {
546 <        try {
545 >    public void testPutNull() throws InterruptedException {
546 >        try {
547              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
548              q.put(null);
549              shouldThrow();
550 <        }
551 <        catch (NullPointerException success){
572 <        }
573 <        catch (InterruptedException ie) {
574 <            unexpectedException();
575 <        }
576 <     }
550 >        } catch (NullPointerException success) {}
551 >    }
552  
553      /**
554       * all elements successfully put are contained
555       */
556 <     public void testPut() {
557 <         try {
558 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
559 <             for (int i = 0; i < SIZE; ++i) {
560 <                 Integer I = new Integer(i);
561 <                 q.put(I);
587 <                 assertTrue(q.contains(I));
588 <             }
589 <             assertEquals(0, q.remainingCapacity());
590 <         }
591 <        catch (InterruptedException ie) {
592 <            unexpectedException();
556 >    public void testPut() throws InterruptedException {
557 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
558 >        for (int i = 0; i < SIZE; ++i) {
559 >            Integer I = new Integer(i);
560 >            q.put(I);
561 >            assertTrue(q.contains(I));
562          }
563 +        assertEquals(0, q.remainingCapacity());
564      }
565  
566      /**
567       * put blocks interruptibly if full
568       */
569 <    public void testBlockingPut() {
570 <        Thread t = new Thread(new Runnable() {
571 <                public void run() {
572 <                    int added = 0;
573 <                    try {
574 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
575 <                        for (int i = 0; i < SIZE; ++i) {
576 <                            q.put(new Integer(i));
577 <                            ++added;
608 <                        }
609 <                        q.put(new Integer(SIZE));
610 <                        threadShouldThrow();
611 <                    } catch (InterruptedException ie){
612 <                        threadAssertEquals(added, SIZE);
569 >    public void testBlockingPut() throws InterruptedException {
570 >        Thread t = new Thread(new CheckedRunnable() {
571 >            public void realRun() {
572 >                int added = 0;
573 >                try {
574 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
575 >                    for (int i = 0; i < SIZE; ++i) {
576 >                        q.put(new Integer(i));
577 >                        ++added;
578                      }
579 <                }});
579 >                    q.put(new Integer(SIZE));
580 >                    threadShouldThrow();
581 >                } catch (InterruptedException success) {
582 >                    threadAssertEquals(added, SIZE);
583 >                }
584 >            }});
585 >
586          t.start();
587 <        try {
588 <           Thread.sleep(SHORT_DELAY_MS);
589 <           t.interrupt();
619 <           t.join();
620 <        }
621 <        catch (InterruptedException ie) {
622 <            unexpectedException();
623 <        }
587 >        Thread.sleep(SHORT_DELAY_MS);
588 >        t.interrupt();
589 >        t.join();
590      }
591  
592      /**
593       * put blocks waiting for take when full
594       */
595 <    public void testPutWithTake() {
595 >    public void testPutWithTake() throws InterruptedException {
596          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
597 <        Thread t = new Thread(new Runnable() {
598 <                public void run() {
599 <                    int added = 0;
600 <                    try {
601 <                        q.put(new Object());
602 <                        ++added;
603 <                        q.put(new Object());
604 <                        ++added;
605 <                        q.put(new Object());
606 <                        ++added;
607 <                        q.put(new Object());
608 <                        ++added;
609 <                        threadShouldThrow();
610 <                    } catch (InterruptedException e){
611 <                        threadAssertTrue(added >= 2);
646 <                    }
597 >        Thread t = new Thread(new CheckedRunnable() {
598 >            public void realRun() {
599 >                int added = 0;
600 >                try {
601 >                    q.put(new Object());
602 >                    ++added;
603 >                    q.put(new Object());
604 >                    ++added;
605 >                    q.put(new Object());
606 >                    ++added;
607 >                    q.put(new Object());
608 >                    ++added;
609 >                    threadShouldThrow();
610 >                } catch (InterruptedException success) {
611 >                    threadAssertTrue(added >= 2);
612                  }
613 <            });
614 <        try {
615 <            t.start();
616 <            Thread.sleep(SHORT_DELAY_MS);
617 <            q.take();
618 <            t.interrupt();
619 <            t.join();
655 <        } catch (Exception e){
656 <            unexpectedException();
657 <        }
613 >            }});
614 >
615 >        t.start();
616 >        Thread.sleep(SHORT_DELAY_MS);
617 >        q.take();
618 >        t.interrupt();
619 >        t.join();
620      }
621  
622      /**
623       * timed offer times out if full and elements not taken
624       */
625 <    public void testTimedOffer() {
625 >    public void testTimedOffer() throws InterruptedException {
626          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
627 <        Thread t = new Thread(new Runnable() {
628 <                public void run() {
629 <                    try {
630 <                        q.put(new Object());
631 <                        q.put(new Object());
632 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
633 <                        q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
672 <                        threadShouldThrow();
673 <                    } catch (InterruptedException success){}
674 <                }
675 <            });
627 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
628 >            public void realRun() throws InterruptedException {
629 >                q.put(new Object());
630 >                q.put(new Object());
631 >                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
632 >                q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
633 >            }};
634  
635 <        try {
636 <            t.start();
637 <            Thread.sleep(SMALL_DELAY_MS);
638 <            t.interrupt();
681 <            t.join();
682 <        } catch (Exception e){
683 <            unexpectedException();
684 <        }
635 >        t.start();
636 >        Thread.sleep(SMALL_DELAY_MS);
637 >        t.interrupt();
638 >        t.join();
639      }
640  
641      /**
642       * take retrieves elements in FIFO order
643       */
644 <    public void testTake() {
645 <        try {
646 <            LinkedBlockingDeque q = populatedDeque(SIZE);
647 <            for (int i = 0; i < SIZE; ++i) {
648 <                assertEquals(i, ((Integer)q.take()).intValue());
695 <            }
696 <        } catch (InterruptedException e){
697 <            unexpectedException();
698 <        }
644 >    public void testTake() throws InterruptedException {
645 >        LinkedBlockingDeque q = populatedDeque(SIZE);
646 >        for (int i = 0; i < SIZE; ++i) {
647 >            assertEquals(i, ((Integer)q.take()).intValue());
648 >        }
649      }
650  
651      /**
652       * take blocks interruptibly when empty
653       */
654 <    public void testTakeFromEmpty() {
654 >    public void testTakeFromEmpty() throws InterruptedException {
655          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
656 <        Thread t = new Thread(new Runnable() {
657 <                public void run() {
658 <                    try {
659 <                        q.take();
660 <                        threadShouldThrow();
661 <                    } catch (InterruptedException success){ }
662 <                }
663 <            });
664 <        try {
715 <            t.start();
716 <            Thread.sleep(SHORT_DELAY_MS);
717 <            t.interrupt();
718 <            t.join();
719 <        } catch (Exception e){
720 <            unexpectedException();
721 <        }
656 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
657 >            public void realRun() throws InterruptedException {
658 >                q.take();
659 >            }};
660 >
661 >        t.start();
662 >        Thread.sleep(SHORT_DELAY_MS);
663 >        t.interrupt();
664 >        t.join();
665      }
666  
667      /**
668       * Take removes existing elements until empty, then blocks interruptibly
669       */
670 <    public void testBlockingTake() {
671 <        Thread t = new Thread(new Runnable() {
672 <                public void run() {
673 <                    try {
674 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
675 <                        for (int i = 0; i < SIZE; ++i) {
676 <                            assertEquals(i, ((Integer)q.take()).intValue());
677 <                        }
678 <                        q.take();
679 <                        threadShouldThrow();
737 <                    } catch (InterruptedException success){
738 <                    }
739 <                }});
670 >    public void testBlockingTake() throws InterruptedException {
671 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
672 >            public void realRun() throws InterruptedException {
673 >                LinkedBlockingDeque q = populatedDeque(SIZE);
674 >                for (int i = 0; i < SIZE; ++i) {
675 >                    assertEquals(i, ((Integer)q.take()).intValue());
676 >                }
677 >                q.take();
678 >            }};
679 >
680          t.start();
681 <        try {
682 <           Thread.sleep(SHORT_DELAY_MS);
683 <           t.interrupt();
744 <           t.join();
745 <        }
746 <        catch (InterruptedException ie) {
747 <            unexpectedException();
748 <        }
681 >        Thread.sleep(SHORT_DELAY_MS);
682 >        t.interrupt();
683 >        t.join();
684      }
685  
686  
# Line 757 | Line 692 | public class LinkedBlockingDequeTest ext
692          for (int i = 0; i < SIZE; ++i) {
693              assertEquals(i, ((Integer)q.poll()).intValue());
694          }
695 <        assertNull(q.poll());
695 >        assertNull(q.poll());
696      }
697  
698      /**
699       * timed poll with zero timeout succeeds when non-empty, else times out
700       */
701 <    public void testTimedPoll0() {
702 <        try {
703 <            LinkedBlockingDeque q = populatedDeque(SIZE);
704 <            for (int i = 0; i < SIZE; ++i) {
705 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
706 <            }
772 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
773 <        } catch (InterruptedException e){
774 <            unexpectedException();
775 <        }
701 >    public void testTimedPoll0() throws InterruptedException {
702 >        LinkedBlockingDeque q = populatedDeque(SIZE);
703 >        for (int i = 0; i < SIZE; ++i) {
704 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
705 >        }
706 >        assertNull(q.poll(0, MILLISECONDS));
707      }
708  
709      /**
710       * timed poll with nonzero timeout succeeds when non-empty, else times out
711       */
712 <    public void testTimedPoll() {
713 <        try {
714 <            LinkedBlockingDeque q = populatedDeque(SIZE);
715 <            for (int i = 0; i < SIZE; ++i) {
716 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
717 <            }
787 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
788 <        } catch (InterruptedException e){
789 <            unexpectedException();
790 <        }
712 >    public void testTimedPoll() throws InterruptedException {
713 >        LinkedBlockingDeque q = populatedDeque(SIZE);
714 >        for (int i = 0; i < SIZE; ++i) {
715 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
716 >        }
717 >        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
718      }
719  
720      /**
721       * Interrupted timed poll throws InterruptedException instead of
722       * returning timeout status
723       */
724 <    public void testInterruptedTimedPoll() {
725 <        Thread t = new Thread(new Runnable() {
726 <                public void run() {
727 <                    try {
728 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
729 <                        for (int i = 0; i < SIZE; ++i) {
730 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
731 <                        }
732 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
733 <                    } catch (InterruptedException success){
734 <                    }
735 <                }});
724 >    public void testInterruptedTimedPoll() throws InterruptedException {
725 >        Thread t = new Thread(new CheckedRunnable() {
726 >            public void realRun() throws InterruptedException {
727 >                LinkedBlockingDeque q = populatedDeque(SIZE);
728 >                for (int i = 0; i < SIZE; ++i) {
729 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
730 >                }
731 >                try {
732 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
733 >                    shouldThrow();
734 >                } catch (InterruptedException success) {}
735 >            }});
736 >
737          t.start();
738 <        try {
739 <           Thread.sleep(SHORT_DELAY_MS);
740 <           t.interrupt();
813 <           t.join();
814 <        }
815 <        catch (InterruptedException ie) {
816 <            unexpectedException();
817 <        }
738 >        Thread.sleep(SHORT_DELAY_MS);
739 >        t.interrupt();
740 >        t.join();
741      }
742  
743      /**
744       *  timed poll before a delayed offer fails; after offer succeeds;
745       *  on interruption throws
746       */
747 <    public void testTimedPollWithOffer() {
747 >    public void testTimedPollWithOffer() throws InterruptedException {
748          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
749 <        Thread t = new Thread(new Runnable() {
750 <                public void run() {
751 <                    try {
752 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
753 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
754 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
755 <                        threadShouldThrow();
756 <                    } catch (InterruptedException success) { }
757 <                }
758 <            });
759 <        try {
760 <            t.start();
761 <            Thread.sleep(SMALL_DELAY_MS);
762 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
763 <            t.interrupt();
841 <            t.join();
842 <        } catch (Exception e){
843 <            unexpectedException();
844 <        }
749 >        Thread t = new Thread(new CheckedRunnable() {
750 >            public void realRun() throws InterruptedException {
751 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
752 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
753 >                try {
754 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
755 >                    shouldThrow();
756 >                } catch (InterruptedException success) {}
757 >            }});
758 >
759 >        t.start();
760 >        Thread.sleep(SMALL_DELAY_MS);
761 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
762 >        t.interrupt();
763 >        t.join();
764      }
765  
766  
767      /**
768       * putFirst(null) throws NPE
769       */
770 <     public void testPutFirstNull() {
771 <        try {
770 >     public void testPutFirstNull() throws InterruptedException {
771 >        try {
772              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
773              q.putFirst(null);
774              shouldThrow();
775 <        }
857 <        catch (NullPointerException success){
858 <        }
859 <        catch (InterruptedException ie) {
860 <            unexpectedException();
861 <        }
775 >        } catch (NullPointerException success) {}
776       }
777  
778      /**
779       * all elements successfully putFirst are contained
780       */
781 <     public void testPutFirst() {
782 <         try {
783 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
784 <             for (int i = 0; i < SIZE; ++i) {
785 <                 Integer I = new Integer(i);
786 <                 q.putFirst(I);
873 <                 assertTrue(q.contains(I));
874 <             }
875 <             assertEquals(0, q.remainingCapacity());
781 >     public void testPutFirst() throws InterruptedException {
782 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
783 >         for (int i = 0; i < SIZE; ++i) {
784 >             Integer I = new Integer(i);
785 >             q.putFirst(I);
786 >             assertTrue(q.contains(I));
787           }
788 <        catch (InterruptedException ie) {
878 <            unexpectedException();
879 <        }
788 >         assertEquals(0, q.remainingCapacity());
789      }
790  
791      /**
792       * putFirst blocks interruptibly if full
793       */
794 <    public void testBlockingPutFirst() {
795 <        Thread t = new Thread(new Runnable() {
796 <                public void run() {
797 <                    int added = 0;
798 <                    try {
799 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800 <                        for (int i = 0; i < SIZE; ++i) {
801 <                            q.putFirst(new Integer(i));
802 <                            ++added;
894 <                        }
895 <                        q.putFirst(new Integer(SIZE));
896 <                        threadShouldThrow();
897 <                    } catch (InterruptedException ie){
898 <                        threadAssertEquals(added, SIZE);
794 >    public void testBlockingPutFirst() throws InterruptedException {
795 >        Thread t = new Thread(new CheckedRunnable() {
796 >            public void realRun() {
797 >                int added = 0;
798 >                try {
799 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800 >                    for (int i = 0; i < SIZE; ++i) {
801 >                        q.putFirst(new Integer(i));
802 >                        ++added;
803                      }
804 <                }});
804 >                    q.putFirst(new Integer(SIZE));
805 >                    threadShouldThrow();
806 >                } catch (InterruptedException success) {
807 >                    threadAssertEquals(added, SIZE);
808 >                }
809 >            }});
810 >
811          t.start();
812 <        try {
813 <           Thread.sleep(SHORT_DELAY_MS);
814 <           t.interrupt();
905 <           t.join();
906 <        }
907 <        catch (InterruptedException ie) {
908 <            unexpectedException();
909 <        }
812 >        Thread.sleep(SHORT_DELAY_MS);
813 >        t.interrupt();
814 >        t.join();
815      }
816  
817      /**
818       * putFirst blocks waiting for take when full
819       */
820 <    public void testPutFirstWithTake() {
820 >    public void testPutFirstWithTake() throws InterruptedException {
821          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
822 <        Thread t = new Thread(new Runnable() {
823 <                public void run() {
824 <                    int added = 0;
825 <                    try {
826 <                        q.putFirst(new Object());
827 <                        ++added;
828 <                        q.putFirst(new Object());
829 <                        ++added;
830 <                        q.putFirst(new Object());
831 <                        ++added;
832 <                        q.putFirst(new Object());
833 <                        ++added;
834 <                        threadShouldThrow();
835 <                    } catch (InterruptedException e){
836 <                        threadAssertTrue(added >= 2);
932 <                    }
822 >        Thread t = new Thread(new CheckedRunnable() {
823 >            public void realRun() {
824 >                int added = 0;
825 >                try {
826 >                    q.putFirst(new Object());
827 >                    ++added;
828 >                    q.putFirst(new Object());
829 >                    ++added;
830 >                    q.putFirst(new Object());
831 >                    ++added;
832 >                    q.putFirst(new Object());
833 >                    ++added;
834 >                    threadShouldThrow();
835 >                } catch (InterruptedException success) {
836 >                    threadAssertTrue(added >= 2);
837                  }
838 <            });
839 <        try {
840 <            t.start();
841 <            Thread.sleep(SHORT_DELAY_MS);
842 <            q.take();
843 <            t.interrupt();
844 <            t.join();
941 <        } catch (Exception e){
942 <            unexpectedException();
943 <        }
838 >            }});
839 >
840 >        t.start();
841 >        Thread.sleep(SHORT_DELAY_MS);
842 >        q.take();
843 >        t.interrupt();
844 >        t.join();
845      }
846  
847      /**
848       * timed offerFirst times out if full and elements not taken
849       */
850 <    public void testTimedOfferFirst() {
850 >    public void testTimedOfferFirst() throws InterruptedException {
851          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
852 <        Thread t = new Thread(new Runnable() {
853 <                public void run() {
854 <                    try {
855 <                        q.putFirst(new Object());
856 <                        q.putFirst(new Object());
857 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
858 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
958 <                        threadShouldThrow();
959 <                    } catch (InterruptedException success){}
960 <                }
961 <            });
852 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
853 >            public void realRun() throws InterruptedException {
854 >                q.putFirst(new Object());
855 >                q.putFirst(new Object());
856 >                threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
857 >                q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
858 >            }};
859  
860 <        try {
861 <            t.start();
862 <            Thread.sleep(SMALL_DELAY_MS);
863 <            t.interrupt();
967 <            t.join();
968 <        } catch (Exception e){
969 <            unexpectedException();
970 <        }
860 >        t.start();
861 >        Thread.sleep(SMALL_DELAY_MS);
862 >        t.interrupt();
863 >        t.join();
864      }
865  
866      /**
867       * take retrieves elements in FIFO order
868       */
869 <    public void testTakeFirst() {
870 <        try {
871 <            LinkedBlockingDeque q = populatedDeque(SIZE);
872 <            for (int i = 0; i < SIZE; ++i) {
873 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
981 <            }
982 <        } catch (InterruptedException e){
983 <            unexpectedException();
984 <        }
869 >    public void testTakeFirst() throws InterruptedException {
870 >        LinkedBlockingDeque q = populatedDeque(SIZE);
871 >        for (int i = 0; i < SIZE; ++i) {
872 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
873 >        }
874      }
875  
876      /**
877       * takeFirst blocks interruptibly when empty
878       */
879 <    public void testTakeFirstFromEmpty() {
879 >    public void testTakeFirstFromEmpty() throws InterruptedException {
880          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
881 <        Thread t = new Thread(new Runnable() {
882 <                public void run() {
883 <                    try {
884 <                        q.takeFirst();
885 <                        threadShouldThrow();
886 <                    } catch (InterruptedException success){ }
887 <                }
888 <            });
889 <        try {
1001 <            t.start();
1002 <            Thread.sleep(SHORT_DELAY_MS);
1003 <            t.interrupt();
1004 <            t.join();
1005 <        } catch (Exception e){
1006 <            unexpectedException();
1007 <        }
881 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
882 >            public void realRun() throws InterruptedException {
883 >                q.takeFirst();
884 >            }};
885 >
886 >        t.start();
887 >        Thread.sleep(SHORT_DELAY_MS);
888 >        t.interrupt();
889 >        t.join();
890      }
891  
892      /**
893       * TakeFirst removes existing elements until empty, then blocks interruptibly
894       */
895 <    public void testBlockingTakeFirst() {
896 <        Thread t = new Thread(new Runnable() {
897 <                public void run() {
898 <                    try {
899 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
900 <                        for (int i = 0; i < SIZE; ++i) {
901 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
902 <                        }
903 <                        q.takeFirst();
904 <                        threadShouldThrow();
1023 <                    } catch (InterruptedException success){
1024 <                    }
1025 <                }});
895 >    public void testBlockingTakeFirst() throws InterruptedException {
896 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
897 >            public void realRun() throws InterruptedException {
898 >                LinkedBlockingDeque q = populatedDeque(SIZE);
899 >                for (int i = 0; i < SIZE; ++i) {
900 >                    assertEquals(i, ((Integer)q.takeFirst()).intValue());
901 >                }
902 >                q.takeFirst();
903 >            }};
904 >
905          t.start();
906 <        try {
907 <           Thread.sleep(SHORT_DELAY_MS);
908 <           t.interrupt();
1030 <           t.join();
1031 <        }
1032 <        catch (InterruptedException ie) {
1033 <            unexpectedException();
1034 <        }
906 >        Thread.sleep(SHORT_DELAY_MS);
907 >        t.interrupt();
908 >        t.join();
909      }
910  
911  
912      /**
913       * timed pollFirst with zero timeout succeeds when non-empty, else times out
914       */
915 <    public void testTimedPollFirst0() {
916 <        try {
917 <            LinkedBlockingDeque q = populatedDeque(SIZE);
918 <            for (int i = 0; i < SIZE; ++i) {
919 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
920 <            }
1047 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1048 <        } catch (InterruptedException e){
1049 <            unexpectedException();
1050 <        }
915 >    public void testTimedPollFirst0() throws InterruptedException {
916 >        LinkedBlockingDeque q = populatedDeque(SIZE);
917 >        for (int i = 0; i < SIZE; ++i) {
918 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
919 >        }
920 >        assertNull(q.pollFirst(0, MILLISECONDS));
921      }
922  
923      /**
924       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
925       */
926 <    public void testTimedPollFirst() {
927 <        try {
928 <            LinkedBlockingDeque q = populatedDeque(SIZE);
929 <            for (int i = 0; i < SIZE; ++i) {
930 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
931 <            }
1062 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1063 <        } catch (InterruptedException e){
1064 <            unexpectedException();
1065 <        }
926 >    public void testTimedPollFirst() throws InterruptedException {
927 >        LinkedBlockingDeque q = populatedDeque(SIZE);
928 >        for (int i = 0; i < SIZE; ++i) {
929 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
930 >        }
931 >        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
932      }
933  
934      /**
935       * Interrupted timed pollFirst throws InterruptedException instead of
936       * returning timeout status
937       */
938 <    public void testInterruptedTimedPollFirst() {
939 <        Thread t = new Thread(new Runnable() {
940 <                public void run() {
941 <                    try {
942 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
943 <                        for (int i = 0; i < SIZE; ++i) {
944 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
945 <                        }
946 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
947 <                    } catch (InterruptedException success){
948 <                    }
949 <                }});
938 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
939 >        Thread t = new Thread(new CheckedRunnable() {
940 >            public void realRun() throws InterruptedException {
941 >                LinkedBlockingDeque q = populatedDeque(SIZE);
942 >                for (int i = 0; i < SIZE; ++i) {
943 >                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
944 >                }
945 >                try {
946 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
947 >                    shouldThrow();
948 >                } catch (InterruptedException success) {}
949 >            }});
950 >
951          t.start();
952 <        try {
953 <           Thread.sleep(SHORT_DELAY_MS);
954 <           t.interrupt();
1088 <           t.join();
1089 <        }
1090 <        catch (InterruptedException ie) {
1091 <            unexpectedException();
1092 <        }
952 >        Thread.sleep(SHORT_DELAY_MS);
953 >        t.interrupt();
954 >        t.join();
955      }
956  
957      /**
958       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
959       *  on interruption throws
960       */
961 <    public void testTimedPollFirstWithOfferFirst() {
961 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
962          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
963 <        Thread t = new Thread(new Runnable() {
964 <                public void run() {
965 <                    try {
966 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
967 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
968 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
969 <                        threadShouldThrow();
970 <                    } catch (InterruptedException success) { }
971 <                }
972 <            });
973 <        try {
974 <            t.start();
975 <            Thread.sleep(SMALL_DELAY_MS);
976 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
977 <            t.interrupt();
1116 <            t.join();
1117 <        } catch (Exception e){
1118 <            unexpectedException();
1119 <        }
963 >        Thread t = new Thread(new CheckedRunnable() {
964 >            public void realRun() throws InterruptedException {
965 >                assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
966 >                assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
967 >                try {
968 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
969 >                    shouldThrow();
970 >                } catch (InterruptedException success) {}
971 >            }});
972 >
973 >        t.start();
974 >        Thread.sleep(SMALL_DELAY_MS);
975 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
976 >        t.interrupt();
977 >        t.join();
978      }
979  
980      /**
981       * putLast(null) throws NPE
982       */
983 <     public void testPutLastNull() {
984 <        try {
983 >     public void testPutLastNull() throws InterruptedException {
984 >        try {
985              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
986              q.putLast(null);
987              shouldThrow();
988 <        }
1131 <        catch (NullPointerException success){
1132 <        }
1133 <        catch (InterruptedException ie) {
1134 <            unexpectedException();
1135 <        }
988 >        } catch (NullPointerException success) {}
989       }
990  
991      /**
992       * all elements successfully putLast are contained
993       */
994 <     public void testPutLast() {
995 <         try {
996 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
997 <             for (int i = 0; i < SIZE; ++i) {
998 <                 Integer I = new Integer(i);
999 <                 q.putLast(I);
1147 <                 assertTrue(q.contains(I));
1148 <             }
1149 <             assertEquals(0, q.remainingCapacity());
994 >     public void testPutLast() throws InterruptedException {
995 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
996 >         for (int i = 0; i < SIZE; ++i) {
997 >             Integer I = new Integer(i);
998 >             q.putLast(I);
999 >             assertTrue(q.contains(I));
1000           }
1001 <        catch (InterruptedException ie) {
1152 <            unexpectedException();
1153 <        }
1001 >         assertEquals(0, q.remainingCapacity());
1002      }
1003  
1004      /**
1005       * putLast blocks interruptibly if full
1006       */
1007 <    public void testBlockingPutLast() {
1008 <        Thread t = new Thread(new Runnable() {
1009 <                public void run() {
1010 <                    int added = 0;
1011 <                    try {
1012 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1013 <                        for (int i = 0; i < SIZE; ++i) {
1014 <                            q.putLast(new Integer(i));
1015 <                            ++added;
1168 <                        }
1169 <                        q.putLast(new Integer(SIZE));
1170 <                        threadShouldThrow();
1171 <                    } catch (InterruptedException ie){
1172 <                        threadAssertEquals(added, SIZE);
1007 >    public void testBlockingPutLast() throws InterruptedException {
1008 >        Thread t = new Thread(new CheckedRunnable() {
1009 >            public void realRun() {
1010 >                int added = 0;
1011 >                try {
1012 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1013 >                    for (int i = 0; i < SIZE; ++i) {
1014 >                        q.putLast(new Integer(i));
1015 >                        ++added;
1016                      }
1017 <                }});
1017 >                    q.putLast(new Integer(SIZE));
1018 >                    threadShouldThrow();
1019 >                } catch (InterruptedException success) {
1020 >                    threadAssertEquals(added, SIZE);
1021 >                }
1022 >            }});
1023 >
1024          t.start();
1025 <        try {
1026 <           Thread.sleep(SHORT_DELAY_MS);
1027 <           t.interrupt();
1179 <           t.join();
1180 <        }
1181 <        catch (InterruptedException ie) {
1182 <            unexpectedException();
1183 <        }
1025 >        Thread.sleep(SHORT_DELAY_MS);
1026 >        t.interrupt();
1027 >        t.join();
1028      }
1029  
1030      /**
1031       * putLast blocks waiting for take when full
1032       */
1033 <    public void testPutLastWithTake() {
1033 >    public void testPutLastWithTake() throws InterruptedException {
1034          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1035 <        Thread t = new Thread(new Runnable() {
1036 <                public void run() {
1037 <                    int added = 0;
1038 <                    try {
1039 <                        q.putLast(new Object());
1040 <                        ++added;
1041 <                        q.putLast(new Object());
1042 <                        ++added;
1043 <                        q.putLast(new Object());
1044 <                        ++added;
1045 <                        q.putLast(new Object());
1046 <                        ++added;
1047 <                        threadShouldThrow();
1048 <                    } catch (InterruptedException e){
1049 <                        threadAssertTrue(added >= 2);
1206 <                    }
1035 >        Thread t = new Thread(new CheckedRunnable() {
1036 >            public void realRun() {
1037 >                int added = 0;
1038 >                try {
1039 >                    q.putLast(new Object());
1040 >                    ++added;
1041 >                    q.putLast(new Object());
1042 >                    ++added;
1043 >                    q.putLast(new Object());
1044 >                    ++added;
1045 >                    q.putLast(new Object());
1046 >                    ++added;
1047 >                    threadShouldThrow();
1048 >                } catch (InterruptedException success) {
1049 >                    threadAssertTrue(added >= 2);
1050                  }
1051 <            });
1052 <        try {
1053 <            t.start();
1054 <            Thread.sleep(SHORT_DELAY_MS);
1055 <            q.take();
1056 <            t.interrupt();
1057 <            t.join();
1215 <        } catch (Exception e){
1216 <            unexpectedException();
1217 <        }
1051 >            }});
1052 >
1053 >        t.start();
1054 >        Thread.sleep(SHORT_DELAY_MS);
1055 >        q.take();
1056 >        t.interrupt();
1057 >        t.join();
1058      }
1059  
1060      /**
1061       * timed offerLast times out if full and elements not taken
1062       */
1063 <    public void testTimedOfferLast() {
1063 >    public void testTimedOfferLast() throws InterruptedException {
1064          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1065 <        Thread t = new Thread(new Runnable() {
1066 <                public void run() {
1067 <                    try {
1068 <                        q.putLast(new Object());
1069 <                        q.putLast(new Object());
1070 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1071 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1232 <                        threadShouldThrow();
1233 <                    } catch (InterruptedException success){}
1234 <                }
1235 <            });
1065 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1066 >            public void realRun() throws InterruptedException {
1067 >                q.putLast(new Object());
1068 >                q.putLast(new Object());
1069 >                threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1070 >                q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1071 >            }};
1072  
1073 <        try {
1074 <            t.start();
1075 <            Thread.sleep(SMALL_DELAY_MS);
1076 <            t.interrupt();
1241 <            t.join();
1242 <        } catch (Exception e){
1243 <            unexpectedException();
1244 <        }
1073 >        t.start();
1074 >        Thread.sleep(SMALL_DELAY_MS);
1075 >        t.interrupt();
1076 >        t.join();
1077      }
1078  
1079      /**
1080       * takeLast retrieves elements in FIFO order
1081       */
1082 <    public void testTakeLast() {
1083 <        try {
1084 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1085 <            for (int i = 0; i < SIZE; ++i) {
1086 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1255 <            }
1256 <        } catch (InterruptedException e){
1257 <            unexpectedException();
1258 <        }
1082 >    public void testTakeLast() throws InterruptedException {
1083 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1084 >        for (int i = 0; i < SIZE; ++i) {
1085 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1086 >        }
1087      }
1088  
1089      /**
1090       * takeLast blocks interruptibly when empty
1091       */
1092 <    public void testTakeLastFromEmpty() {
1092 >    public void testTakeLastFromEmpty() throws InterruptedException {
1093          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1094 <        Thread t = new Thread(new Runnable() {
1095 <                public void run() {
1096 <                    try {
1097 <                        q.takeLast();
1098 <                        threadShouldThrow();
1099 <                    } catch (InterruptedException success){ }
1100 <                }
1101 <            });
1102 <        try {
1275 <            t.start();
1276 <            Thread.sleep(SHORT_DELAY_MS);
1277 <            t.interrupt();
1278 <            t.join();
1279 <        } catch (Exception e){
1280 <            unexpectedException();
1281 <        }
1094 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1095 >            public void realRun() throws InterruptedException {
1096 >                q.takeLast();
1097 >            }};
1098 >
1099 >        t.start();
1100 >        Thread.sleep(SHORT_DELAY_MS);
1101 >        t.interrupt();
1102 >        t.join();
1103      }
1104  
1105      /**
1106       * TakeLast removes existing elements until empty, then blocks interruptibly
1107       */
1108 <    public void testBlockingTakeLast() {
1109 <        Thread t = new Thread(new Runnable() {
1110 <                public void run() {
1111 <                    try {
1112 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1113 <                        for (int i = 0; i < SIZE; ++i) {
1114 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1115 <                        }
1116 <                        q.takeLast();
1117 <                        threadShouldThrow();
1297 <                    } catch (InterruptedException success){
1298 <                    }
1299 <                }});
1108 >    public void testBlockingTakeLast() throws InterruptedException {
1109 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1110 >            public void realRun() throws InterruptedException {
1111 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1112 >                for (int i = 0; i < SIZE; ++i) {
1113 >                    assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1114 >                }
1115 >                q.takeLast();
1116 >            }};
1117 >
1118          t.start();
1119 <        try {
1120 <           Thread.sleep(SHORT_DELAY_MS);
1121 <           t.interrupt();
1304 <           t.join();
1305 <        }
1306 <        catch (InterruptedException ie) {
1307 <            unexpectedException();
1308 <        }
1119 >        Thread.sleep(SHORT_DELAY_MS);
1120 >        t.interrupt();
1121 >        t.join();
1122      }
1123  
1124  
1125      /**
1126       * timed pollLast with zero timeout succeeds when non-empty, else times out
1127       */
1128 <    public void testTimedPollLast0() {
1129 <        try {
1130 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1131 <            for (int i = 0; i < SIZE; ++i) {
1132 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1133 <            }
1321 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1322 <        } catch (InterruptedException e){
1323 <            unexpectedException();
1324 <        }
1128 >    public void testTimedPollLast0() throws InterruptedException {
1129 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1130 >        for (int i = 0; i < SIZE; ++i) {
1131 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1132 >        }
1133 >        assertNull(q.pollLast(0, MILLISECONDS));
1134      }
1135  
1136      /**
1137       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1138       */
1139 <    public void testTimedPollLast() {
1140 <        try {
1141 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1142 <            for (int i = 0; i < SIZE; ++i) {
1143 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1144 <            }
1336 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1337 <        } catch (InterruptedException e){
1338 <            unexpectedException();
1339 <        }
1139 >    public void testTimedPollLast() throws InterruptedException {
1140 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1141 >        for (int i = 0; i < SIZE; ++i) {
1142 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1143 >        }
1144 >        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1145      }
1146  
1147      /**
1148       * Interrupted timed pollLast throws InterruptedException instead of
1149       * returning timeout status
1150       */
1151 <    public void testInterruptedTimedPollLast() {
1152 <        Thread t = new Thread(new Runnable() {
1153 <                public void run() {
1154 <                    try {
1155 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1156 <                        for (int i = 0; i < SIZE; ++i) {
1157 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1158 <                        }
1159 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1160 <                    } catch (InterruptedException success){
1161 <                    }
1162 <                }});
1151 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1152 >        Thread t = new Thread(new CheckedRunnable() {
1153 >            public void realRun() throws InterruptedException {
1154 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1155 >                for (int i = 0; i < SIZE; ++i) {
1156 >                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1157 >                }
1158 >                try {
1159 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1160 >                    shouldThrow();
1161 >                } catch (InterruptedException success) {}
1162 >            }});
1163 >
1164          t.start();
1165 <        try {
1166 <           Thread.sleep(SHORT_DELAY_MS);
1167 <           t.interrupt();
1362 <           t.join();
1363 <        }
1364 <        catch (InterruptedException ie) {
1365 <            unexpectedException();
1366 <        }
1165 >        Thread.sleep(SHORT_DELAY_MS);
1166 >        t.interrupt();
1167 >        t.join();
1168      }
1169  
1170      /**
1171       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1172       *  on interruption throws
1173       */
1174 <    public void testTimedPollWithOfferLast() {
1174 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1175          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1176 <        Thread t = new Thread(new Runnable() {
1177 <                public void run() {
1178 <                    try {
1179 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1180 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1181 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1182 <                        threadShouldThrow();
1183 <                    } catch (InterruptedException success) { }
1184 <                }
1185 <            });
1186 <        try {
1187 <            t.start();
1188 <            Thread.sleep(SMALL_DELAY_MS);
1189 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1190 <            t.interrupt();
1390 <            t.join();
1391 <        } catch (Exception e){
1392 <            unexpectedException();
1393 <        }
1176 >        Thread t = new Thread(new CheckedRunnable() {
1177 >            public void realRun() throws InterruptedException {
1178 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1179 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1180 >                try {
1181 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1182 >                    shouldThrow();
1183 >                } catch (InterruptedException success) {}
1184 >            }});
1185 >
1186 >        t.start();
1187 >        Thread.sleep(SMALL_DELAY_MS);
1188 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1189 >        t.interrupt();
1190 >        t.join();
1191      }
1192  
1193  
# Line 1406 | Line 1203 | public class LinkedBlockingDequeTest ext
1203          try {
1204              q.element();
1205              shouldThrow();
1206 <        }
1410 <        catch (NoSuchElementException success) {}
1206 >        } catch (NoSuchElementException success) {}
1207      }
1208  
1209      /**
# Line 1505 | Line 1301 | public class LinkedBlockingDequeTest ext
1301      /**
1302       * toArray contains all elements
1303       */
1304 <    public void testToArray() {
1304 >    public void testToArray() throws InterruptedException{
1305          LinkedBlockingDeque q = populatedDeque(SIZE);
1306 <        Object[] o = q.toArray();
1307 <        try {
1308 <        for (int i = 0; i < o.length; i++)
1513 <            assertEquals(o[i], q.take());
1514 <        } catch (InterruptedException e){
1515 <            unexpectedException();
1516 <        }
1306 >        Object[] o = q.toArray();
1307 >        for (int i = 0; i < o.length; i++)
1308 >            assertEquals(o[i], q.take());
1309      }
1310  
1311      /**
1312       * toArray(a) contains all elements
1313       */
1314 <    public void testToArray2() {
1314 >    public void testToArray2() throws InterruptedException {
1315          LinkedBlockingDeque q = populatedDeque(SIZE);
1316 <        Integer[] ints = new Integer[SIZE];
1317 <        ints = (Integer[])q.toArray(ints);
1318 <        try {
1319 <            for (int i = 0; i < ints.length; i++)
1528 <                assertEquals(ints[i], q.take());
1529 <        } catch (InterruptedException e){
1530 <            unexpectedException();
1531 <        }
1316 >        Integer[] ints = new Integer[SIZE];
1317 >        ints = (Integer[])q.toArray(ints);
1318 >        for (int i = 0; i < ints.length; i++)
1319 >            assertEquals(ints[i], q.take());
1320      }
1321  
1322      /**
1323       * toArray(null) throws NPE
1324       */
1325      public void testToArray_BadArg() {
1326 <        try {
1326 >        try {
1327              LinkedBlockingDeque q = populatedDeque(SIZE);
1328 <            Object o[] = q.toArray(null);
1329 <            shouldThrow();
1330 <        } catch (NullPointerException success){}
1328 >            Object o[] = q.toArray(null);
1329 >            shouldThrow();
1330 >        } catch (NullPointerException success) {}
1331      }
1332  
1333      /**
1334       * toArray with incompatible array type throws CCE
1335       */
1336      public void testToArray1_BadArg() {
1337 <        try {
1337 >        try {
1338              LinkedBlockingDeque q = populatedDeque(SIZE);
1339 <            Object o[] = q.toArray(new String[10] );
1340 <            shouldThrow();
1341 <        } catch (ArrayStoreException  success){}
1339 >            Object o[] = q.toArray(new String[10] );
1340 >            shouldThrow();
1341 >        } catch (ArrayStoreException success) {}
1342      }
1343  
1344  
1345      /**
1346       * iterator iterates through all elements
1347       */
1348 <    public void testIterator() {
1348 >    public void testIterator() throws InterruptedException {
1349          LinkedBlockingDeque q = populatedDeque(SIZE);
1350 <        Iterator it = q.iterator();
1351 <        try {
1352 <            while (it.hasNext()){
1353 <                assertEquals(it.next(), q.take());
1566 <            }
1567 <        } catch (InterruptedException e){
1568 <            unexpectedException();
1569 <        }
1350 >        Iterator it = q.iterator();
1351 >        while (it.hasNext()) {
1352 >            assertEquals(it.next(), q.take());
1353 >        }
1354      }
1355  
1356      /**
# Line 1614 | Line 1398 | public class LinkedBlockingDequeTest ext
1398          q.add(one);
1399          q.add(two);
1400          q.add(three);
1401 <        try {
1402 <            for (Iterator it = q.iterator(); it.hasNext();) {
1403 <                q.remove();
1620 <                it.next();
1621 <            }
1622 <        }
1623 <        catch (ConcurrentModificationException e) {
1624 <            unexpectedException();
1401 >        for (Iterator it = q.iterator(); it.hasNext();) {
1402 >            q.remove();
1403 >            it.next();
1404          }
1405          assertEquals(0, q.size());
1406      }
# Line 1633 | Line 1412 | public class LinkedBlockingDequeTest ext
1412      public void testDescendingIterator() {
1413          LinkedBlockingDeque q = populatedDeque(SIZE);
1414          int i = 0;
1415 <        Iterator it = q.descendingIterator();
1415 >        Iterator it = q.descendingIterator();
1416          while (it.hasNext()) {
1417              assertTrue(q.contains(it.next()));
1418              ++i;
# Line 1642 | Line 1421 | public class LinkedBlockingDequeTest ext
1421          assertFalse(it.hasNext());
1422          try {
1423              it.next();
1424 <        } catch (NoSuchElementException success) {
1425 <        }
1424 >            shouldThrow();
1425 >        } catch (NoSuchElementException success) {}
1426      }
1427  
1428      /**
# Line 1711 | Line 1490 | public class LinkedBlockingDequeTest ext
1490          q.add(one);
1491          q.add(two);
1492          ExecutorService executor = Executors.newFixedThreadPool(2);
1493 <        executor.execute(new Runnable() {
1494 <            public void run() {
1493 >        executor.execute(new CheckedRunnable() {
1494 >            public void realRun() throws InterruptedException {
1495                  threadAssertFalse(q.offer(three));
1496 <                try {
1497 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1498 <                    threadAssertEquals(0, q.remainingCapacity());
1499 <                }
1500 <                catch (InterruptedException e) {
1501 <                    threadUnexpectedException();
1502 <                }
1503 <            }
1504 <        });
1726 <
1727 <        executor.execute(new Runnable() {
1728 <            public void run() {
1729 <                try {
1730 <                    Thread.sleep(SMALL_DELAY_MS);
1731 <                    threadAssertEquals(one, q.take());
1732 <                }
1733 <                catch (InterruptedException e) {
1734 <                    threadUnexpectedException();
1735 <                }
1736 <            }
1737 <        });
1496 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1497 >                threadAssertEquals(0, q.remainingCapacity());
1498 >            }});
1499 >
1500 >        executor.execute(new CheckedRunnable() {
1501 >            public void realRun() throws InterruptedException {
1502 >                Thread.sleep(SMALL_DELAY_MS);
1503 >                threadAssertEquals(one, q.take());
1504 >            }});
1505  
1506          joinPool(executor);
1507      }
# Line 1745 | Line 1512 | public class LinkedBlockingDequeTest ext
1512      public void testPollInExecutor() {
1513          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1514          ExecutorService executor = Executors.newFixedThreadPool(2);
1515 <        executor.execute(new Runnable() {
1516 <            public void run() {
1515 >        executor.execute(new CheckedRunnable() {
1516 >            public void realRun() throws InterruptedException {
1517                  threadAssertNull(q.poll());
1518 <                try {
1519 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1520 <                    threadAssertTrue(q.isEmpty());
1521 <                }
1522 <                catch (InterruptedException e) {
1523 <                    threadUnexpectedException();
1524 <                }
1525 <            }
1526 <        });
1760 <
1761 <        executor.execute(new Runnable() {
1762 <            public void run() {
1763 <                try {
1764 <                    Thread.sleep(SMALL_DELAY_MS);
1765 <                    q.put(one);
1766 <                }
1767 <                catch (InterruptedException e) {
1768 <                    threadUnexpectedException();
1769 <                }
1770 <            }
1771 <        });
1518 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1519 >                threadAssertTrue(q.isEmpty());
1520 >            }});
1521 >
1522 >        executor.execute(new CheckedRunnable() {
1523 >            public void realRun() throws InterruptedException {
1524 >                Thread.sleep(SMALL_DELAY_MS);
1525 >                q.put(one);
1526 >            }});
1527  
1528          joinPool(executor);
1529      }
# Line 1776 | Line 1531 | public class LinkedBlockingDequeTest ext
1531      /**
1532       * A deserialized serialized deque has same elements in same order
1533       */
1534 <    public void testSerialization() {
1534 >    public void testSerialization() throws Exception {
1535          LinkedBlockingDeque q = populatedDeque(SIZE);
1536  
1537 <        try {
1538 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1539 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1540 <            out.writeObject(q);
1541 <            out.close();
1542 <
1543 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1544 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1545 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1546 <            assertEquals(q.size(), r.size());
1547 <            while (!q.isEmpty())
1793 <                assertEquals(q.remove(), r.remove());
1794 <        } catch (Exception e){
1795 <            unexpectedException();
1796 <        }
1537 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1538 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1539 >        out.writeObject(q);
1540 >        out.close();
1541 >
1542 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1543 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1544 >        LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1545 >        assertEquals(q.size(), r.size());
1546 >        while (!q.isEmpty())
1547 >            assertEquals(q.remove(), r.remove());
1548      }
1549  
1550      /**
# Line 1804 | Line 1555 | public class LinkedBlockingDequeTest ext
1555          try {
1556              q.drainTo(null);
1557              shouldThrow();
1558 <        } catch (NullPointerException success) {
1808 <        }
1558 >        } catch (NullPointerException success) {}
1559      }
1560  
1561      /**
# Line 1816 | Line 1566 | public class LinkedBlockingDequeTest ext
1566          try {
1567              q.drainTo(q);
1568              shouldThrow();
1569 <        } catch (IllegalArgumentException success) {
1820 <        }
1569 >        } catch (IllegalArgumentException success) {}
1570      }
1571  
1572      /**
# Line 1847 | Line 1596 | public class LinkedBlockingDequeTest ext
1596      /**
1597       * drainTo empties full deque, unblocking a waiting put.
1598       */
1599 <    public void testDrainToWithActivePut() {
1599 >    public void testDrainToWithActivePut() throws InterruptedException {
1600          final LinkedBlockingDeque q = populatedDeque(SIZE);
1601 <        Thread t = new Thread(new Runnable() {
1602 <                public void run() {
1603 <                    try {
1604 <                        q.put(new Integer(SIZE+1));
1605 <                    } catch (InterruptedException ie){
1606 <                        threadUnexpectedException();
1607 <                    }
1608 <                }
1609 <            });
1610 <        try {
1611 <            t.start();
1612 <            ArrayList l = new ArrayList();
1613 <            q.drainTo(l);
1865 <            assertTrue(l.size() >= SIZE);
1866 <            for (int i = 0; i < SIZE; ++i)
1867 <                assertEquals(l.get(i), new Integer(i));
1868 <            t.join();
1869 <            assertTrue(q.size() + l.size() >= SIZE);
1870 <        } catch (Exception e){
1871 <            unexpectedException();
1872 <        }
1601 >        Thread t = new Thread(new CheckedRunnable() {
1602 >            public void realRun() throws InterruptedException {
1603 >                q.put(new Integer(SIZE+1));
1604 >            }});
1605 >
1606 >        t.start();
1607 >        ArrayList l = new ArrayList();
1608 >        q.drainTo(l);
1609 >        assertTrue(l.size() >= SIZE);
1610 >        for (int i = 0; i < SIZE; ++i)
1611 >            assertEquals(l.get(i), new Integer(i));
1612 >        t.join();
1613 >        assertTrue(q.size() + l.size() >= SIZE);
1614      }
1615  
1616      /**
# Line 1880 | Line 1621 | public class LinkedBlockingDequeTest ext
1621          try {
1622              q.drainTo(null, 0);
1623              shouldThrow();
1624 <        } catch (NullPointerException success) {
1884 <        }
1624 >        } catch (NullPointerException success) {}
1625      }
1626  
1627      /**
# Line 1892 | Line 1632 | public class LinkedBlockingDequeTest ext
1632          try {
1633              q.drainTo(q, 0);
1634              shouldThrow();
1635 <        } catch (IllegalArgumentException success) {
1896 <        }
1635 >        } catch (IllegalArgumentException success) {}
1636      }
1637  
1638      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines