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.4 by jsr166, Mon Nov 2 20:28:31 2009 UTC vs.
Revision 1.13 by jsr166, Sat Nov 21 19:11:53 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();
838 <            Thread.sleep(SMALL_DELAY_MS);
839 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
840 <            t.interrupt();
841 <            t.join();
842 <        } catch (Exception e){
843 <            unexpectedException();
844 <        }
749 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
750 >            public void realRun() throws InterruptedException {
751 >                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
752 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
753 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
754 >            }};
755 >
756 >        t.start();
757 >        Thread.sleep(SMALL_DELAY_MS);
758 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
759 >        t.interrupt();
760 >        t.join();
761      }
762  
763  
764      /**
765       * putFirst(null) throws NPE
766       */
767 <     public void testPutFirstNull() {
768 <        try {
767 >     public void testPutFirstNull() throws InterruptedException {
768 >        try {
769              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
770              q.putFirst(null);
771              shouldThrow();
772 <        }
857 <        catch (NullPointerException success){
858 <        }
859 <        catch (InterruptedException ie) {
860 <            unexpectedException();
861 <        }
772 >        } catch (NullPointerException success) {}
773       }
774  
775      /**
776       * all elements successfully putFirst are contained
777       */
778 <     public void testPutFirst() {
779 <         try {
780 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
781 <             for (int i = 0; i < SIZE; ++i) {
782 <                 Integer I = new Integer(i);
783 <                 q.putFirst(I);
873 <                 assertTrue(q.contains(I));
874 <             }
875 <             assertEquals(0, q.remainingCapacity());
778 >     public void testPutFirst() throws InterruptedException {
779 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
780 >         for (int i = 0; i < SIZE; ++i) {
781 >             Integer I = new Integer(i);
782 >             q.putFirst(I);
783 >             assertTrue(q.contains(I));
784           }
785 <        catch (InterruptedException ie) {
878 <            unexpectedException();
879 <        }
785 >         assertEquals(0, q.remainingCapacity());
786      }
787  
788      /**
789       * putFirst blocks interruptibly if full
790       */
791 <    public void testBlockingPutFirst() {
792 <        Thread t = new Thread(new Runnable() {
793 <                public void run() {
794 <                    int added = 0;
795 <                    try {
796 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
797 <                        for (int i = 0; i < SIZE; ++i) {
798 <                            q.putFirst(new Integer(i));
799 <                            ++added;
894 <                        }
895 <                        q.putFirst(new Integer(SIZE));
896 <                        threadShouldThrow();
897 <                    } catch (InterruptedException ie){
898 <                        threadAssertEquals(added, SIZE);
791 >    public void testBlockingPutFirst() throws InterruptedException {
792 >        Thread t = new Thread(new CheckedRunnable() {
793 >            public void realRun() {
794 >                int added = 0;
795 >                try {
796 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
797 >                    for (int i = 0; i < SIZE; ++i) {
798 >                        q.putFirst(new Integer(i));
799 >                        ++added;
800                      }
801 <                }});
801 >                    q.putFirst(new Integer(SIZE));
802 >                    threadShouldThrow();
803 >                } catch (InterruptedException success) {
804 >                    threadAssertEquals(added, SIZE);
805 >                }
806 >            }});
807 >
808          t.start();
809 <        try {
810 <           Thread.sleep(SHORT_DELAY_MS);
811 <           t.interrupt();
905 <           t.join();
906 <        }
907 <        catch (InterruptedException ie) {
908 <            unexpectedException();
909 <        }
809 >        Thread.sleep(SHORT_DELAY_MS);
810 >        t.interrupt();
811 >        t.join();
812      }
813  
814      /**
815       * putFirst blocks waiting for take when full
816       */
817 <    public void testPutFirstWithTake() {
817 >    public void testPutFirstWithTake() throws InterruptedException {
818          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
819 <        Thread t = new Thread(new Runnable() {
820 <                public void run() {
821 <                    int added = 0;
822 <                    try {
823 <                        q.putFirst(new Object());
824 <                        ++added;
825 <                        q.putFirst(new Object());
826 <                        ++added;
827 <                        q.putFirst(new Object());
828 <                        ++added;
829 <                        q.putFirst(new Object());
830 <                        ++added;
831 <                        threadShouldThrow();
832 <                    } catch (InterruptedException e){
833 <                        threadAssertTrue(added >= 2);
932 <                    }
819 >        Thread t = new Thread(new CheckedRunnable() {
820 >            public void realRun() {
821 >                int added = 0;
822 >                try {
823 >                    q.putFirst(new Object());
824 >                    ++added;
825 >                    q.putFirst(new Object());
826 >                    ++added;
827 >                    q.putFirst(new Object());
828 >                    ++added;
829 >                    q.putFirst(new Object());
830 >                    ++added;
831 >                    threadShouldThrow();
832 >                } catch (InterruptedException success) {
833 >                    threadAssertTrue(added >= 2);
834                  }
835 <            });
836 <        try {
837 <            t.start();
838 <            Thread.sleep(SHORT_DELAY_MS);
839 <            q.take();
840 <            t.interrupt();
841 <            t.join();
941 <        } catch (Exception e){
942 <            unexpectedException();
943 <        }
835 >            }});
836 >
837 >        t.start();
838 >        Thread.sleep(SHORT_DELAY_MS);
839 >        q.take();
840 >        t.interrupt();
841 >        t.join();
842      }
843  
844      /**
845       * timed offerFirst times out if full and elements not taken
846       */
847 <    public void testTimedOfferFirst() {
847 >    public void testTimedOfferFirst() throws InterruptedException {
848          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
849 <        Thread t = new Thread(new Runnable() {
850 <                public void run() {
851 <                    try {
852 <                        q.putFirst(new Object());
853 <                        q.putFirst(new Object());
854 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
855 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
958 <                        threadShouldThrow();
959 <                    } catch (InterruptedException success){}
960 <                }
961 <            });
849 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
850 >            public void realRun() throws InterruptedException {
851 >                q.putFirst(new Object());
852 >                q.putFirst(new Object());
853 >                threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
854 >                q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
855 >            }};
856  
857 <        try {
858 <            t.start();
859 <            Thread.sleep(SMALL_DELAY_MS);
860 <            t.interrupt();
967 <            t.join();
968 <        } catch (Exception e){
969 <            unexpectedException();
970 <        }
857 >        t.start();
858 >        Thread.sleep(SMALL_DELAY_MS);
859 >        t.interrupt();
860 >        t.join();
861      }
862  
863      /**
864       * take retrieves elements in FIFO order
865       */
866 <    public void testTakeFirst() {
867 <        try {
868 <            LinkedBlockingDeque q = populatedDeque(SIZE);
869 <            for (int i = 0; i < SIZE; ++i) {
870 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
981 <            }
982 <        } catch (InterruptedException e){
983 <            unexpectedException();
984 <        }
866 >    public void testTakeFirst() throws InterruptedException {
867 >        LinkedBlockingDeque q = populatedDeque(SIZE);
868 >        for (int i = 0; i < SIZE; ++i) {
869 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
870 >        }
871      }
872  
873      /**
874       * takeFirst blocks interruptibly when empty
875       */
876 <    public void testTakeFirstFromEmpty() {
876 >    public void testTakeFirstFromEmpty() throws InterruptedException {
877          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
878 <        Thread t = new Thread(new Runnable() {
879 <                public void run() {
880 <                    try {
881 <                        q.takeFirst();
882 <                        threadShouldThrow();
883 <                    } catch (InterruptedException success){ }
884 <                }
885 <            });
886 <        try {
1001 <            t.start();
1002 <            Thread.sleep(SHORT_DELAY_MS);
1003 <            t.interrupt();
1004 <            t.join();
1005 <        } catch (Exception e){
1006 <            unexpectedException();
1007 <        }
878 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
879 >            public void realRun() throws InterruptedException {
880 >                q.takeFirst();
881 >            }};
882 >
883 >        t.start();
884 >        Thread.sleep(SHORT_DELAY_MS);
885 >        t.interrupt();
886 >        t.join();
887      }
888  
889      /**
890       * TakeFirst removes existing elements until empty, then blocks interruptibly
891       */
892 <    public void testBlockingTakeFirst() {
893 <        Thread t = new Thread(new Runnable() {
894 <                public void run() {
895 <                    try {
896 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
897 <                        for (int i = 0; i < SIZE; ++i) {
898 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
899 <                        }
900 <                        q.takeFirst();
901 <                        threadShouldThrow();
1023 <                    } catch (InterruptedException success){
1024 <                    }
1025 <                }});
892 >    public void testBlockingTakeFirst() throws InterruptedException {
893 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
894 >            public void realRun() throws InterruptedException {
895 >                LinkedBlockingDeque q = populatedDeque(SIZE);
896 >                for (int i = 0; i < SIZE; ++i) {
897 >                    assertEquals(i, ((Integer)q.takeFirst()).intValue());
898 >                }
899 >                q.takeFirst();
900 >            }};
901 >
902          t.start();
903 <        try {
904 <           Thread.sleep(SHORT_DELAY_MS);
905 <           t.interrupt();
1030 <           t.join();
1031 <        }
1032 <        catch (InterruptedException ie) {
1033 <            unexpectedException();
1034 <        }
903 >        Thread.sleep(SHORT_DELAY_MS);
904 >        t.interrupt();
905 >        t.join();
906      }
907  
908  
909      /**
910       * timed pollFirst with zero timeout succeeds when non-empty, else times out
911       */
912 <    public void testTimedPollFirst0() {
913 <        try {
914 <            LinkedBlockingDeque q = populatedDeque(SIZE);
915 <            for (int i = 0; i < SIZE; ++i) {
916 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
917 <            }
1047 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1048 <        } catch (InterruptedException e){
1049 <            unexpectedException();
1050 <        }
912 >    public void testTimedPollFirst0() throws InterruptedException {
913 >        LinkedBlockingDeque q = populatedDeque(SIZE);
914 >        for (int i = 0; i < SIZE; ++i) {
915 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
916 >        }
917 >        assertNull(q.pollFirst(0, MILLISECONDS));
918      }
919  
920      /**
921       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
922       */
923 <    public void testTimedPollFirst() {
924 <        try {
925 <            LinkedBlockingDeque q = populatedDeque(SIZE);
926 <            for (int i = 0; i < SIZE; ++i) {
927 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
928 <            }
1062 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1063 <        } catch (InterruptedException e){
1064 <            unexpectedException();
1065 <        }
923 >    public void testTimedPollFirst() throws InterruptedException {
924 >        LinkedBlockingDeque q = populatedDeque(SIZE);
925 >        for (int i = 0; i < SIZE; ++i) {
926 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
927 >        }
928 >        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
929      }
930  
931      /**
932       * Interrupted timed pollFirst throws InterruptedException instead of
933       * returning timeout status
934       */
935 <    public void testInterruptedTimedPollFirst() {
936 <        Thread t = new Thread(new Runnable() {
937 <                public void run() {
938 <                    try {
939 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
940 <                        for (int i = 0; i < SIZE; ++i) {
941 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
942 <                        }
943 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
944 <                    } catch (InterruptedException success){
945 <                    }
946 <                }});
935 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
936 >        Thread t = new Thread(new CheckedRunnable() {
937 >            public void realRun() throws InterruptedException {
938 >                LinkedBlockingDeque q = populatedDeque(SIZE);
939 >                for (int i = 0; i < SIZE; ++i) {
940 >                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
941 >                }
942 >                try {
943 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
944 >                    shouldThrow();
945 >                } catch (InterruptedException success) {}
946 >            }});
947 >
948          t.start();
949 <        try {
950 <           Thread.sleep(SHORT_DELAY_MS);
951 <           t.interrupt();
1088 <           t.join();
1089 <        }
1090 <        catch (InterruptedException ie) {
1091 <            unexpectedException();
1092 <        }
949 >        Thread.sleep(SHORT_DELAY_MS);
950 >        t.interrupt();
951 >        t.join();
952      }
953  
954      /**
955       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
956       *  on interruption throws
957       */
958 <    public void testTimedPollFirstWithOfferFirst() {
958 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
959          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
960 <        Thread t = new Thread(new Runnable() {
961 <                public void run() {
962 <                    try {
963 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
964 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
965 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
966 <                        threadShouldThrow();
967 <                    } catch (InterruptedException success) { }
968 <                }
969 <            });
970 <        try {
971 <            t.start();
1113 <            Thread.sleep(SMALL_DELAY_MS);
1114 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1115 <            t.interrupt();
1116 <            t.join();
1117 <        } catch (Exception e){
1118 <            unexpectedException();
1119 <        }
960 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
961 >            public void realRun() throws InterruptedException {
962 >                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
963 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
964 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
965 >            }};
966 >
967 >        t.start();
968 >        Thread.sleep(SMALL_DELAY_MS);
969 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
970 >        t.interrupt();
971 >        t.join();
972      }
973  
974      /**
975       * putLast(null) throws NPE
976       */
977 <     public void testPutLastNull() {
978 <        try {
977 >     public void testPutLastNull() throws InterruptedException {
978 >        try {
979              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
980              q.putLast(null);
981              shouldThrow();
982 <        }
1131 <        catch (NullPointerException success){
1132 <        }
1133 <        catch (InterruptedException ie) {
1134 <            unexpectedException();
1135 <        }
982 >        } catch (NullPointerException success) {}
983       }
984  
985      /**
986       * all elements successfully putLast are contained
987       */
988 <     public void testPutLast() {
989 <         try {
990 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
991 <             for (int i = 0; i < SIZE; ++i) {
992 <                 Integer I = new Integer(i);
993 <                 q.putLast(I);
1147 <                 assertTrue(q.contains(I));
1148 <             }
1149 <             assertEquals(0, q.remainingCapacity());
988 >     public void testPutLast() throws InterruptedException {
989 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
990 >         for (int i = 0; i < SIZE; ++i) {
991 >             Integer I = new Integer(i);
992 >             q.putLast(I);
993 >             assertTrue(q.contains(I));
994           }
995 <        catch (InterruptedException ie) {
1152 <            unexpectedException();
1153 <        }
995 >         assertEquals(0, q.remainingCapacity());
996      }
997  
998      /**
999       * putLast blocks interruptibly if full
1000       */
1001 <    public void testBlockingPutLast() {
1002 <        Thread t = new Thread(new Runnable() {
1003 <                public void run() {
1004 <                    int added = 0;
1005 <                    try {
1006 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1007 <                        for (int i = 0; i < SIZE; ++i) {
1008 <                            q.putLast(new Integer(i));
1009 <                            ++added;
1168 <                        }
1169 <                        q.putLast(new Integer(SIZE));
1170 <                        threadShouldThrow();
1171 <                    } catch (InterruptedException ie){
1172 <                        threadAssertEquals(added, SIZE);
1001 >    public void testBlockingPutLast() throws InterruptedException {
1002 >        Thread t = new Thread(new CheckedRunnable() {
1003 >            public void realRun() {
1004 >                int added = 0;
1005 >                try {
1006 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1007 >                    for (int i = 0; i < SIZE; ++i) {
1008 >                        q.putLast(new Integer(i));
1009 >                        ++added;
1010                      }
1011 <                }});
1011 >                    q.putLast(new Integer(SIZE));
1012 >                    threadShouldThrow();
1013 >                } catch (InterruptedException success) {
1014 >                    threadAssertEquals(added, SIZE);
1015 >                }
1016 >            }});
1017 >
1018          t.start();
1019 <        try {
1020 <           Thread.sleep(SHORT_DELAY_MS);
1021 <           t.interrupt();
1179 <           t.join();
1180 <        }
1181 <        catch (InterruptedException ie) {
1182 <            unexpectedException();
1183 <        }
1019 >        Thread.sleep(SHORT_DELAY_MS);
1020 >        t.interrupt();
1021 >        t.join();
1022      }
1023  
1024      /**
1025       * putLast blocks waiting for take when full
1026       */
1027 <    public void testPutLastWithTake() {
1027 >    public void testPutLastWithTake() throws InterruptedException {
1028          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1029 <        Thread t = new Thread(new Runnable() {
1030 <                public void run() {
1031 <                    int added = 0;
1032 <                    try {
1033 <                        q.putLast(new Object());
1034 <                        ++added;
1035 <                        q.putLast(new Object());
1036 <                        ++added;
1037 <                        q.putLast(new Object());
1038 <                        ++added;
1039 <                        q.putLast(new Object());
1040 <                        ++added;
1041 <                        threadShouldThrow();
1042 <                    } catch (InterruptedException e){
1043 <                        threadAssertTrue(added >= 2);
1206 <                    }
1029 >        Thread t = new Thread(new CheckedRunnable() {
1030 >            public void realRun() {
1031 >                int added = 0;
1032 >                try {
1033 >                    q.putLast(new Object());
1034 >                    ++added;
1035 >                    q.putLast(new Object());
1036 >                    ++added;
1037 >                    q.putLast(new Object());
1038 >                    ++added;
1039 >                    q.putLast(new Object());
1040 >                    ++added;
1041 >                    threadShouldThrow();
1042 >                } catch (InterruptedException success) {
1043 >                    threadAssertTrue(added >= 2);
1044                  }
1045 <            });
1046 <        try {
1047 <            t.start();
1048 <            Thread.sleep(SHORT_DELAY_MS);
1049 <            q.take();
1050 <            t.interrupt();
1051 <            t.join();
1215 <        } catch (Exception e){
1216 <            unexpectedException();
1217 <        }
1045 >            }});
1046 >
1047 >        t.start();
1048 >        Thread.sleep(SHORT_DELAY_MS);
1049 >        q.take();
1050 >        t.interrupt();
1051 >        t.join();
1052      }
1053  
1054      /**
1055       * timed offerLast times out if full and elements not taken
1056       */
1057 <    public void testTimedOfferLast() {
1057 >    public void testTimedOfferLast() throws InterruptedException {
1058          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1059 <        Thread t = new Thread(new Runnable() {
1060 <                public void run() {
1061 <                    try {
1062 <                        q.putLast(new Object());
1063 <                        q.putLast(new Object());
1064 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1065 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1232 <                        threadShouldThrow();
1233 <                    } catch (InterruptedException success){}
1234 <                }
1235 <            });
1059 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1060 >            public void realRun() throws InterruptedException {
1061 >                q.putLast(new Object());
1062 >                q.putLast(new Object());
1063 >                threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1064 >                q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1065 >            }};
1066  
1067 <        try {
1068 <            t.start();
1069 <            Thread.sleep(SMALL_DELAY_MS);
1070 <            t.interrupt();
1241 <            t.join();
1242 <        } catch (Exception e){
1243 <            unexpectedException();
1244 <        }
1067 >        t.start();
1068 >        Thread.sleep(SMALL_DELAY_MS);
1069 >        t.interrupt();
1070 >        t.join();
1071      }
1072  
1073      /**
1074       * takeLast retrieves elements in FIFO order
1075       */
1076 <    public void testTakeLast() {
1077 <        try {
1078 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1079 <            for (int i = 0; i < SIZE; ++i) {
1080 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1255 <            }
1256 <        } catch (InterruptedException e){
1257 <            unexpectedException();
1258 <        }
1076 >    public void testTakeLast() throws InterruptedException {
1077 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1078 >        for (int i = 0; i < SIZE; ++i) {
1079 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1080 >        }
1081      }
1082  
1083      /**
1084       * takeLast blocks interruptibly when empty
1085       */
1086 <    public void testTakeLastFromEmpty() {
1086 >    public void testTakeLastFromEmpty() throws InterruptedException {
1087          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1088 <        Thread t = new Thread(new Runnable() {
1089 <                public void run() {
1090 <                    try {
1091 <                        q.takeLast();
1092 <                        threadShouldThrow();
1093 <                    } catch (InterruptedException success){ }
1094 <                }
1095 <            });
1096 <        try {
1275 <            t.start();
1276 <            Thread.sleep(SHORT_DELAY_MS);
1277 <            t.interrupt();
1278 <            t.join();
1279 <        } catch (Exception e){
1280 <            unexpectedException();
1281 <        }
1088 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1089 >            public void realRun() throws InterruptedException {
1090 >                q.takeLast();
1091 >            }};
1092 >
1093 >        t.start();
1094 >        Thread.sleep(SHORT_DELAY_MS);
1095 >        t.interrupt();
1096 >        t.join();
1097      }
1098  
1099      /**
1100       * TakeLast removes existing elements until empty, then blocks interruptibly
1101       */
1102 <    public void testBlockingTakeLast() {
1103 <        Thread t = new Thread(new Runnable() {
1104 <                public void run() {
1105 <                    try {
1106 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1107 <                        for (int i = 0; i < SIZE; ++i) {
1108 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1109 <                        }
1110 <                        q.takeLast();
1111 <                        threadShouldThrow();
1297 <                    } catch (InterruptedException success){
1298 <                    }
1299 <                }});
1102 >    public void testBlockingTakeLast() throws InterruptedException {
1103 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1104 >            public void realRun() throws InterruptedException {
1105 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1106 >                for (int i = 0; i < SIZE; ++i) {
1107 >                    assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1108 >                }
1109 >                q.takeLast();
1110 >            }};
1111 >
1112          t.start();
1113 <        try {
1114 <           Thread.sleep(SHORT_DELAY_MS);
1115 <           t.interrupt();
1304 <           t.join();
1305 <        }
1306 <        catch (InterruptedException ie) {
1307 <            unexpectedException();
1308 <        }
1113 >        Thread.sleep(SHORT_DELAY_MS);
1114 >        t.interrupt();
1115 >        t.join();
1116      }
1117  
1118  
1119      /**
1120       * timed pollLast with zero timeout succeeds when non-empty, else times out
1121       */
1122 <    public void testTimedPollLast0() {
1123 <        try {
1124 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1125 <            for (int i = 0; i < SIZE; ++i) {
1126 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1127 <            }
1321 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1322 <        } catch (InterruptedException e){
1323 <            unexpectedException();
1324 <        }
1122 >    public void testTimedPollLast0() throws InterruptedException {
1123 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1124 >        for (int i = 0; i < SIZE; ++i) {
1125 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1126 >        }
1127 >        assertNull(q.pollLast(0, MILLISECONDS));
1128      }
1129  
1130      /**
1131       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1132       */
1133 <    public void testTimedPollLast() {
1134 <        try {
1135 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1136 <            for (int i = 0; i < SIZE; ++i) {
1137 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1138 <            }
1336 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1337 <        } catch (InterruptedException e){
1338 <            unexpectedException();
1339 <        }
1133 >    public void testTimedPollLast() throws InterruptedException {
1134 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1135 >        for (int i = 0; i < SIZE; ++i) {
1136 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1137 >        }
1138 >        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1139      }
1140  
1141      /**
1142       * Interrupted timed pollLast throws InterruptedException instead of
1143       * returning timeout status
1144       */
1145 <    public void testInterruptedTimedPollLast() {
1146 <        Thread t = new Thread(new Runnable() {
1147 <                public void run() {
1148 <                    try {
1149 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1150 <                        for (int i = 0; i < SIZE; ++i) {
1151 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1152 <                        }
1153 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1154 <                    } catch (InterruptedException success){
1155 <                    }
1156 <                }});
1145 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1146 >        Thread t = new Thread(new CheckedRunnable() {
1147 >            public void realRun() throws InterruptedException {
1148 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1149 >                for (int i = 0; i < SIZE; ++i) {
1150 >                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1151 >                }
1152 >                try {
1153 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1154 >                    shouldThrow();
1155 >                } catch (InterruptedException success) {}
1156 >            }});
1157 >
1158          t.start();
1159 <        try {
1160 <           Thread.sleep(SHORT_DELAY_MS);
1161 <           t.interrupt();
1362 <           t.join();
1363 <        }
1364 <        catch (InterruptedException ie) {
1365 <            unexpectedException();
1366 <        }
1159 >        Thread.sleep(SHORT_DELAY_MS);
1160 >        t.interrupt();
1161 >        t.join();
1162      }
1163  
1164      /**
1165       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1166       *  on interruption throws
1167       */
1168 <    public void testTimedPollWithOfferLast() {
1168 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1169          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1170 <        Thread t = new Thread(new Runnable() {
1171 <                public void run() {
1172 <                    try {
1173 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1174 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1175 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1176 <                        threadShouldThrow();
1177 <                    } catch (InterruptedException success) { }
1178 <                }
1179 <            });
1180 <        try {
1181 <            t.start();
1182 <            Thread.sleep(SMALL_DELAY_MS);
1183 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1184 <            t.interrupt();
1390 <            t.join();
1391 <        } catch (Exception e){
1392 <            unexpectedException();
1393 <        }
1170 >        Thread t = new Thread(new CheckedRunnable() {
1171 >            public void realRun() throws InterruptedException {
1172 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1173 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1174 >                try {
1175 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1176 >                    shouldThrow();
1177 >                } catch (InterruptedException success) {}
1178 >            }});
1179 >
1180 >        t.start();
1181 >        Thread.sleep(SMALL_DELAY_MS);
1182 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1183 >        t.interrupt();
1184 >        t.join();
1185      }
1186  
1187  
# Line 1406 | Line 1197 | public class LinkedBlockingDequeTest ext
1197          try {
1198              q.element();
1199              shouldThrow();
1200 <        }
1410 <        catch (NoSuchElementException success) {}
1200 >        } catch (NoSuchElementException success) {}
1201      }
1202  
1203      /**
# Line 1505 | Line 1295 | public class LinkedBlockingDequeTest ext
1295      /**
1296       * toArray contains all elements
1297       */
1298 <    public void testToArray() {
1298 >    public void testToArray() throws InterruptedException{
1299          LinkedBlockingDeque q = populatedDeque(SIZE);
1300 <        Object[] o = q.toArray();
1301 <        try {
1302 <        for(int i = 0; i < o.length; i++)
1513 <            assertEquals(o[i], q.take());
1514 <        } catch (InterruptedException e){
1515 <            unexpectedException();
1516 <        }
1300 >        Object[] o = q.toArray();
1301 >        for (int i = 0; i < o.length; i++)
1302 >            assertEquals(o[i], q.take());
1303      }
1304  
1305      /**
1306       * toArray(a) contains all elements
1307       */
1308 <    public void testToArray2() {
1308 >    public void testToArray2() throws InterruptedException {
1309          LinkedBlockingDeque q = populatedDeque(SIZE);
1310 <        Integer[] ints = new Integer[SIZE];
1311 <        ints = (Integer[])q.toArray(ints);
1312 <        try {
1313 <            for(int i = 0; i < ints.length; i++)
1528 <                assertEquals(ints[i], q.take());
1529 <        } catch (InterruptedException e){
1530 <            unexpectedException();
1531 <        }
1310 >        Integer[] ints = new Integer[SIZE];
1311 >        ints = (Integer[])q.toArray(ints);
1312 >        for (int i = 0; i < ints.length; i++)
1313 >            assertEquals(ints[i], q.take());
1314      }
1315  
1316      /**
1317       * toArray(null) throws NPE
1318       */
1319      public void testToArray_BadArg() {
1320 <        try {
1320 >        try {
1321              LinkedBlockingDeque q = populatedDeque(SIZE);
1322 <            Object o[] = q.toArray(null);
1323 <            shouldThrow();
1324 <        } catch(NullPointerException success){}
1322 >            Object o[] = q.toArray(null);
1323 >            shouldThrow();
1324 >        } catch (NullPointerException success) {}
1325      }
1326  
1327      /**
1328       * toArray with incompatible array type throws CCE
1329       */
1330      public void testToArray1_BadArg() {
1331 <        try {
1331 >        try {
1332              LinkedBlockingDeque q = populatedDeque(SIZE);
1333 <            Object o[] = q.toArray(new String[10] );
1334 <            shouldThrow();
1335 <        } catch(ArrayStoreException  success){}
1333 >            Object o[] = q.toArray(new String[10] );
1334 >            shouldThrow();
1335 >        } catch (ArrayStoreException success) {}
1336      }
1337  
1338  
1339      /**
1340       * iterator iterates through all elements
1341       */
1342 <    public void testIterator() {
1342 >    public void testIterator() throws InterruptedException {
1343          LinkedBlockingDeque q = populatedDeque(SIZE);
1344 <        Iterator it = q.iterator();
1345 <        try {
1346 <            while(it.hasNext()){
1347 <                assertEquals(it.next(), q.take());
1566 <            }
1567 <        } catch (InterruptedException e){
1568 <            unexpectedException();
1569 <        }
1344 >        Iterator it = q.iterator();
1345 >        while (it.hasNext()) {
1346 >            assertEquals(it.next(), q.take());
1347 >        }
1348      }
1349  
1350      /**
# Line 1614 | Line 1392 | public class LinkedBlockingDequeTest ext
1392          q.add(one);
1393          q.add(two);
1394          q.add(three);
1395 <        try {
1396 <            for (Iterator it = q.iterator(); it.hasNext();) {
1397 <                q.remove();
1620 <                it.next();
1621 <            }
1622 <        }
1623 <        catch (ConcurrentModificationException e) {
1624 <            unexpectedException();
1395 >        for (Iterator it = q.iterator(); it.hasNext();) {
1396 >            q.remove();
1397 >            it.next();
1398          }
1399          assertEquals(0, q.size());
1400      }
# Line 1633 | Line 1406 | public class LinkedBlockingDequeTest ext
1406      public void testDescendingIterator() {
1407          LinkedBlockingDeque q = populatedDeque(SIZE);
1408          int i = 0;
1409 <        Iterator it = q.descendingIterator();
1410 <        while(it.hasNext()) {
1409 >        Iterator it = q.descendingIterator();
1410 >        while (it.hasNext()) {
1411              assertTrue(q.contains(it.next()));
1412              ++i;
1413          }
# Line 1642 | Line 1415 | public class LinkedBlockingDequeTest ext
1415          assertFalse(it.hasNext());
1416          try {
1417              it.next();
1418 <        } catch(NoSuchElementException success) {
1419 <        }
1418 >            shouldThrow();
1419 >        } catch (NoSuchElementException success) {}
1420      }
1421  
1422      /**
# Line 1711 | Line 1484 | public class LinkedBlockingDequeTest ext
1484          q.add(one);
1485          q.add(two);
1486          ExecutorService executor = Executors.newFixedThreadPool(2);
1487 <        executor.execute(new Runnable() {
1488 <            public void run() {
1487 >        executor.execute(new CheckedRunnable() {
1488 >            public void realRun() throws InterruptedException {
1489                  threadAssertFalse(q.offer(three));
1490 <                try {
1491 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1492 <                    threadAssertEquals(0, q.remainingCapacity());
1493 <                }
1494 <                catch (InterruptedException e) {
1495 <                    threadUnexpectedException();
1496 <                }
1497 <            }
1498 <        });
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 <        });
1490 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1491 >                threadAssertEquals(0, q.remainingCapacity());
1492 >            }});
1493 >
1494 >        executor.execute(new CheckedRunnable() {
1495 >            public void realRun() throws InterruptedException {
1496 >                Thread.sleep(SMALL_DELAY_MS);
1497 >                threadAssertEquals(one, q.take());
1498 >            }});
1499  
1500          joinPool(executor);
1501      }
# Line 1745 | Line 1506 | public class LinkedBlockingDequeTest ext
1506      public void testPollInExecutor() {
1507          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1508          ExecutorService executor = Executors.newFixedThreadPool(2);
1509 <        executor.execute(new Runnable() {
1510 <            public void run() {
1509 >        executor.execute(new CheckedRunnable() {
1510 >            public void realRun() throws InterruptedException {
1511                  threadAssertNull(q.poll());
1512 <                try {
1513 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1514 <                    threadAssertTrue(q.isEmpty());
1515 <                }
1516 <                catch (InterruptedException e) {
1517 <                    threadUnexpectedException();
1518 <                }
1519 <            }
1520 <        });
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 <        });
1512 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1513 >                threadAssertTrue(q.isEmpty());
1514 >            }});
1515 >
1516 >        executor.execute(new CheckedRunnable() {
1517 >            public void realRun() throws InterruptedException {
1518 >                Thread.sleep(SMALL_DELAY_MS);
1519 >                q.put(one);
1520 >            }});
1521  
1522          joinPool(executor);
1523      }
# Line 1776 | Line 1525 | public class LinkedBlockingDequeTest ext
1525      /**
1526       * A deserialized serialized deque has same elements in same order
1527       */
1528 <    public void testSerialization() {
1528 >    public void testSerialization() throws Exception {
1529          LinkedBlockingDeque q = populatedDeque(SIZE);
1530  
1531 <        try {
1532 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1533 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1534 <            out.writeObject(q);
1535 <            out.close();
1536 <
1537 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1538 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1539 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1540 <            assertEquals(q.size(), r.size());
1541 <            while (!q.isEmpty())
1793 <                assertEquals(q.remove(), r.remove());
1794 <        } catch(Exception e){
1795 <            unexpectedException();
1796 <        }
1531 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1532 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1533 >        out.writeObject(q);
1534 >        out.close();
1535 >
1536 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1537 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1538 >        LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1539 >        assertEquals(q.size(), r.size());
1540 >        while (!q.isEmpty())
1541 >            assertEquals(q.remove(), r.remove());
1542      }
1543  
1544      /**
# Line 1804 | Line 1549 | public class LinkedBlockingDequeTest ext
1549          try {
1550              q.drainTo(null);
1551              shouldThrow();
1552 <        } catch(NullPointerException success) {
1808 <        }
1552 >        } catch (NullPointerException success) {}
1553      }
1554  
1555      /**
# Line 1816 | Line 1560 | public class LinkedBlockingDequeTest ext
1560          try {
1561              q.drainTo(q);
1562              shouldThrow();
1563 <        } catch(IllegalArgumentException success) {
1820 <        }
1563 >        } catch (IllegalArgumentException success) {}
1564      }
1565  
1566      /**
# Line 1847 | Line 1590 | public class LinkedBlockingDequeTest ext
1590      /**
1591       * drainTo empties full deque, unblocking a waiting put.
1592       */
1593 <    public void testDrainToWithActivePut() {
1593 >    public void testDrainToWithActivePut() throws InterruptedException {
1594          final LinkedBlockingDeque q = populatedDeque(SIZE);
1595 <        Thread t = new Thread(new Runnable() {
1596 <                public void run() {
1597 <                    try {
1598 <                        q.put(new Integer(SIZE+1));
1599 <                    } catch (InterruptedException ie){
1600 <                        threadUnexpectedException();
1601 <                    }
1602 <                }
1603 <            });
1604 <        try {
1605 <            t.start();
1606 <            ArrayList l = new ArrayList();
1607 <            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 <        }
1595 >        Thread t = new Thread(new CheckedRunnable() {
1596 >            public void realRun() throws InterruptedException {
1597 >                q.put(new Integer(SIZE+1));
1598 >            }});
1599 >
1600 >        t.start();
1601 >        ArrayList l = new ArrayList();
1602 >        q.drainTo(l);
1603 >        assertTrue(l.size() >= SIZE);
1604 >        for (int i = 0; i < SIZE; ++i)
1605 >            assertEquals(l.get(i), new Integer(i));
1606 >        t.join();
1607 >        assertTrue(q.size() + l.size() >= SIZE);
1608      }
1609  
1610      /**
# Line 1880 | Line 1615 | public class LinkedBlockingDequeTest ext
1615          try {
1616              q.drainTo(null, 0);
1617              shouldThrow();
1618 <        } catch(NullPointerException success) {
1884 <        }
1618 >        } catch (NullPointerException success) {}
1619      }
1620  
1621      /**
# Line 1892 | Line 1626 | public class LinkedBlockingDequeTest ext
1626          try {
1627              q.drainTo(q, 0);
1628              shouldThrow();
1629 <        } catch(IllegalArgumentException success) {
1896 <        }
1629 >        } catch (IllegalArgumentException success) {}
1630      }
1631  
1632      /**
# Line 1902 | Line 1635 | public class LinkedBlockingDequeTest ext
1635      public void testDrainToN() {
1636          LinkedBlockingDeque q = new LinkedBlockingDeque();
1637          for (int i = 0; i < SIZE + 2; ++i) {
1638 <            for(int j = 0; j < SIZE; j++)
1638 >            for (int j = 0; j < SIZE; j++)
1639                  assertTrue(q.offer(new Integer(j)));
1640              ArrayList l = new ArrayList();
1641              q.drainTo(l, i);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines