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.15 by jsr166, Sat Nov 21 21:12:55 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 >        assertNull(q.peekFirst());
173      }
174  
175      /**
# Line 184 | Line 184 | public class LinkedBlockingDequeTest ext
184          try {
185              q.getLast();
186              shouldThrow();
187 <        }
188 <        catch (NoSuchElementException success) {}
189 <        assertNull(q.peekLast());
187 >        } catch (NoSuchElementException success) {}
188 >        assertNull(q.peekLast());
189      }
190  
191      /**
# Line 200 | Line 199 | public class LinkedBlockingDequeTest ext
199          try {
200              q.removeFirst();
201              shouldThrow();
202 <        } catch (NoSuchElementException success){
203 <        }
202 >        } catch (NoSuchElementException success) {}
203 >        assertNull(q.peekFirst());
204 >    }
205 >
206 >    /**
207 >     *  removeLast removes last element, or throws NSEE if empty
208 >     */
209 >    public void testRemoveLast() {
210 >        LinkedBlockingDeque q = populatedDeque(SIZE);
211 >        for (int i = SIZE - 1; i >= 0; --i) {
212 >            assertEquals(i, ((Integer)q.removeLast()).intValue());
213 >        }
214 >        try {
215 >            q.removeLast();
216 >            shouldThrow();
217 >        } catch (NoSuchElementException success) {}
218 >        assertNull(q.peekLast());
219      }
220  
221      /**
# Line 215 | Line 229 | public class LinkedBlockingDequeTest ext
229          try {
230              q.remove();
231              shouldThrow();
232 <        } catch (NoSuchElementException success){
219 <        }
232 >        } catch (NoSuchElementException success) {}
233      }
234  
235      /**
# Line 255 | Line 268 | public class LinkedBlockingDequeTest ext
268      public void testAddFirst() {
269          LinkedBlockingDeque q = populatedDeque(3);
270          q.pollLast();
271 <        q.addFirst(four);
272 <        assertEquals(four,q.peekFirst());
271 >        q.addFirst(four);
272 >        assertEquals(four,q.peekFirst());
273      }
274  
275      /**
# Line 265 | Line 278 | public class LinkedBlockingDequeTest ext
278      public void testAddLast() {
279          LinkedBlockingDeque q = populatedDeque(3);
280          q.pollLast();
281 <        q.addLast(four);
282 <        assertEquals(four,q.peekLast());
281 >        q.addLast(four);
282 >        assertEquals(four,q.peekLast());
283      }
284  
285  
# Line 280 | Line 293 | public class LinkedBlockingDequeTest ext
293      }
294  
295      /**
296 <     * Constructor throws IAE if  capacity argument nonpositive
296 >     * Constructor throws IAE if capacity argument nonpositive
297       */
298      public void testConstructor2() {
299          try {
300              LinkedBlockingDeque q = new LinkedBlockingDeque(0);
301              shouldThrow();
302 <        }
290 <        catch (IllegalArgumentException success) {}
302 >        } catch (IllegalArgumentException success) {}
303      }
304  
305      /**
# Line 297 | Line 309 | public class LinkedBlockingDequeTest ext
309          try {
310              LinkedBlockingDeque q = new LinkedBlockingDeque(null);
311              shouldThrow();
312 <        }
301 <        catch (NullPointerException success) {}
312 >        } catch (NullPointerException success) {}
313      }
314  
315      /**
# Line 309 | Line 320 | public class LinkedBlockingDequeTest ext
320              Integer[] ints = new Integer[SIZE];
321              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
322              shouldThrow();
323 <        }
313 <        catch (NullPointerException success) {}
323 >        } catch (NullPointerException success) {}
324      }
325  
326      /**
# Line 323 | Line 333 | public class LinkedBlockingDequeTest ext
333                  ints[i] = new Integer(i);
334              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
335              shouldThrow();
336 <        }
327 <        catch (NullPointerException success) {}
336 >        } catch (NullPointerException success) {}
337      }
338  
339      /**
340       * Deque contains all elements of collection used to initialize
341       */
342      public void testConstructor6() {
343 <        try {
344 <            Integer[] ints = new Integer[SIZE];
345 <            for (int i = 0; i < SIZE; ++i)
346 <                ints[i] = new Integer(i);
347 <            LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
348 <            for (int i = 0; i < SIZE; ++i)
340 <                assertEquals(ints[i], q.poll());
341 <        }
342 <        finally {}
343 >        Integer[] ints = new Integer[SIZE];
344 >        for (int i = 0; i < SIZE; ++i)
345 >            ints[i] = new Integer(i);
346 >        LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
347 >        for (int i = 0; i < SIZE; ++i)
348 >            assertEquals(ints[i], q.poll());
349      }
350  
351      /**
# Line 378 | Line 384 | public class LinkedBlockingDequeTest ext
384       * offer(null) throws NPE
385       */
386      public void testOfferNull() {
387 <        try {
387 >        try {
388              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
389              q.offer(null);
390              shouldThrow();
391 <        } catch (NullPointerException success) { }
391 >        } catch (NullPointerException success) {}
392      }
393  
394      /**
395       * add(null) throws NPE
396       */
397      public void testAddNull() {
398 <        try {
398 >        try {
399              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
400              q.add(null);
401              shouldThrow();
402 <        } catch (NullPointerException success) { }
402 >        } catch (NullPointerException success) {}
403      }
404  
405      /**
406       * push(null) throws NPE
407       */
408      public void testPushNull() {
409 <        try {
409 >        try {
410              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
411              q.push(null);
412              shouldThrow();
413 <        } catch (NullPointerException success) { }
413 >        } catch (NullPointerException success) {}
414      }
415  
416      /**
417       * push succeeds if not full; throws ISE if full
418       */
419      public void testPush() {
420 <        try {
420 >        try {
421              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
422              for (int i = 0; i < SIZE; ++i) {
423                  Integer I = new Integer(i);
# Line 420 | Line 426 | public class LinkedBlockingDequeTest ext
426              }
427              assertEquals(0, q.remainingCapacity());
428              q.push(new Integer(SIZE));
429 <        } catch (IllegalStateException success){
430 <        }
429 >            shouldThrow();
430 >        } catch (IllegalStateException success) {}
431      }
432  
433      /**
# Line 430 | Line 436 | public class LinkedBlockingDequeTest ext
436      public void testPushWithPeek() {
437          LinkedBlockingDeque q = populatedDeque(3);
438          q.pollLast();
439 <        q.push(four);
440 <        assertEquals(four,q.peekFirst());
439 >        q.push(four);
440 >        assertEquals(four,q.peekFirst());
441      }
442  
443  
# Line 446 | Line 452 | public class LinkedBlockingDequeTest ext
452          try {
453              q.pop();
454              shouldThrow();
455 <        } catch (NoSuchElementException success){
450 <        }
455 >        } catch (NoSuchElementException success) {}
456      }
457  
458  
# Line 464 | Line 469 | public class LinkedBlockingDequeTest ext
469       * add succeeds if not full; throws ISE if full
470       */
471      public void testAdd() {
472 <        try {
472 >        try {
473              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
474              for (int i = 0; i < SIZE; ++i) {
475                  assertTrue(q.add(new Integer(i)));
476              }
477              assertEquals(0, q.remainingCapacity());
478              q.add(new Integer(SIZE));
479 <        } catch (IllegalStateException success){
480 <        }
479 >            shouldThrow();
480 >        } catch (IllegalStateException success) {}
481      }
482  
483      /**
# Line 483 | Line 488 | public class LinkedBlockingDequeTest ext
488              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
489              q.addAll(null);
490              shouldThrow();
491 <        }
487 <        catch (NullPointerException success) {}
491 >        } catch (NullPointerException success) {}
492      }
493  
494      /**
# Line 495 | Line 499 | public class LinkedBlockingDequeTest ext
499              LinkedBlockingDeque q = populatedDeque(SIZE);
500              q.addAll(q);
501              shouldThrow();
502 <        }
499 <        catch (IllegalArgumentException success) {}
502 >        } catch (IllegalArgumentException success) {}
503      }
504  
505      /**
# Line 508 | Line 511 | public class LinkedBlockingDequeTest ext
511              Integer[] ints = new Integer[SIZE];
512              q.addAll(Arrays.asList(ints));
513              shouldThrow();
514 <        }
512 <        catch (NullPointerException success) {}
514 >        } catch (NullPointerException success) {}
515      }
516      /**
517       * addAll of a collection with any null elements throws NPE after
# Line 523 | Line 525 | public class LinkedBlockingDequeTest ext
525                  ints[i] = new Integer(i);
526              q.addAll(Arrays.asList(ints));
527              shouldThrow();
528 <        }
527 <        catch (NullPointerException success) {}
528 >        } catch (NullPointerException success) {}
529      }
530      /**
531       * addAll throws ISE if not enough room
# Line 537 | Line 538 | public class LinkedBlockingDequeTest ext
538                  ints[i] = new Integer(i);
539              q.addAll(Arrays.asList(ints));
540              shouldThrow();
541 <        }
541 <        catch (IllegalStateException success) {}
541 >        } catch (IllegalStateException success) {}
542      }
543      /**
544       * Deque contains all elements, in traversal order, of successful addAll
545       */
546      public void testAddAll5() {
547 <        try {
548 <            Integer[] empty = new Integer[0];
549 <            Integer[] ints = new Integer[SIZE];
550 <            for (int i = 0; i < SIZE; ++i)
551 <                ints[i] = new Integer(i);
552 <            LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
553 <            assertFalse(q.addAll(Arrays.asList(empty)));
554 <            assertTrue(q.addAll(Arrays.asList(ints)));
555 <            for (int i = 0; i < SIZE; ++i)
556 <                assertEquals(ints[i], q.poll());
557 <        }
558 <        finally {}
547 >        Integer[] empty = new Integer[0];
548 >        Integer[] ints = new Integer[SIZE];
549 >        for (int i = 0; i < SIZE; ++i)
550 >            ints[i] = new Integer(i);
551 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
552 >        assertFalse(q.addAll(Arrays.asList(empty)));
553 >        assertTrue(q.addAll(Arrays.asList(ints)));
554 >        for (int i = 0; i < SIZE; ++i)
555 >            assertEquals(ints[i], q.poll());
556      }
557  
558  
559      /**
560       * put(null) throws NPE
561       */
562 <     public void testPutNull() {
563 <        try {
562 >    public void testPutNull() throws InterruptedException {
563 >        try {
564              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
565              q.put(null);
566              shouldThrow();
567 <        }
568 <        catch (NullPointerException success){
572 <        }
573 <        catch (InterruptedException ie) {
574 <            unexpectedException();
575 <        }
576 <     }
567 >        } catch (NullPointerException success) {}
568 >    }
569  
570      /**
571       * all elements successfully put are contained
572       */
573 <     public void testPut() {
574 <         try {
575 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
576 <             for (int i = 0; i < SIZE; ++i) {
577 <                 Integer I = new Integer(i);
578 <                 q.put(I);
587 <                 assertTrue(q.contains(I));
588 <             }
589 <             assertEquals(0, q.remainingCapacity());
590 <         }
591 <        catch (InterruptedException ie) {
592 <            unexpectedException();
573 >    public void testPut() throws InterruptedException {
574 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
575 >        for (int i = 0; i < SIZE; ++i) {
576 >            Integer I = new Integer(i);
577 >            q.put(I);
578 >            assertTrue(q.contains(I));
579          }
580 +        assertEquals(0, q.remainingCapacity());
581      }
582  
583      /**
584       * put blocks interruptibly if full
585       */
586 <    public void testBlockingPut() {
587 <        Thread t = new Thread(new Runnable() {
588 <                public void run() {
589 <                    int added = 0;
590 <                    try {
591 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
592 <                        for (int i = 0; i < SIZE; ++i) {
593 <                            q.put(new Integer(i));
594 <                            ++added;
608 <                        }
609 <                        q.put(new Integer(SIZE));
610 <                        threadShouldThrow();
611 <                    } catch (InterruptedException ie){
612 <                        threadAssertEquals(added, SIZE);
586 >    public void testBlockingPut() throws InterruptedException {
587 >        Thread t = new Thread(new CheckedRunnable() {
588 >            public void realRun() {
589 >                int added = 0;
590 >                try {
591 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
592 >                    for (int i = 0; i < SIZE; ++i) {
593 >                        q.put(new Integer(i));
594 >                        ++added;
595                      }
596 <                }});
596 >                    q.put(new Integer(SIZE));
597 >                    threadShouldThrow();
598 >                } catch (InterruptedException success) {
599 >                    threadAssertEquals(added, SIZE);
600 >                }
601 >            }});
602 >
603          t.start();
604 <        try {
605 <           Thread.sleep(SHORT_DELAY_MS);
606 <           t.interrupt();
619 <           t.join();
620 <        }
621 <        catch (InterruptedException ie) {
622 <            unexpectedException();
623 <        }
604 >        Thread.sleep(SHORT_DELAY_MS);
605 >        t.interrupt();
606 >        t.join();
607      }
608  
609      /**
610       * put blocks waiting for take when full
611       */
612 <    public void testPutWithTake() {
612 >    public void testPutWithTake() throws InterruptedException {
613          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
614 <        Thread t = new Thread(new Runnable() {
615 <                public void run() {
616 <                    int added = 0;
617 <                    try {
618 <                        q.put(new Object());
619 <                        ++added;
620 <                        q.put(new Object());
621 <                        ++added;
622 <                        q.put(new Object());
623 <                        ++added;
624 <                        q.put(new Object());
625 <                        ++added;
626 <                        threadShouldThrow();
627 <                    } catch (InterruptedException e){
628 <                        threadAssertTrue(added >= 2);
646 <                    }
614 >        Thread t = new Thread(new CheckedRunnable() {
615 >            public void realRun() {
616 >                int added = 0;
617 >                try {
618 >                    q.put(new Object());
619 >                    ++added;
620 >                    q.put(new Object());
621 >                    ++added;
622 >                    q.put(new Object());
623 >                    ++added;
624 >                    q.put(new Object());
625 >                    ++added;
626 >                    threadShouldThrow();
627 >                } catch (InterruptedException success) {
628 >                    threadAssertTrue(added >= 2);
629                  }
630 <            });
631 <        try {
632 <            t.start();
633 <            Thread.sleep(SHORT_DELAY_MS);
634 <            q.take();
635 <            t.interrupt();
636 <            t.join();
655 <        } catch (Exception e){
656 <            unexpectedException();
657 <        }
630 >            }});
631 >
632 >        t.start();
633 >        Thread.sleep(SHORT_DELAY_MS);
634 >        q.take();
635 >        t.interrupt();
636 >        t.join();
637      }
638  
639      /**
640       * timed offer times out if full and elements not taken
641       */
642 <    public void testTimedOffer() {
642 >    public void testTimedOffer() throws InterruptedException {
643          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
644 <        Thread t = new Thread(new Runnable() {
645 <                public void run() {
646 <                    try {
647 <                        q.put(new Object());
648 <                        q.put(new Object());
649 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
650 <                        q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
672 <                        threadShouldThrow();
673 <                    } catch (InterruptedException success){}
674 <                }
675 <            });
644 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
645 >            public void realRun() throws InterruptedException {
646 >                q.put(new Object());
647 >                q.put(new Object());
648 >                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
649 >                q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
650 >            }};
651  
652 <        try {
653 <            t.start();
654 <            Thread.sleep(SMALL_DELAY_MS);
655 <            t.interrupt();
681 <            t.join();
682 <        } catch (Exception e){
683 <            unexpectedException();
684 <        }
652 >        t.start();
653 >        Thread.sleep(SMALL_DELAY_MS);
654 >        t.interrupt();
655 >        t.join();
656      }
657  
658      /**
659       * take retrieves elements in FIFO order
660       */
661 <    public void testTake() {
662 <        try {
663 <            LinkedBlockingDeque q = populatedDeque(SIZE);
664 <            for (int i = 0; i < SIZE; ++i) {
665 <                assertEquals(i, ((Integer)q.take()).intValue());
695 <            }
696 <        } catch (InterruptedException e){
697 <            unexpectedException();
698 <        }
661 >    public void testTake() throws InterruptedException {
662 >        LinkedBlockingDeque q = populatedDeque(SIZE);
663 >        for (int i = 0; i < SIZE; ++i) {
664 >            assertEquals(i, ((Integer)q.take()).intValue());
665 >        }
666      }
667  
668      /**
669       * take blocks interruptibly when empty
670       */
671 <    public void testTakeFromEmpty() {
671 >    public void testTakeFromEmpty() throws InterruptedException {
672          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
673 <        Thread t = new Thread(new Runnable() {
674 <                public void run() {
675 <                    try {
676 <                        q.take();
677 <                        threadShouldThrow();
678 <                    } catch (InterruptedException success){ }
679 <                }
680 <            });
681 <        try {
715 <            t.start();
716 <            Thread.sleep(SHORT_DELAY_MS);
717 <            t.interrupt();
718 <            t.join();
719 <        } catch (Exception e){
720 <            unexpectedException();
721 <        }
673 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
674 >            public void realRun() throws InterruptedException {
675 >                q.take();
676 >            }};
677 >
678 >        t.start();
679 >        Thread.sleep(SHORT_DELAY_MS);
680 >        t.interrupt();
681 >        t.join();
682      }
683  
684      /**
685       * Take removes existing elements until empty, then blocks interruptibly
686       */
687 <    public void testBlockingTake() {
688 <        Thread t = new Thread(new Runnable() {
689 <                public void run() {
690 <                    try {
691 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
692 <                        for (int i = 0; i < SIZE; ++i) {
693 <                            assertEquals(i, ((Integer)q.take()).intValue());
694 <                        }
695 <                        q.take();
696 <                        threadShouldThrow();
737 <                    } catch (InterruptedException success){
738 <                    }
739 <                }});
687 >    public void testBlockingTake() throws InterruptedException {
688 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
689 >            public void realRun() throws InterruptedException {
690 >                LinkedBlockingDeque q = populatedDeque(SIZE);
691 >                for (int i = 0; i < SIZE; ++i) {
692 >                    assertEquals(i, ((Integer)q.take()).intValue());
693 >                }
694 >                q.take();
695 >            }};
696 >
697          t.start();
698 <        try {
699 <           Thread.sleep(SHORT_DELAY_MS);
700 <           t.interrupt();
744 <           t.join();
745 <        }
746 <        catch (InterruptedException ie) {
747 <            unexpectedException();
748 <        }
698 >        Thread.sleep(SHORT_DELAY_MS);
699 >        t.interrupt();
700 >        t.join();
701      }
702  
703  
# Line 757 | Line 709 | public class LinkedBlockingDequeTest ext
709          for (int i = 0; i < SIZE; ++i) {
710              assertEquals(i, ((Integer)q.poll()).intValue());
711          }
712 <        assertNull(q.poll());
712 >        assertNull(q.poll());
713      }
714  
715      /**
716       * timed poll with zero timeout succeeds when non-empty, else times out
717       */
718 <    public void testTimedPoll0() {
719 <        try {
720 <            LinkedBlockingDeque q = populatedDeque(SIZE);
721 <            for (int i = 0; i < SIZE; ++i) {
722 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
723 <            }
772 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
773 <        } catch (InterruptedException e){
774 <            unexpectedException();
775 <        }
718 >    public void testTimedPoll0() throws InterruptedException {
719 >        LinkedBlockingDeque q = populatedDeque(SIZE);
720 >        for (int i = 0; i < SIZE; ++i) {
721 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
722 >        }
723 >        assertNull(q.poll(0, MILLISECONDS));
724      }
725  
726      /**
727       * timed poll with nonzero timeout succeeds when non-empty, else times out
728       */
729 <    public void testTimedPoll() {
730 <        try {
731 <            LinkedBlockingDeque q = populatedDeque(SIZE);
732 <            for (int i = 0; i < SIZE; ++i) {
733 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
734 <            }
787 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
788 <        } catch (InterruptedException e){
789 <            unexpectedException();
790 <        }
729 >    public void testTimedPoll() throws InterruptedException {
730 >        LinkedBlockingDeque q = populatedDeque(SIZE);
731 >        for (int i = 0; i < SIZE; ++i) {
732 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
733 >        }
734 >        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
735      }
736  
737      /**
738       * Interrupted timed poll throws InterruptedException instead of
739       * returning timeout status
740       */
741 <    public void testInterruptedTimedPoll() {
742 <        Thread t = new Thread(new Runnable() {
743 <                public void run() {
744 <                    try {
745 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
746 <                        for (int i = 0; i < SIZE; ++i) {
747 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
748 <                        }
749 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
750 <                    } catch (InterruptedException success){
751 <                    }
752 <                }});
741 >    public void testInterruptedTimedPoll() throws InterruptedException {
742 >        Thread t = new Thread(new CheckedRunnable() {
743 >            public void realRun() throws InterruptedException {
744 >                LinkedBlockingDeque q = populatedDeque(SIZE);
745 >                for (int i = 0; i < SIZE; ++i) {
746 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
747 >                }
748 >                try {
749 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
750 >                    shouldThrow();
751 >                } catch (InterruptedException success) {}
752 >            }});
753 >
754          t.start();
755 <        try {
756 <           Thread.sleep(SHORT_DELAY_MS);
757 <           t.interrupt();
813 <           t.join();
814 <        }
815 <        catch (InterruptedException ie) {
816 <            unexpectedException();
817 <        }
755 >        Thread.sleep(SHORT_DELAY_MS);
756 >        t.interrupt();
757 >        t.join();
758      }
759  
760      /**
761       *  timed poll before a delayed offer fails; after offer succeeds;
762       *  on interruption throws
763       */
764 <    public void testTimedPollWithOffer() {
764 >    public void testTimedPollWithOffer() throws InterruptedException {
765          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
766 <        Thread t = new Thread(new Runnable() {
767 <                public void run() {
768 <                    try {
769 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
770 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
771 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
772 <                        threadShouldThrow();
773 <                    } catch (InterruptedException success) { }
774 <                }
775 <            });
776 <        try {
777 <            t.start();
778 <            Thread.sleep(SMALL_DELAY_MS);
779 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
780 <            t.interrupt();
841 <            t.join();
842 <        } catch (Exception e){
843 <            unexpectedException();
844 <        }
766 >        Thread t = new Thread(new CheckedRunnable() {
767 >            public void realRun() throws InterruptedException {
768 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
769 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
770 >                try {
771 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
772 >                    shouldThrow();
773 >                } catch (InterruptedException success) {}
774 >            }});
775 >
776 >        t.start();
777 >        Thread.sleep(SMALL_DELAY_MS);
778 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
779 >        t.interrupt();
780 >        t.join();
781      }
782  
783  
784      /**
785       * putFirst(null) throws NPE
786       */
787 <     public void testPutFirstNull() {
788 <        try {
787 >     public void testPutFirstNull() throws InterruptedException {
788 >        try {
789              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
790              q.putFirst(null);
791              shouldThrow();
792 <        }
857 <        catch (NullPointerException success){
858 <        }
859 <        catch (InterruptedException ie) {
860 <            unexpectedException();
861 <        }
792 >        } catch (NullPointerException success) {}
793       }
794  
795      /**
796       * all elements successfully putFirst are contained
797       */
798 <     public void testPutFirst() {
799 <         try {
800 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
801 <             for (int i = 0; i < SIZE; ++i) {
802 <                 Integer I = new Integer(i);
803 <                 q.putFirst(I);
873 <                 assertTrue(q.contains(I));
874 <             }
875 <             assertEquals(0, q.remainingCapacity());
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));
804           }
805 <        catch (InterruptedException ie) {
878 <            unexpectedException();
879 <        }
805 >         assertEquals(0, q.remainingCapacity());
806      }
807  
808      /**
809       * putFirst blocks interruptibly if full
810       */
811 <    public void testBlockingPutFirst() {
812 <        Thread t = new Thread(new Runnable() {
813 <                public void run() {
814 <                    int added = 0;
815 <                    try {
816 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
817 <                        for (int i = 0; i < SIZE; ++i) {
818 <                            q.putFirst(new Integer(i));
819 <                            ++added;
894 <                        }
895 <                        q.putFirst(new Integer(SIZE));
896 <                        threadShouldThrow();
897 <                    } catch (InterruptedException ie){
898 <                        threadAssertEquals(added, SIZE);
811 >    public void testBlockingPutFirst() throws InterruptedException {
812 >        Thread t = new Thread(new CheckedRunnable() {
813 >            public void realRun() {
814 >                int added = 0;
815 >                try {
816 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
817 >                    for (int i = 0; i < SIZE; ++i) {
818 >                        q.putFirst(new Integer(i));
819 >                        ++added;
820                      }
821 <                }});
821 >                    q.putFirst(new Integer(SIZE));
822 >                    threadShouldThrow();
823 >                } catch (InterruptedException success) {
824 >                    threadAssertEquals(added, SIZE);
825 >                }
826 >            }});
827 >
828          t.start();
829 <        try {
830 <           Thread.sleep(SHORT_DELAY_MS);
831 <           t.interrupt();
905 <           t.join();
906 <        }
907 <        catch (InterruptedException ie) {
908 <            unexpectedException();
909 <        }
829 >        Thread.sleep(SHORT_DELAY_MS);
830 >        t.interrupt();
831 >        t.join();
832      }
833  
834      /**
835       * putFirst blocks waiting for take when full
836       */
837 <    public void testPutFirstWithTake() {
837 >    public void testPutFirstWithTake() throws InterruptedException {
838          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
839 <        Thread t = new Thread(new Runnable() {
840 <                public void run() {
841 <                    int added = 0;
842 <                    try {
843 <                        q.putFirst(new Object());
844 <                        ++added;
845 <                        q.putFirst(new Object());
846 <                        ++added;
847 <                        q.putFirst(new Object());
848 <                        ++added;
849 <                        q.putFirst(new Object());
850 <                        ++added;
851 <                        threadShouldThrow();
852 <                    } catch (InterruptedException e){
853 <                        threadAssertTrue(added >= 2);
932 <                    }
839 >        Thread t = new Thread(new CheckedRunnable() {
840 >            public void realRun() {
841 >                int added = 0;
842 >                try {
843 >                    q.putFirst(new Object());
844 >                    ++added;
845 >                    q.putFirst(new Object());
846 >                    ++added;
847 >                    q.putFirst(new Object());
848 >                    ++added;
849 >                    q.putFirst(new Object());
850 >                    ++added;
851 >                    threadShouldThrow();
852 >                } catch (InterruptedException success) {
853 >                    threadAssertTrue(added >= 2);
854                  }
855 <            });
856 <        try {
857 <            t.start();
858 <            Thread.sleep(SHORT_DELAY_MS);
859 <            q.take();
860 <            t.interrupt();
861 <            t.join();
941 <        } catch (Exception e){
942 <            unexpectedException();
943 <        }
855 >            }});
856 >
857 >        t.start();
858 >        Thread.sleep(SHORT_DELAY_MS);
859 >        q.take();
860 >        t.interrupt();
861 >        t.join();
862      }
863  
864      /**
865       * timed offerFirst times out if full and elements not taken
866       */
867 <    public void testTimedOfferFirst() {
867 >    public void testTimedOfferFirst() throws InterruptedException {
868          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
869 <        Thread t = new Thread(new Runnable() {
870 <                public void run() {
871 <                    try {
872 <                        q.putFirst(new Object());
873 <                        q.putFirst(new Object());
874 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
875 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
958 <                        threadShouldThrow();
959 <                    } catch (InterruptedException success){}
960 <                }
961 <            });
869 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
870 >            public void realRun() throws InterruptedException {
871 >                q.putFirst(new Object());
872 >                q.putFirst(new Object());
873 >                threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
874 >                q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
875 >            }};
876  
877 <        try {
878 <            t.start();
879 <            Thread.sleep(SMALL_DELAY_MS);
880 <            t.interrupt();
967 <            t.join();
968 <        } catch (Exception e){
969 <            unexpectedException();
970 <        }
877 >        t.start();
878 >        Thread.sleep(SMALL_DELAY_MS);
879 >        t.interrupt();
880 >        t.join();
881      }
882  
883      /**
884       * take retrieves elements in FIFO order
885       */
886 <    public void testTakeFirst() {
887 <        try {
888 <            LinkedBlockingDeque q = populatedDeque(SIZE);
889 <            for (int i = 0; i < SIZE; ++i) {
890 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
981 <            }
982 <        } catch (InterruptedException e){
983 <            unexpectedException();
984 <        }
886 >    public void testTakeFirst() throws InterruptedException {
887 >        LinkedBlockingDeque q = populatedDeque(SIZE);
888 >        for (int i = 0; i < SIZE; ++i) {
889 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
890 >        }
891      }
892  
893      /**
894       * takeFirst blocks interruptibly when empty
895       */
896 <    public void testTakeFirstFromEmpty() {
896 >    public void testTakeFirstFromEmpty() throws InterruptedException {
897          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
898 <        Thread t = new Thread(new Runnable() {
899 <                public void run() {
900 <                    try {
901 <                        q.takeFirst();
902 <                        threadShouldThrow();
903 <                    } catch (InterruptedException success){ }
904 <                }
905 <            });
906 <        try {
1001 <            t.start();
1002 <            Thread.sleep(SHORT_DELAY_MS);
1003 <            t.interrupt();
1004 <            t.join();
1005 <        } catch (Exception e){
1006 <            unexpectedException();
1007 <        }
898 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
899 >            public void realRun() throws InterruptedException {
900 >                q.takeFirst();
901 >            }};
902 >
903 >        t.start();
904 >        Thread.sleep(SHORT_DELAY_MS);
905 >        t.interrupt();
906 >        t.join();
907      }
908  
909      /**
910       * TakeFirst removes existing elements until empty, then blocks interruptibly
911       */
912 <    public void testBlockingTakeFirst() {
913 <        Thread t = new Thread(new Runnable() {
914 <                public void run() {
915 <                    try {
916 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
917 <                        for (int i = 0; i < SIZE; ++i) {
918 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
919 <                        }
920 <                        q.takeFirst();
921 <                        threadShouldThrow();
1023 <                    } catch (InterruptedException success){
1024 <                    }
1025 <                }});
912 >    public void testBlockingTakeFirst() throws InterruptedException {
913 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
914 >            public void realRun() throws InterruptedException {
915 >                LinkedBlockingDeque q = populatedDeque(SIZE);
916 >                for (int i = 0; i < SIZE; ++i) {
917 >                    assertEquals(i, ((Integer)q.takeFirst()).intValue());
918 >                }
919 >                q.takeFirst();
920 >            }};
921 >
922          t.start();
923 <        try {
924 <           Thread.sleep(SHORT_DELAY_MS);
925 <           t.interrupt();
1030 <           t.join();
1031 <        }
1032 <        catch (InterruptedException ie) {
1033 <            unexpectedException();
1034 <        }
923 >        Thread.sleep(SHORT_DELAY_MS);
924 >        t.interrupt();
925 >        t.join();
926      }
927  
928  
929      /**
930       * timed pollFirst with zero timeout succeeds when non-empty, else times out
931       */
932 <    public void testTimedPollFirst0() {
933 <        try {
934 <            LinkedBlockingDeque q = populatedDeque(SIZE);
935 <            for (int i = 0; i < SIZE; ++i) {
936 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
937 <            }
1047 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1048 <        } catch (InterruptedException e){
1049 <            unexpectedException();
1050 <        }
932 >    public void testTimedPollFirst0() throws InterruptedException {
933 >        LinkedBlockingDeque q = populatedDeque(SIZE);
934 >        for (int i = 0; i < SIZE; ++i) {
935 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
936 >        }
937 >        assertNull(q.pollFirst(0, MILLISECONDS));
938      }
939  
940      /**
941       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
942       */
943 <    public void testTimedPollFirst() {
944 <        try {
945 <            LinkedBlockingDeque q = populatedDeque(SIZE);
946 <            for (int i = 0; i < SIZE; ++i) {
947 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
948 <            }
1062 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1063 <        } catch (InterruptedException e){
1064 <            unexpectedException();
1065 <        }
943 >    public void testTimedPollFirst() throws InterruptedException {
944 >        LinkedBlockingDeque q = populatedDeque(SIZE);
945 >        for (int i = 0; i < SIZE; ++i) {
946 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
947 >        }
948 >        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
949      }
950  
951      /**
952       * Interrupted timed pollFirst throws InterruptedException instead of
953       * returning timeout status
954       */
955 <    public void testInterruptedTimedPollFirst() {
956 <        Thread t = new Thread(new Runnable() {
957 <                public void run() {
958 <                    try {
959 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
960 <                        for (int i = 0; i < SIZE; ++i) {
961 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
962 <                        }
963 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
964 <                    } catch (InterruptedException success){
965 <                    }
966 <                }});
955 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
956 >        Thread t = new Thread(new CheckedRunnable() {
957 >            public void realRun() throws InterruptedException {
958 >                LinkedBlockingDeque q = populatedDeque(SIZE);
959 >                for (int i = 0; i < SIZE; ++i) {
960 >                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
961 >                }
962 >                try {
963 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
964 >                    shouldThrow();
965 >                } catch (InterruptedException success) {}
966 >            }});
967 >
968          t.start();
969 <        try {
970 <           Thread.sleep(SHORT_DELAY_MS);
971 <           t.interrupt();
1088 <           t.join();
1089 <        }
1090 <        catch (InterruptedException ie) {
1091 <            unexpectedException();
1092 <        }
969 >        Thread.sleep(SHORT_DELAY_MS);
970 >        t.interrupt();
971 >        t.join();
972      }
973  
974      /**
975       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
976       *  on interruption throws
977       */
978 <    public void testTimedPollFirstWithOfferFirst() {
978 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
979          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
980 <        Thread t = new Thread(new Runnable() {
981 <                public void run() {
982 <                    try {
983 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
984 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
985 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
986 <                        threadShouldThrow();
987 <                    } catch (InterruptedException success) { }
988 <                }
989 <            });
990 <        try {
991 <            t.start();
992 <            Thread.sleep(SMALL_DELAY_MS);
993 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
994 <            t.interrupt();
1116 <            t.join();
1117 <        } catch (Exception e){
1118 <            unexpectedException();
1119 <        }
980 >        Thread t = new Thread(new CheckedRunnable() {
981 >            public void realRun() throws InterruptedException {
982 >                assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
983 >                assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
984 >                try {
985 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
986 >                    shouldThrow();
987 >                } catch (InterruptedException success) {}
988 >            }});
989 >
990 >        t.start();
991 >        Thread.sleep(SMALL_DELAY_MS);
992 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
993 >        t.interrupt();
994 >        t.join();
995      }
996  
997      /**
998       * putLast(null) throws NPE
999       */
1000 <     public void testPutLastNull() {
1001 <        try {
1000 >     public void testPutLastNull() throws InterruptedException {
1001 >        try {
1002              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1003              q.putLast(null);
1004              shouldThrow();
1005 <        }
1131 <        catch (NullPointerException success){
1132 <        }
1133 <        catch (InterruptedException ie) {
1134 <            unexpectedException();
1135 <        }
1005 >        } catch (NullPointerException success) {}
1006       }
1007  
1008      /**
1009       * all elements successfully putLast are contained
1010       */
1011 <     public void testPutLast() {
1012 <         try {
1013 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1014 <             for (int i = 0; i < SIZE; ++i) {
1015 <                 Integer I = new Integer(i);
1016 <                 q.putLast(I);
1147 <                 assertTrue(q.contains(I));
1148 <             }
1149 <             assertEquals(0, q.remainingCapacity());
1011 >     public void testPutLast() throws InterruptedException {
1012 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1013 >         for (int i = 0; i < SIZE; ++i) {
1014 >             Integer I = new Integer(i);
1015 >             q.putLast(I);
1016 >             assertTrue(q.contains(I));
1017           }
1018 <        catch (InterruptedException ie) {
1152 <            unexpectedException();
1153 <        }
1018 >         assertEquals(0, q.remainingCapacity());
1019      }
1020  
1021      /**
1022       * putLast blocks interruptibly if full
1023       */
1024 <    public void testBlockingPutLast() {
1025 <        Thread t = new Thread(new Runnable() {
1026 <                public void run() {
1027 <                    int added = 0;
1028 <                    try {
1029 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1030 <                        for (int i = 0; i < SIZE; ++i) {
1031 <                            q.putLast(new Integer(i));
1032 <                            ++added;
1168 <                        }
1169 <                        q.putLast(new Integer(SIZE));
1170 <                        threadShouldThrow();
1171 <                    } catch (InterruptedException ie){
1172 <                        threadAssertEquals(added, SIZE);
1024 >    public void testBlockingPutLast() throws InterruptedException {
1025 >        Thread t = new Thread(new CheckedRunnable() {
1026 >            public void realRun() {
1027 >                int added = 0;
1028 >                try {
1029 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1030 >                    for (int i = 0; i < SIZE; ++i) {
1031 >                        q.putLast(new Integer(i));
1032 >                        ++added;
1033                      }
1034 <                }});
1034 >                    q.putLast(new Integer(SIZE));
1035 >                    threadShouldThrow();
1036 >                } catch (InterruptedException success) {
1037 >                    threadAssertEquals(added, SIZE);
1038 >                }
1039 >            }});
1040 >
1041          t.start();
1042 <        try {
1043 <           Thread.sleep(SHORT_DELAY_MS);
1044 <           t.interrupt();
1179 <           t.join();
1180 <        }
1181 <        catch (InterruptedException ie) {
1182 <            unexpectedException();
1183 <        }
1042 >        Thread.sleep(SHORT_DELAY_MS);
1043 >        t.interrupt();
1044 >        t.join();
1045      }
1046  
1047      /**
1048       * putLast blocks waiting for take when full
1049       */
1050 <    public void testPutLastWithTake() {
1050 >    public void testPutLastWithTake() throws InterruptedException {
1051          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1052 <        Thread t = new Thread(new Runnable() {
1053 <                public void run() {
1054 <                    int added = 0;
1055 <                    try {
1056 <                        q.putLast(new Object());
1057 <                        ++added;
1058 <                        q.putLast(new Object());
1059 <                        ++added;
1060 <                        q.putLast(new Object());
1061 <                        ++added;
1062 <                        q.putLast(new Object());
1063 <                        ++added;
1064 <                        threadShouldThrow();
1065 <                    } catch (InterruptedException e){
1066 <                        threadAssertTrue(added >= 2);
1206 <                    }
1052 >        Thread t = new Thread(new CheckedRunnable() {
1053 >            public void realRun() {
1054 >                int added = 0;
1055 >                try {
1056 >                    q.putLast(new Object());
1057 >                    ++added;
1058 >                    q.putLast(new Object());
1059 >                    ++added;
1060 >                    q.putLast(new Object());
1061 >                    ++added;
1062 >                    q.putLast(new Object());
1063 >                    ++added;
1064 >                    threadShouldThrow();
1065 >                } catch (InterruptedException success) {
1066 >                    threadAssertTrue(added >= 2);
1067                  }
1068 <            });
1069 <        try {
1070 <            t.start();
1071 <            Thread.sleep(SHORT_DELAY_MS);
1072 <            q.take();
1073 <            t.interrupt();
1074 <            t.join();
1215 <        } catch (Exception e){
1216 <            unexpectedException();
1217 <        }
1068 >            }});
1069 >
1070 >        t.start();
1071 >        Thread.sleep(SHORT_DELAY_MS);
1072 >        q.take();
1073 >        t.interrupt();
1074 >        t.join();
1075      }
1076  
1077      /**
1078       * timed offerLast times out if full and elements not taken
1079       */
1080 <    public void testTimedOfferLast() {
1080 >    public void testTimedOfferLast() throws InterruptedException {
1081          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1082 <        Thread t = new Thread(new Runnable() {
1083 <                public void run() {
1084 <                    try {
1085 <                        q.putLast(new Object());
1086 <                        q.putLast(new Object());
1087 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1088 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1232 <                        threadShouldThrow();
1233 <                    } catch (InterruptedException success){}
1234 <                }
1235 <            });
1082 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1083 >            public void realRun() throws InterruptedException {
1084 >                q.putLast(new Object());
1085 >                q.putLast(new Object());
1086 >                threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1087 >                q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1088 >            }};
1089  
1090 <        try {
1091 <            t.start();
1092 <            Thread.sleep(SMALL_DELAY_MS);
1093 <            t.interrupt();
1241 <            t.join();
1242 <        } catch (Exception e){
1243 <            unexpectedException();
1244 <        }
1090 >        t.start();
1091 >        Thread.sleep(SMALL_DELAY_MS);
1092 >        t.interrupt();
1093 >        t.join();
1094      }
1095  
1096      /**
1097       * takeLast retrieves elements in FIFO order
1098       */
1099 <    public void testTakeLast() {
1100 <        try {
1101 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1102 <            for (int i = 0; i < SIZE; ++i) {
1103 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1255 <            }
1256 <        } catch (InterruptedException e){
1257 <            unexpectedException();
1258 <        }
1099 >    public void testTakeLast() throws InterruptedException {
1100 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1101 >        for (int i = 0; i < SIZE; ++i) {
1102 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1103 >        }
1104      }
1105  
1106      /**
1107       * takeLast blocks interruptibly when empty
1108       */
1109 <    public void testTakeLastFromEmpty() {
1109 >    public void testTakeLastFromEmpty() throws InterruptedException {
1110          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1111 <        Thread t = new Thread(new Runnable() {
1112 <                public void run() {
1113 <                    try {
1114 <                        q.takeLast();
1115 <                        threadShouldThrow();
1116 <                    } catch (InterruptedException success){ }
1117 <                }
1118 <            });
1119 <        try {
1275 <            t.start();
1276 <            Thread.sleep(SHORT_DELAY_MS);
1277 <            t.interrupt();
1278 <            t.join();
1279 <        } catch (Exception e){
1280 <            unexpectedException();
1281 <        }
1111 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1112 >            public void realRun() throws InterruptedException {
1113 >                q.takeLast();
1114 >            }};
1115 >
1116 >        t.start();
1117 >        Thread.sleep(SHORT_DELAY_MS);
1118 >        t.interrupt();
1119 >        t.join();
1120      }
1121  
1122      /**
1123       * TakeLast removes existing elements until empty, then blocks interruptibly
1124       */
1125 <    public void testBlockingTakeLast() {
1126 <        Thread t = new Thread(new Runnable() {
1127 <                public void run() {
1128 <                    try {
1129 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1130 <                        for (int i = 0; i < SIZE; ++i) {
1131 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1132 <                        }
1133 <                        q.takeLast();
1134 <                        threadShouldThrow();
1297 <                    } catch (InterruptedException success){
1298 <                    }
1299 <                }});
1125 >    public void testBlockingTakeLast() throws InterruptedException {
1126 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1127 >            public void realRun() throws InterruptedException {
1128 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1129 >                for (int i = 0; i < SIZE; ++i) {
1130 >                    assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1131 >                }
1132 >                q.takeLast();
1133 >            }};
1134 >
1135          t.start();
1136 <        try {
1137 <           Thread.sleep(SHORT_DELAY_MS);
1138 <           t.interrupt();
1304 <           t.join();
1305 <        }
1306 <        catch (InterruptedException ie) {
1307 <            unexpectedException();
1308 <        }
1136 >        Thread.sleep(SHORT_DELAY_MS);
1137 >        t.interrupt();
1138 >        t.join();
1139      }
1140  
1141  
1142      /**
1143       * timed pollLast with zero timeout succeeds when non-empty, else times out
1144       */
1145 <    public void testTimedPollLast0() {
1146 <        try {
1147 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1148 <            for (int i = 0; i < SIZE; ++i) {
1149 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1150 <            }
1321 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1322 <        } catch (InterruptedException e){
1323 <            unexpectedException();
1324 <        }
1145 >    public void testTimedPollLast0() throws InterruptedException {
1146 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1147 >        for (int i = 0; i < SIZE; ++i) {
1148 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1149 >        }
1150 >        assertNull(q.pollLast(0, MILLISECONDS));
1151      }
1152  
1153      /**
1154       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1155       */
1156 <    public void testTimedPollLast() {
1157 <        try {
1158 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1159 <            for (int i = 0; i < SIZE; ++i) {
1160 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1161 <            }
1336 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1337 <        } catch (InterruptedException e){
1338 <            unexpectedException();
1339 <        }
1156 >    public void testTimedPollLast() throws InterruptedException {
1157 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1158 >        for (int i = 0; i < SIZE; ++i) {
1159 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1160 >        }
1161 >        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1162      }
1163  
1164      /**
1165       * Interrupted timed pollLast throws InterruptedException instead of
1166       * returning timeout status
1167       */
1168 <    public void testInterruptedTimedPollLast() {
1169 <        Thread t = new Thread(new Runnable() {
1170 <                public void run() {
1171 <                    try {
1172 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1173 <                        for (int i = 0; i < SIZE; ++i) {
1174 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1175 <                        }
1176 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1177 <                    } catch (InterruptedException success){
1178 <                    }
1179 <                }});
1168 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1169 >        Thread t = new Thread(new CheckedRunnable() {
1170 >            public void realRun() throws InterruptedException {
1171 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1172 >                for (int i = 0; i < SIZE; ++i) {
1173 >                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1174 >                }
1175 >                try {
1176 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1177 >                    shouldThrow();
1178 >                } catch (InterruptedException success) {}
1179 >            }});
1180 >
1181          t.start();
1182 <        try {
1183 <           Thread.sleep(SHORT_DELAY_MS);
1184 <           t.interrupt();
1362 <           t.join();
1363 <        }
1364 <        catch (InterruptedException ie) {
1365 <            unexpectedException();
1366 <        }
1182 >        Thread.sleep(SHORT_DELAY_MS);
1183 >        t.interrupt();
1184 >        t.join();
1185      }
1186  
1187      /**
1188       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1189       *  on interruption throws
1190       */
1191 <    public void testTimedPollWithOfferLast() {
1191 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1192          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1193 <        Thread t = new Thread(new Runnable() {
1194 <                public void run() {
1195 <                    try {
1196 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1197 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1198 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1199 <                        threadShouldThrow();
1200 <                    } catch (InterruptedException success) { }
1201 <                }
1202 <            });
1203 <        try {
1204 <            t.start();
1205 <            Thread.sleep(SMALL_DELAY_MS);
1206 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1207 <            t.interrupt();
1390 <            t.join();
1391 <        } catch (Exception e){
1392 <            unexpectedException();
1393 <        }
1193 >        Thread t = new Thread(new CheckedRunnable() {
1194 >            public void realRun() throws InterruptedException {
1195 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1196 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1197 >                try {
1198 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1199 >                    shouldThrow();
1200 >                } catch (InterruptedException success) {}
1201 >            }});
1202 >
1203 >        t.start();
1204 >        Thread.sleep(SMALL_DELAY_MS);
1205 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1206 >        t.interrupt();
1207 >        t.join();
1208      }
1209  
1210  
# Line 1406 | Line 1220 | public class LinkedBlockingDequeTest ext
1220          try {
1221              q.element();
1222              shouldThrow();
1223 <        }
1410 <        catch (NoSuchElementException success) {}
1223 >        } catch (NoSuchElementException success) {}
1224      }
1225  
1226      /**
# Line 1505 | Line 1318 | public class LinkedBlockingDequeTest ext
1318      /**
1319       * toArray contains all elements
1320       */
1321 <    public void testToArray() {
1321 >    public void testToArray() throws InterruptedException{
1322          LinkedBlockingDeque q = populatedDeque(SIZE);
1323 <        Object[] o = q.toArray();
1324 <        try {
1325 <        for (int i = 0; i < o.length; i++)
1513 <            assertEquals(o[i], q.take());
1514 <        } catch (InterruptedException e){
1515 <            unexpectedException();
1516 <        }
1323 >        Object[] o = q.toArray();
1324 >        for (int i = 0; i < o.length; i++)
1325 >            assertEquals(o[i], q.take());
1326      }
1327  
1328      /**
1329       * toArray(a) contains all elements
1330       */
1331 <    public void testToArray2() {
1331 >    public void testToArray2() throws InterruptedException {
1332          LinkedBlockingDeque q = populatedDeque(SIZE);
1333 <        Integer[] ints = new Integer[SIZE];
1334 <        ints = (Integer[])q.toArray(ints);
1335 <        try {
1336 <            for (int i = 0; i < ints.length; i++)
1528 <                assertEquals(ints[i], q.take());
1529 <        } catch (InterruptedException e){
1530 <            unexpectedException();
1531 <        }
1333 >        Integer[] ints = new Integer[SIZE];
1334 >        ints = (Integer[])q.toArray(ints);
1335 >        for (int i = 0; i < ints.length; i++)
1336 >            assertEquals(ints[i], q.take());
1337      }
1338  
1339      /**
1340       * toArray(null) throws NPE
1341       */
1342      public void testToArray_BadArg() {
1343 <        try {
1343 >        try {
1344              LinkedBlockingDeque q = populatedDeque(SIZE);
1345 <            Object o[] = q.toArray(null);
1346 <            shouldThrow();
1347 <        } catch (NullPointerException success){}
1345 >            Object o[] = q.toArray(null);
1346 >            shouldThrow();
1347 >        } catch (NullPointerException success) {}
1348      }
1349  
1350      /**
1351       * toArray with incompatible array type throws CCE
1352       */
1353      public void testToArray1_BadArg() {
1354 <        try {
1354 >        try {
1355              LinkedBlockingDeque q = populatedDeque(SIZE);
1356 <            Object o[] = q.toArray(new String[10] );
1357 <            shouldThrow();
1358 <        } catch (ArrayStoreException  success){}
1356 >            Object o[] = q.toArray(new String[10] );
1357 >            shouldThrow();
1358 >        } catch (ArrayStoreException success) {}
1359      }
1360  
1361  
1362      /**
1363       * iterator iterates through all elements
1364       */
1365 <    public void testIterator() {
1365 >    public void testIterator() throws InterruptedException {
1366          LinkedBlockingDeque q = populatedDeque(SIZE);
1367 <        Iterator it = q.iterator();
1368 <        try {
1369 <            while (it.hasNext()){
1370 <                assertEquals(it.next(), q.take());
1566 <            }
1567 <        } catch (InterruptedException e){
1568 <            unexpectedException();
1569 <        }
1367 >        Iterator it = q.iterator();
1368 >        while (it.hasNext()) {
1369 >            assertEquals(it.next(), q.take());
1370 >        }
1371      }
1372  
1373      /**
# Line 1614 | Line 1415 | public class LinkedBlockingDequeTest ext
1415          q.add(one);
1416          q.add(two);
1417          q.add(three);
1418 <        try {
1419 <            for (Iterator it = q.iterator(); it.hasNext();) {
1420 <                q.remove();
1620 <                it.next();
1621 <            }
1622 <        }
1623 <        catch (ConcurrentModificationException e) {
1624 <            unexpectedException();
1418 >        for (Iterator it = q.iterator(); it.hasNext();) {
1419 >            q.remove();
1420 >            it.next();
1421          }
1422          assertEquals(0, q.size());
1423      }
# Line 1633 | Line 1429 | public class LinkedBlockingDequeTest ext
1429      public void testDescendingIterator() {
1430          LinkedBlockingDeque q = populatedDeque(SIZE);
1431          int i = 0;
1432 <        Iterator it = q.descendingIterator();
1432 >        Iterator it = q.descendingIterator();
1433          while (it.hasNext()) {
1434              assertTrue(q.contains(it.next()));
1435              ++i;
# Line 1642 | Line 1438 | public class LinkedBlockingDequeTest ext
1438          assertFalse(it.hasNext());
1439          try {
1440              it.next();
1441 <        } catch (NoSuchElementException success) {
1442 <        }
1441 >            shouldThrow();
1442 >        } catch (NoSuchElementException success) {}
1443      }
1444  
1445      /**
# Line 1711 | Line 1507 | public class LinkedBlockingDequeTest ext
1507          q.add(one);
1508          q.add(two);
1509          ExecutorService executor = Executors.newFixedThreadPool(2);
1510 <        executor.execute(new Runnable() {
1511 <            public void run() {
1510 >        executor.execute(new CheckedRunnable() {
1511 >            public void realRun() throws InterruptedException {
1512                  threadAssertFalse(q.offer(three));
1513 <                try {
1514 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1515 <                    threadAssertEquals(0, q.remainingCapacity());
1516 <                }
1517 <                catch (InterruptedException e) {
1518 <                    threadUnexpectedException();
1519 <                }
1520 <            }
1521 <        });
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 <        });
1513 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1514 >                threadAssertEquals(0, q.remainingCapacity());
1515 >            }});
1516 >
1517 >        executor.execute(new CheckedRunnable() {
1518 >            public void realRun() throws InterruptedException {
1519 >                Thread.sleep(SMALL_DELAY_MS);
1520 >                threadAssertEquals(one, q.take());
1521 >            }});
1522  
1523          joinPool(executor);
1524      }
# Line 1745 | Line 1529 | public class LinkedBlockingDequeTest ext
1529      public void testPollInExecutor() {
1530          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1531          ExecutorService executor = Executors.newFixedThreadPool(2);
1532 <        executor.execute(new Runnable() {
1533 <            public void run() {
1532 >        executor.execute(new CheckedRunnable() {
1533 >            public void realRun() throws InterruptedException {
1534                  threadAssertNull(q.poll());
1535 <                try {
1536 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1537 <                    threadAssertTrue(q.isEmpty());
1538 <                }
1539 <                catch (InterruptedException e) {
1540 <                    threadUnexpectedException();
1541 <                }
1542 <            }
1543 <        });
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 <        });
1535 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1536 >                threadAssertTrue(q.isEmpty());
1537 >            }});
1538 >
1539 >        executor.execute(new CheckedRunnable() {
1540 >            public void realRun() throws InterruptedException {
1541 >                Thread.sleep(SMALL_DELAY_MS);
1542 >                q.put(one);
1543 >            }});
1544  
1545          joinPool(executor);
1546      }
# Line 1776 | Line 1548 | public class LinkedBlockingDequeTest ext
1548      /**
1549       * A deserialized serialized deque has same elements in same order
1550       */
1551 <    public void testSerialization() {
1551 >    public void testSerialization() throws Exception {
1552          LinkedBlockingDeque q = populatedDeque(SIZE);
1553  
1554 <        try {
1555 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1556 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1557 <            out.writeObject(q);
1558 <            out.close();
1559 <
1560 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1561 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1562 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1563 <            assertEquals(q.size(), r.size());
1564 <            while (!q.isEmpty())
1793 <                assertEquals(q.remove(), r.remove());
1794 <        } catch (Exception e){
1795 <            unexpectedException();
1796 <        }
1554 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1555 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1556 >        out.writeObject(q);
1557 >        out.close();
1558 >
1559 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1560 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1561 >        LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1562 >        assertEquals(q.size(), r.size());
1563 >        while (!q.isEmpty())
1564 >            assertEquals(q.remove(), r.remove());
1565      }
1566  
1567      /**
# Line 1804 | Line 1572 | public class LinkedBlockingDequeTest ext
1572          try {
1573              q.drainTo(null);
1574              shouldThrow();
1575 <        } catch (NullPointerException success) {
1808 <        }
1575 >        } catch (NullPointerException success) {}
1576      }
1577  
1578      /**
# Line 1816 | Line 1583 | public class LinkedBlockingDequeTest ext
1583          try {
1584              q.drainTo(q);
1585              shouldThrow();
1586 <        } catch (IllegalArgumentException success) {
1820 <        }
1586 >        } catch (IllegalArgumentException success) {}
1587      }
1588  
1589      /**
# Line 1847 | Line 1613 | public class LinkedBlockingDequeTest ext
1613      /**
1614       * drainTo empties full deque, unblocking a waiting put.
1615       */
1616 <    public void testDrainToWithActivePut() {
1616 >    public void testDrainToWithActivePut() throws InterruptedException {
1617          final LinkedBlockingDeque q = populatedDeque(SIZE);
1618 <        Thread t = new Thread(new Runnable() {
1619 <                public void run() {
1620 <                    try {
1621 <                        q.put(new Integer(SIZE+1));
1622 <                    } catch (InterruptedException ie){
1623 <                        threadUnexpectedException();
1624 <                    }
1625 <                }
1626 <            });
1627 <        try {
1628 <            t.start();
1629 <            ArrayList l = new ArrayList();
1630 <            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 <        }
1618 >        Thread t = new Thread(new CheckedRunnable() {
1619 >            public void realRun() throws InterruptedException {
1620 >                q.put(new Integer(SIZE+1));
1621 >            }});
1622 >
1623 >        t.start();
1624 >        ArrayList l = new ArrayList();
1625 >        q.drainTo(l);
1626 >        assertTrue(l.size() >= SIZE);
1627 >        for (int i = 0; i < SIZE; ++i)
1628 >            assertEquals(l.get(i), new Integer(i));
1629 >        t.join();
1630 >        assertTrue(q.size() + l.size() >= SIZE);
1631      }
1632  
1633      /**
# Line 1880 | Line 1638 | public class LinkedBlockingDequeTest ext
1638          try {
1639              q.drainTo(null, 0);
1640              shouldThrow();
1641 <        } catch (NullPointerException success) {
1884 <        }
1641 >        } catch (NullPointerException success) {}
1642      }
1643  
1644      /**
# Line 1892 | Line 1649 | public class LinkedBlockingDequeTest ext
1649          try {
1650              q.drainTo(q, 0);
1651              shouldThrow();
1652 <        } catch (IllegalArgumentException success) {
1896 <        }
1652 >        } catch (IllegalArgumentException success) {}
1653      }
1654  
1655      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines