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.2 by dl, Wed Sep 14 23:50:31 2005 UTC vs.
Revision 1.8 by jsr166, Sat Nov 21 02:33:20 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) {
75 <        }  
74 >        } catch (NullPointerException success) {
75 >        }
76      }
77  
78      /**
79 <     * OfferFirst succeeds
79 >     * OfferFirst succeeds
80       */
81      public void testOfferFirst() {
82          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 84 | Line 85 | public class LinkedBlockingDequeTest ext
85      }
86  
87      /**
88 <     * OfferLast succeeds
88 >     * OfferLast succeeds
89       */
90      public void testOfferLast() {
91          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 100 | Line 101 | public class LinkedBlockingDequeTest ext
101          for (int i = 0; i < SIZE; ++i) {
102              assertEquals(i, ((Integer)q.pollFirst()).intValue());
103          }
104 <        assertNull(q.pollFirst());
104 >        assertNull(q.pollFirst());
105      }
106  
107      /**
# Line 111 | Line 112 | public class LinkedBlockingDequeTest ext
112          for (int i = SIZE-1; i >= 0; --i) {
113              assertEquals(i, ((Integer)q.pollLast()).intValue());
114          }
115 <        assertNull(q.pollLast());
115 >        assertNull(q.pollLast());
116      }
117  
118      /**
# Line 125 | Line 126 | public class LinkedBlockingDequeTest ext
126              assertTrue(q.peekFirst() == null ||
127                         i != ((Integer)q.peekFirst()).intValue());
128          }
129 <        assertNull(q.peekFirst());
129 >        assertNull(q.peekFirst());
130      }
131  
132      /**
# Line 139 | Line 140 | public class LinkedBlockingDequeTest ext
140              assertTrue(q.peek() == null ||
141                         i != ((Integer)q.peek()).intValue());
142          }
143 <        assertNull(q.peek());
143 >        assertNull(q.peek());
144      }
145  
146      /**
# Line 153 | Line 154 | public class LinkedBlockingDequeTest ext
154              assertTrue(q.peekLast() == null ||
155                         i != ((Integer)q.peekLast()).intValue());
156          }
157 <        assertNull(q.peekLast());
157 >        assertNull(q.peekLast());
158      }
159  
160      /**
# Line 186 | Line 187 | public class LinkedBlockingDequeTest ext
187              shouldThrow();
188          }
189          catch (NoSuchElementException success) {}
190 <        assertNull(q.peekLast());
190 >        assertNull(q.peekLast());
191      }
192  
193      /**
# Line 200 | Line 201 | public class LinkedBlockingDequeTest ext
201          try {
202              q.removeFirst();
203              shouldThrow();
204 <        } catch (NoSuchElementException success){
205 <        }  
204 >        } catch (NoSuchElementException success) {
205 >        }
206      }
207  
208      /**
# Line 215 | Line 216 | public class LinkedBlockingDequeTest ext
216          try {
217              q.remove();
218              shouldThrow();
219 <        } catch (NoSuchElementException success){
220 <        }  
219 >        } catch (NoSuchElementException success) {
220 >        }
221      }
222  
223      /**
# Line 255 | Line 256 | public class LinkedBlockingDequeTest ext
256      public void testAddFirst() {
257          LinkedBlockingDeque q = populatedDeque(3);
258          q.pollLast();
259 <        q.addFirst(four);
260 <        assertEquals(four,q.peekFirst());
261 <    }  
259 >        q.addFirst(four);
260 >        assertEquals(four,q.peekFirst());
261 >    }
262  
263      /**
264       * peekLast returns element inserted with addLast
# Line 265 | Line 266 | public class LinkedBlockingDequeTest ext
266      public void testAddLast() {
267          LinkedBlockingDeque q = populatedDeque(3);
268          q.pollLast();
269 <        q.addLast(four);
270 <        assertEquals(four,q.peekLast());
271 <    }  
269 >        q.addLast(four);
270 >        assertEquals(four,q.peekLast());
271 >    }
272  
273  
274      /**
# Line 378 | Line 379 | public class LinkedBlockingDequeTest ext
379       * offer(null) throws NPE
380       */
381      public void testOfferNull() {
382 <        try {
382 >        try {
383              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
384              q.offer(null);
385              shouldThrow();
386 <        } catch (NullPointerException success) { }  
386 >        } catch (NullPointerException success) { }
387      }
388  
389      /**
390       * add(null) throws NPE
391       */
392      public void testAddNull() {
393 <        try {
393 >        try {
394              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
395              q.add(null);
396              shouldThrow();
397 <        } catch (NullPointerException success) { }  
397 >        } catch (NullPointerException success) { }
398      }
399  
400      /**
401       * push(null) throws NPE
402       */
403      public void testPushNull() {
404 <        try {
404 >        try {
405              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
406              q.push(null);
407              shouldThrow();
408 <        } catch (NullPointerException success) { }  
408 >        } catch (NullPointerException success) { }
409      }
410  
411      /**
412       * push succeeds if not full; throws ISE if full
413       */
414      public void testPush() {
415 <        try {
415 >        try {
416              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
417              for (int i = 0; i < SIZE; ++i) {
418                  Integer I = new Integer(i);
# Line 420 | Line 421 | public class LinkedBlockingDequeTest ext
421              }
422              assertEquals(0, q.remainingCapacity());
423              q.push(new Integer(SIZE));
424 <        } catch (IllegalStateException success){
425 <        }  
424 >        } catch (IllegalStateException success) {
425 >        }
426      }
427  
428      /**
# Line 430 | Line 431 | public class LinkedBlockingDequeTest ext
431      public void testPushWithPeek() {
432          LinkedBlockingDeque q = populatedDeque(3);
433          q.pollLast();
434 <        q.push(four);
435 <        assertEquals(four,q.peekFirst());
436 <    }  
434 >        q.push(four);
435 >        assertEquals(four,q.peekFirst());
436 >    }
437  
438  
439      /**
# Line 446 | Line 447 | public class LinkedBlockingDequeTest ext
447          try {
448              q.pop();
449              shouldThrow();
450 <        } catch (NoSuchElementException success){
451 <        }  
450 >        } catch (NoSuchElementException success) {
451 >        }
452      }
453  
454  
# Line 464 | Line 465 | public class LinkedBlockingDequeTest ext
465       * add succeeds if not full; throws ISE if full
466       */
467      public void testAdd() {
468 <        try {
468 >        try {
469              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
470              for (int i = 0; i < SIZE; ++i) {
471                  assertTrue(q.add(new Integer(i)));
472              }
473              assertEquals(0, q.remainingCapacity());
474              q.add(new Integer(SIZE));
475 <        } catch (IllegalStateException success){
476 <        }  
475 >        } catch (IllegalStateException success) {
476 >        }
477      }
478  
479      /**
# Line 563 | Line 564 | public class LinkedBlockingDequeTest ext
564       * put(null) throws NPE
565       */
566       public void testPutNull() {
567 <        try {
567 >        try {
568              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
569              q.put(null);
570              shouldThrow();
571 <        }
572 <        catch (NullPointerException success){
573 <        }  
571 >        }
572 >        catch (NullPointerException success) {
573 >        }
574          catch (InterruptedException ie) {
575 <            unexpectedException();
575 >            unexpectedException();
576          }
577       }
578  
# Line 589 | Line 590 | public class LinkedBlockingDequeTest ext
590               assertEquals(0, q.remainingCapacity());
591           }
592          catch (InterruptedException ie) {
593 <            unexpectedException();
593 >            unexpectedException();
594          }
595      }
596  
# Line 608 | Line 609 | public class LinkedBlockingDequeTest ext
609                          }
610                          q.put(new Integer(SIZE));
611                          threadShouldThrow();
612 <                    } catch (InterruptedException ie){
612 >                    } catch (InterruptedException ie) {
613                          threadAssertEquals(added, SIZE);
614 <                    }  
614 >                    }
615                  }});
616          t.start();
617 <        try {
618 <           Thread.sleep(SHORT_DELAY_MS);
617 >        try {
618 >           Thread.sleep(SHORT_DELAY_MS);
619             t.interrupt();
620             t.join();
621          }
622          catch (InterruptedException ie) {
623 <            unexpectedException();
623 >            unexpectedException();
624          }
625      }
626  
# Line 640 | Line 641 | public class LinkedBlockingDequeTest ext
641                          ++added;
642                          q.put(new Object());
643                          ++added;
644 <                        threadShouldThrow();
645 <                    } catch (InterruptedException e){
644 >                        threadShouldThrow();
645 >                    } catch (InterruptedException e) {
646                          threadAssertTrue(added >= 2);
647                      }
648                  }
# Line 652 | Line 653 | public class LinkedBlockingDequeTest ext
653              q.take();
654              t.interrupt();
655              t.join();
656 <        } catch (Exception e){
656 >        } catch (Exception e) {
657              unexpectedException();
658          }
659      }
# Line 667 | Line 668 | public class LinkedBlockingDequeTest ext
668                      try {
669                          q.put(new Object());
670                          q.put(new Object());
671 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
672 <                        q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
673 <                        threadShouldThrow();
674 <                    } catch (InterruptedException success){}
671 >                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
672 >                        q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
673 >                        threadShouldThrow();
674 >                    } catch (InterruptedException success) {}
675                  }
676              });
677 <        
677 >
678          try {
679              t.start();
680              Thread.sleep(SMALL_DELAY_MS);
681              t.interrupt();
682              t.join();
683 <        } catch (Exception e){
683 >        } catch (Exception e) {
684              unexpectedException();
685          }
686      }
# Line 688 | Line 689 | public class LinkedBlockingDequeTest ext
689       * take retrieves elements in FIFO order
690       */
691      public void testTake() {
692 <        try {
692 >        try {
693              LinkedBlockingDeque q = populatedDeque(SIZE);
694              for (int i = 0; i < SIZE; ++i) {
695                  assertEquals(i, ((Integer)q.take()).intValue());
696              }
697 <        } catch (InterruptedException e){
698 <            unexpectedException();
699 <        }  
697 >        } catch (InterruptedException e) {
698 >            unexpectedException();
699 >        }
700      }
701  
702      /**
# Line 707 | Line 708 | public class LinkedBlockingDequeTest ext
708                  public void run() {
709                      try {
710                          q.take();
711 <                        threadShouldThrow();
712 <                    } catch (InterruptedException success){ }                
711 >                        threadShouldThrow();
712 >                    } catch (InterruptedException success) { }
713                  }
714              });
715          try {
# Line 716 | Line 717 | public class LinkedBlockingDequeTest ext
717              Thread.sleep(SHORT_DELAY_MS);
718              t.interrupt();
719              t.join();
720 <        } catch (Exception e){
720 >        } catch (Exception e) {
721              unexpectedException();
722          }
723      }
# Line 734 | Line 735 | public class LinkedBlockingDequeTest ext
735                          }
736                          q.take();
737                          threadShouldThrow();
738 <                    } catch (InterruptedException success){
739 <                    }  
738 >                    } catch (InterruptedException success) {
739 >                    }
740                  }});
741          t.start();
742 <        try {
743 <           Thread.sleep(SHORT_DELAY_MS);
742 >        try {
743 >           Thread.sleep(SHORT_DELAY_MS);
744             t.interrupt();
745             t.join();
746          }
747          catch (InterruptedException ie) {
748 <            unexpectedException();
748 >            unexpectedException();
749          }
750      }
751  
# Line 757 | Line 758 | public class LinkedBlockingDequeTest ext
758          for (int i = 0; i < SIZE; ++i) {
759              assertEquals(i, ((Integer)q.poll()).intValue());
760          }
761 <        assertNull(q.poll());
761 >        assertNull(q.poll());
762      }
763  
764      /**
# Line 767 | Line 768 | public class LinkedBlockingDequeTest ext
768          try {
769              LinkedBlockingDeque q = populatedDeque(SIZE);
770              for (int i = 0; i < SIZE; ++i) {
771 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
771 >                assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
772              }
773 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
774 <        } catch (InterruptedException e){
775 <            unexpectedException();
776 <        }  
773 >            assertNull(q.poll(0, MILLISECONDS));
774 >        } catch (InterruptedException e) {
775 >            unexpectedException();
776 >        }
777      }
778  
779      /**
# Line 782 | Line 783 | public class LinkedBlockingDequeTest ext
783          try {
784              LinkedBlockingDeque q = populatedDeque(SIZE);
785              for (int i = 0; i < SIZE; ++i) {
786 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
786 >                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
787              }
788 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
789 <        } catch (InterruptedException e){
790 <            unexpectedException();
791 <        }  
788 >            assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
789 >        } catch (InterruptedException e) {
790 >            unexpectedException();
791 >        }
792      }
793  
794      /**
# Line 800 | Line 801 | public class LinkedBlockingDequeTest ext
801                      try {
802                          LinkedBlockingDeque q = populatedDeque(SIZE);
803                          for (int i = 0; i < SIZE; ++i) {
804 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
804 >                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
805                          }
806 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
807 <                    } catch (InterruptedException success){
808 <                    }  
806 >                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
807 >                    } catch (InterruptedException success) {
808 >                    }
809                  }});
810          t.start();
811 <        try {
812 <           Thread.sleep(SHORT_DELAY_MS);
811 >        try {
812 >           Thread.sleep(SHORT_DELAY_MS);
813             t.interrupt();
814             t.join();
815          }
816          catch (InterruptedException ie) {
817 <            unexpectedException();
817 >            unexpectedException();
818          }
819      }
820  
# Line 826 | Line 827 | public class LinkedBlockingDequeTest ext
827          Thread t = new Thread(new Runnable() {
828                  public void run() {
829                      try {
830 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
831 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
832 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
833 <                        threadShouldThrow();
834 <                    } catch (InterruptedException success) { }                
830 >                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
831 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
832 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
833 >                        threadShouldThrow();
834 >                    } catch (InterruptedException success) { }
835                  }
836              });
837          try {
838              t.start();
839              Thread.sleep(SMALL_DELAY_MS);
840 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
840 >            assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
841              t.interrupt();
842              t.join();
843 <        } catch (Exception e){
843 >        } catch (Exception e) {
844              unexpectedException();
845          }
846 <    }  
846 >    }
847  
848  
849      /**
850       * putFirst(null) throws NPE
851       */
852       public void testPutFirstNull() {
853 <        try {
853 >        try {
854              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
855              q.putFirst(null);
856              shouldThrow();
857 <        }
858 <        catch (NullPointerException success){
859 <        }  
857 >        }
858 >        catch (NullPointerException success) {
859 >        }
860          catch (InterruptedException ie) {
861 <            unexpectedException();
861 >            unexpectedException();
862          }
863       }
864  
# Line 875 | Line 876 | public class LinkedBlockingDequeTest ext
876               assertEquals(0, q.remainingCapacity());
877           }
878          catch (InterruptedException ie) {
879 <            unexpectedException();
879 >            unexpectedException();
880          }
881      }
882  
# Line 894 | Line 895 | public class LinkedBlockingDequeTest ext
895                          }
896                          q.putFirst(new Integer(SIZE));
897                          threadShouldThrow();
898 <                    } catch (InterruptedException ie){
898 >                    } catch (InterruptedException ie) {
899                          threadAssertEquals(added, SIZE);
900 <                    }  
900 >                    }
901                  }});
902          t.start();
903 <        try {
904 <           Thread.sleep(SHORT_DELAY_MS);
903 >        try {
904 >           Thread.sleep(SHORT_DELAY_MS);
905             t.interrupt();
906             t.join();
907          }
908          catch (InterruptedException ie) {
909 <            unexpectedException();
909 >            unexpectedException();
910          }
911      }
912  
# Line 926 | Line 927 | public class LinkedBlockingDequeTest ext
927                          ++added;
928                          q.putFirst(new Object());
929                          ++added;
930 <                        threadShouldThrow();
931 <                    } catch (InterruptedException e){
930 >                        threadShouldThrow();
931 >                    } catch (InterruptedException e) {
932                          threadAssertTrue(added >= 2);
933                      }
934                  }
# Line 938 | Line 939 | public class LinkedBlockingDequeTest ext
939              q.take();
940              t.interrupt();
941              t.join();
942 <        } catch (Exception e){
942 >        } catch (Exception e) {
943              unexpectedException();
944          }
945      }
# Line 953 | Line 954 | public class LinkedBlockingDequeTest ext
954                      try {
955                          q.putFirst(new Object());
956                          q.putFirst(new Object());
957 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
958 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
959 <                        threadShouldThrow();
960 <                    } catch (InterruptedException success){}
957 >                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
958 >                        q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
959 >                        threadShouldThrow();
960 >                    } catch (InterruptedException success) {}
961                  }
962              });
963 <        
963 >
964          try {
965              t.start();
966              Thread.sleep(SMALL_DELAY_MS);
967              t.interrupt();
968              t.join();
969 <        } catch (Exception e){
969 >        } catch (Exception e) {
970              unexpectedException();
971          }
972      }
# Line 974 | Line 975 | public class LinkedBlockingDequeTest ext
975       * take retrieves elements in FIFO order
976       */
977      public void testTakeFirst() {
978 <        try {
978 >        try {
979              LinkedBlockingDeque q = populatedDeque(SIZE);
980              for (int i = 0; i < SIZE; ++i) {
981                  assertEquals(i, ((Integer)q.takeFirst()).intValue());
982              }
983 <        } catch (InterruptedException e){
984 <            unexpectedException();
985 <        }  
983 >        } catch (InterruptedException e) {
984 >            unexpectedException();
985 >        }
986      }
987  
988      /**
# Line 993 | Line 994 | public class LinkedBlockingDequeTest ext
994                  public void run() {
995                      try {
996                          q.takeFirst();
997 <                        threadShouldThrow();
998 <                    } catch (InterruptedException success){ }                
997 >                        threadShouldThrow();
998 >                    } catch (InterruptedException success) { }
999                  }
1000              });
1001          try {
# Line 1002 | Line 1003 | public class LinkedBlockingDequeTest ext
1003              Thread.sleep(SHORT_DELAY_MS);
1004              t.interrupt();
1005              t.join();
1006 <        } catch (Exception e){
1006 >        } catch (Exception e) {
1007              unexpectedException();
1008          }
1009      }
# Line 1020 | Line 1021 | public class LinkedBlockingDequeTest ext
1021                          }
1022                          q.takeFirst();
1023                          threadShouldThrow();
1024 <                    } catch (InterruptedException success){
1025 <                    }  
1024 >                    } catch (InterruptedException success) {
1025 >                    }
1026                  }});
1027          t.start();
1028 <        try {
1029 <           Thread.sleep(SHORT_DELAY_MS);
1028 >        try {
1029 >           Thread.sleep(SHORT_DELAY_MS);
1030             t.interrupt();
1031             t.join();
1032          }
1033          catch (InterruptedException ie) {
1034 <            unexpectedException();
1034 >            unexpectedException();
1035          }
1036      }
1037  
# Line 1042 | Line 1043 | public class LinkedBlockingDequeTest ext
1043          try {
1044              LinkedBlockingDeque q = populatedDeque(SIZE);
1045              for (int i = 0; i < SIZE; ++i) {
1046 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
1046 >                assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
1047              }
1048 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1049 <        } catch (InterruptedException e){
1050 <            unexpectedException();
1051 <        }  
1048 >            assertNull(q.pollFirst(0, MILLISECONDS));
1049 >        } catch (InterruptedException e) {
1050 >            unexpectedException();
1051 >        }
1052      }
1053  
1054      /**
# Line 1057 | Line 1058 | public class LinkedBlockingDequeTest ext
1058          try {
1059              LinkedBlockingDeque q = populatedDeque(SIZE);
1060              for (int i = 0; i < SIZE; ++i) {
1061 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1061 >                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1062              }
1063 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1064 <        } catch (InterruptedException e){
1065 <            unexpectedException();
1066 <        }  
1063 >            assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1064 >        } catch (InterruptedException e) {
1065 >            unexpectedException();
1066 >        }
1067      }
1068  
1069      /**
# Line 1075 | Line 1076 | public class LinkedBlockingDequeTest ext
1076                      try {
1077                          LinkedBlockingDeque q = populatedDeque(SIZE);
1078                          for (int i = 0; i < SIZE; ++i) {
1079 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1079 >                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1080                          }
1081 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1082 <                    } catch (InterruptedException success){
1083 <                    }  
1081 >                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1082 >                    } catch (InterruptedException success) {
1083 >                    }
1084                  }});
1085          t.start();
1086 <        try {
1087 <           Thread.sleep(SHORT_DELAY_MS);
1086 >        try {
1087 >           Thread.sleep(SHORT_DELAY_MS);
1088             t.interrupt();
1089             t.join();
1090          }
1091          catch (InterruptedException ie) {
1092 <            unexpectedException();
1092 >            unexpectedException();
1093          }
1094      }
1095  
# Line 1101 | Line 1102 | public class LinkedBlockingDequeTest ext
1102          Thread t = new Thread(new Runnable() {
1103                  public void run() {
1104                      try {
1105 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1106 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1107 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1108 <                        threadShouldThrow();
1109 <                    } catch (InterruptedException success) { }                
1105 >                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1106 >                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1107 >                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1108 >                        threadShouldThrow();
1109 >                    } catch (InterruptedException success) { }
1110                  }
1111              });
1112          try {
1113              t.start();
1114              Thread.sleep(SMALL_DELAY_MS);
1115 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1115 >            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
1116              t.interrupt();
1117              t.join();
1118 <        } catch (Exception e){
1118 >        } catch (Exception e) {
1119              unexpectedException();
1120          }
1121 <    }  
1121 >    }
1122  
1123      /**
1124       * putLast(null) throws NPE
1125       */
1126       public void testPutLastNull() {
1127 <        try {
1127 >        try {
1128              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1129              q.putLast(null);
1130              shouldThrow();
1131 <        }
1132 <        catch (NullPointerException success){
1133 <        }  
1131 >        }
1132 >        catch (NullPointerException success) {
1133 >        }
1134          catch (InterruptedException ie) {
1135 <            unexpectedException();
1135 >            unexpectedException();
1136          }
1137       }
1138  
# Line 1149 | Line 1150 | public class LinkedBlockingDequeTest ext
1150               assertEquals(0, q.remainingCapacity());
1151           }
1152          catch (InterruptedException ie) {
1153 <            unexpectedException();
1153 >            unexpectedException();
1154          }
1155      }
1156  
# Line 1168 | Line 1169 | public class LinkedBlockingDequeTest ext
1169                          }
1170                          q.putLast(new Integer(SIZE));
1171                          threadShouldThrow();
1172 <                    } catch (InterruptedException ie){
1172 >                    } catch (InterruptedException ie) {
1173                          threadAssertEquals(added, SIZE);
1174 <                    }  
1174 >                    }
1175                  }});
1176          t.start();
1177 <        try {
1178 <           Thread.sleep(SHORT_DELAY_MS);
1177 >        try {
1178 >           Thread.sleep(SHORT_DELAY_MS);
1179             t.interrupt();
1180             t.join();
1181          }
1182          catch (InterruptedException ie) {
1183 <            unexpectedException();
1183 >            unexpectedException();
1184          }
1185      }
1186  
# Line 1200 | Line 1201 | public class LinkedBlockingDequeTest ext
1201                          ++added;
1202                          q.putLast(new Object());
1203                          ++added;
1204 <                        threadShouldThrow();
1205 <                    } catch (InterruptedException e){
1204 >                        threadShouldThrow();
1205 >                    } catch (InterruptedException e) {
1206                          threadAssertTrue(added >= 2);
1207                      }
1208                  }
# Line 1212 | Line 1213 | public class LinkedBlockingDequeTest ext
1213              q.take();
1214              t.interrupt();
1215              t.join();
1216 <        } catch (Exception e){
1216 >        } catch (Exception e) {
1217              unexpectedException();
1218          }
1219      }
# Line 1227 | Line 1228 | public class LinkedBlockingDequeTest ext
1228                      try {
1229                          q.putLast(new Object());
1230                          q.putLast(new Object());
1231 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1232 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1233 <                        threadShouldThrow();
1234 <                    } catch (InterruptedException success){}
1231 >                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1232 >                        q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1233 >                        threadShouldThrow();
1234 >                    } catch (InterruptedException success) {}
1235                  }
1236              });
1237 <        
1237 >
1238          try {
1239              t.start();
1240              Thread.sleep(SMALL_DELAY_MS);
1241              t.interrupt();
1242              t.join();
1243 <        } catch (Exception e){
1243 >        } catch (Exception e) {
1244              unexpectedException();
1245          }
1246      }
# Line 1248 | Line 1249 | public class LinkedBlockingDequeTest ext
1249       * takeLast retrieves elements in FIFO order
1250       */
1251      public void testTakeLast() {
1252 <        try {
1252 >        try {
1253              LinkedBlockingDeque q = populatedDeque(SIZE);
1254              for (int i = 0; i < SIZE; ++i) {
1255                  assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1256              }
1257 <        } catch (InterruptedException e){
1258 <            unexpectedException();
1259 <        }  
1257 >        } catch (InterruptedException e) {
1258 >            unexpectedException();
1259 >        }
1260      }
1261  
1262      /**
# Line 1267 | Line 1268 | public class LinkedBlockingDequeTest ext
1268                  public void run() {
1269                      try {
1270                          q.takeLast();
1271 <                        threadShouldThrow();
1272 <                    } catch (InterruptedException success){ }                
1271 >                        threadShouldThrow();
1272 >                    } catch (InterruptedException success) { }
1273                  }
1274              });
1275          try {
# Line 1276 | Line 1277 | public class LinkedBlockingDequeTest ext
1277              Thread.sleep(SHORT_DELAY_MS);
1278              t.interrupt();
1279              t.join();
1280 <        } catch (Exception e){
1280 >        } catch (Exception e) {
1281              unexpectedException();
1282          }
1283      }
# Line 1294 | Line 1295 | public class LinkedBlockingDequeTest ext
1295                          }
1296                          q.takeLast();
1297                          threadShouldThrow();
1298 <                    } catch (InterruptedException success){
1299 <                    }  
1298 >                    } catch (InterruptedException success) {
1299 >                    }
1300                  }});
1301          t.start();
1302 <        try {
1303 <           Thread.sleep(SHORT_DELAY_MS);
1302 >        try {
1303 >           Thread.sleep(SHORT_DELAY_MS);
1304             t.interrupt();
1305             t.join();
1306          }
1307          catch (InterruptedException ie) {
1308 <            unexpectedException();
1308 >            unexpectedException();
1309          }
1310      }
1311  
# Line 1316 | Line 1317 | public class LinkedBlockingDequeTest ext
1317          try {
1318              LinkedBlockingDeque q = populatedDeque(SIZE);
1319              for (int i = 0; i < SIZE; ++i) {
1320 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1320 >                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1321              }
1322 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1323 <        } catch (InterruptedException e){
1324 <            unexpectedException();
1325 <        }  
1322 >            assertNull(q.pollLast(0, MILLISECONDS));
1323 >        } catch (InterruptedException e) {
1324 >            unexpectedException();
1325 >        }
1326      }
1327  
1328      /**
# Line 1331 | Line 1332 | public class LinkedBlockingDequeTest ext
1332          try {
1333              LinkedBlockingDeque q = populatedDeque(SIZE);
1334              for (int i = 0; i < SIZE; ++i) {
1335 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1335 >                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1336              }
1337 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1338 <        } catch (InterruptedException e){
1339 <            unexpectedException();
1340 <        }  
1337 >            assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1338 >        } catch (InterruptedException e) {
1339 >            unexpectedException();
1340 >        }
1341      }
1342  
1343      /**
# Line 1349 | Line 1350 | public class LinkedBlockingDequeTest ext
1350                      try {
1351                          LinkedBlockingDeque q = populatedDeque(SIZE);
1352                          for (int i = 0; i < SIZE; ++i) {
1353 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1353 >                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1354                          }
1355 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1356 <                    } catch (InterruptedException success){
1357 <                    }  
1355 >                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1356 >                    } catch (InterruptedException success) {
1357 >                    }
1358                  }});
1359          t.start();
1360 <        try {
1361 <           Thread.sleep(SHORT_DELAY_MS);
1360 >        try {
1361 >           Thread.sleep(SHORT_DELAY_MS);
1362             t.interrupt();
1363             t.join();
1364          }
1365          catch (InterruptedException ie) {
1366 <            unexpectedException();
1366 >            unexpectedException();
1367          }
1368      }
1369  
# Line 1375 | Line 1376 | public class LinkedBlockingDequeTest ext
1376          Thread t = new Thread(new Runnable() {
1377                  public void run() {
1378                      try {
1379 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1380 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1381 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1382 <                        threadShouldThrow();
1383 <                    } catch (InterruptedException success) { }                
1379 >                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1380 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1381 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1382 >                        threadShouldThrow();
1383 >                    } catch (InterruptedException success) { }
1384                  }
1385              });
1386          try {
1387              t.start();
1388              Thread.sleep(SMALL_DELAY_MS);
1389 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1389 >            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1390              t.interrupt();
1391              t.join();
1392 <        } catch (Exception e){
1392 >        } catch (Exception e) {
1393              unexpectedException();
1394          }
1395 <    }  
1395 >    }
1396  
1397  
1398      /**
# Line 1424 | Line 1425 | public class LinkedBlockingDequeTest ext
1425          }
1426          assertTrue(q.isEmpty());
1427      }
1428 <        
1428 >
1429      /**
1430       * contains(x) reports true when elements added but not yet removed
1431       */
# Line 1507 | Line 1508 | public class LinkedBlockingDequeTest ext
1508       */
1509      public void testToArray() {
1510          LinkedBlockingDeque q = populatedDeque(SIZE);
1511 <        Object[] o = q.toArray();
1512 <        try {
1513 <        for(int i = 0; i < o.length; i++)
1514 <            assertEquals(o[i], q.take());
1515 <        } catch (InterruptedException e){
1516 <            unexpectedException();
1517 <        }    
1511 >        Object[] o = q.toArray();
1512 >        try {
1513 >        for (int i = 0; i < o.length; i++)
1514 >            assertEquals(o[i], q.take());
1515 >        } catch (InterruptedException e) {
1516 >            unexpectedException();
1517 >        }
1518      }
1519  
1520      /**
# Line 1521 | Line 1522 | public class LinkedBlockingDequeTest ext
1522       */
1523      public void testToArray2() {
1524          LinkedBlockingDeque q = populatedDeque(SIZE);
1525 <        Integer[] ints = new Integer[SIZE];
1526 <        ints = (Integer[])q.toArray(ints);
1527 <        try {
1528 <            for(int i = 0; i < ints.length; i++)
1529 <                assertEquals(ints[i], q.take());
1530 <        } catch (InterruptedException e){
1531 <            unexpectedException();
1532 <        }    
1525 >        Integer[] ints = new Integer[SIZE];
1526 >        ints = (Integer[])q.toArray(ints);
1527 >        try {
1528 >            for (int i = 0; i < ints.length; i++)
1529 >                assertEquals(ints[i], q.take());
1530 >        } catch (InterruptedException e) {
1531 >            unexpectedException();
1532 >        }
1533      }
1534  
1535      /**
1536       * toArray(null) throws NPE
1537       */
1538      public void testToArray_BadArg() {
1539 <        try {
1539 >        try {
1540              LinkedBlockingDeque q = populatedDeque(SIZE);
1541 <            Object o[] = q.toArray(null);
1542 <            shouldThrow();
1543 <        } catch(NullPointerException success){}
1541 >            Object o[] = q.toArray(null);
1542 >            shouldThrow();
1543 >        } catch (NullPointerException success) {}
1544      }
1545  
1546      /**
1547       * toArray with incompatible array type throws CCE
1548       */
1549      public void testToArray1_BadArg() {
1550 <        try {
1550 >        try {
1551              LinkedBlockingDeque q = populatedDeque(SIZE);
1552 <            Object o[] = q.toArray(new String[10] );
1553 <            shouldThrow();
1554 <        } catch(ArrayStoreException  success){}
1552 >            Object o[] = q.toArray(new String[10] );
1553 >            shouldThrow();
1554 >        } catch (ArrayStoreException  success) {}
1555      }
1556  
1557 <    
1557 >
1558      /**
1559       * iterator iterates through all elements
1560       */
1561      public void testIterator() {
1562          LinkedBlockingDeque q = populatedDeque(SIZE);
1563 <        Iterator it = q.iterator();
1564 <        try {
1565 <            while(it.hasNext()){
1566 <                assertEquals(it.next(), q.take());
1567 <            }
1568 <        } catch (InterruptedException e){
1569 <            unexpectedException();
1570 <        }    
1563 >        Iterator it = q.iterator();
1564 >        try {
1565 >            while (it.hasNext()) {
1566 >                assertEquals(it.next(), q.take());
1567 >            }
1568 >        } catch (InterruptedException e) {
1569 >            unexpectedException();
1570 >        }
1571      }
1572  
1573      /**
# Line 1581 | Line 1582 | public class LinkedBlockingDequeTest ext
1582          Iterator it = q.iterator();
1583          it.next();
1584          it.remove();
1585 <        
1585 >
1586          it = q.iterator();
1587          assertEquals(it.next(), one);
1588          assertEquals(it.next(), three);
# Line 1633 | Line 1634 | public class LinkedBlockingDequeTest ext
1634      public void testDescendingIterator() {
1635          LinkedBlockingDeque q = populatedDeque(SIZE);
1636          int i = 0;
1637 <        Iterator it = q.descendingIterator();
1638 <        while(it.hasNext()) {
1637 >        Iterator it = q.descendingIterator();
1638 >        while (it.hasNext()) {
1639              assertTrue(q.contains(it.next()));
1640              ++i;
1641          }
# Line 1642 | Line 1643 | public class LinkedBlockingDequeTest ext
1643          assertFalse(it.hasNext());
1644          try {
1645              it.next();
1646 <        } catch(NoSuchElementException success) {
1646 >        } catch (NoSuchElementException success) {
1647          }
1648      }
1649  
# Line 1651 | Line 1652 | public class LinkedBlockingDequeTest ext
1652       */
1653      public void testDescendingIteratorOrdering() {
1654          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1655 <        q.add(new Integer(3));
1656 <        q.add(new Integer(2));
1657 <        q.add(new Integer(1));
1658 <        int k = 0;
1659 <        for (Iterator it = q.descendingIterator(); it.hasNext();) {
1660 <            int i = ((Integer)(it.next())).intValue();
1661 <            assertEquals(++k, i);
1662 <        }
1655 >        for (int iters = 0; iters < 100; ++iters) {
1656 >            q.add(new Integer(3));
1657 >            q.add(new Integer(2));
1658 >            q.add(new Integer(1));
1659 >            int k = 0;
1660 >            for (Iterator it = q.descendingIterator(); it.hasNext();) {
1661 >                int i = ((Integer)(it.next())).intValue();
1662 >                assertEquals(++k, i);
1663 >            }
1664  
1665 <        assertEquals(3, k);
1665 >            assertEquals(3, k);
1666 >            q.remove();
1667 >            q.remove();
1668 >            q.remove();
1669 >        }
1670      }
1671  
1672      /**
# Line 1668 | Line 1674 | public class LinkedBlockingDequeTest ext
1674       */
1675      public void testDescendingIteratorRemove () {
1676          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1677 <        q.add(new Integer(3));
1678 <        q.add(new Integer(2));
1679 <        q.add(new Integer(1));
1680 <        Iterator it = q.descendingIterator();
1681 <        it.next();
1682 <        it.remove();
1683 <        it = q.descendingIterator();
1684 <        assertEquals(it.next(), new Integer(2));
1685 <        assertEquals(it.next(), new Integer(3));
1686 <        assertFalse(it.hasNext());
1677 >        for (int iters = 0; iters < 100; ++iters) {
1678 >            q.add(new Integer(3));
1679 >            q.add(new Integer(2));
1680 >            q.add(new Integer(1));
1681 >            Iterator it = q.descendingIterator();
1682 >            assertEquals(it.next(), new Integer(1));
1683 >            it.remove();
1684 >            assertEquals(it.next(), new Integer(2));
1685 >            it = q.descendingIterator();
1686 >            assertEquals(it.next(), new Integer(2));
1687 >            assertEquals(it.next(), new Integer(3));
1688 >            it.remove();
1689 >            assertFalse(it.hasNext());
1690 >            q.remove();
1691 >        }
1692      }
1693  
1694  
# Line 1690 | Line 1701 | public class LinkedBlockingDequeTest ext
1701          for (int i = 0; i < SIZE; ++i) {
1702              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
1703          }
1704 <    }        
1704 >    }
1705  
1706  
1707      /**
# Line 1705 | Line 1716 | public class LinkedBlockingDequeTest ext
1716              public void run() {
1717                  threadAssertFalse(q.offer(three));
1718                  try {
1719 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1719 >                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1720                      threadAssertEquals(0, q.remainingCapacity());
1721                  }
1722                  catch (InterruptedException e) {
# Line 1725 | Line 1736 | public class LinkedBlockingDequeTest ext
1736                  }
1737              }
1738          });
1739 <        
1739 >
1740          joinPool(executor);
1741      }
1742  
# Line 1739 | Line 1750 | public class LinkedBlockingDequeTest ext
1750              public void run() {
1751                  threadAssertNull(q.poll());
1752                  try {
1753 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1753 >                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1754                      threadAssertTrue(q.isEmpty());
1755                  }
1756                  catch (InterruptedException e) {
# Line 1759 | Line 1770 | public class LinkedBlockingDequeTest ext
1770                  }
1771              }
1772          });
1773 <        
1773 >
1774          joinPool(executor);
1775      }
1776  
# Line 1779 | Line 1790 | public class LinkedBlockingDequeTest ext
1790              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1791              LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1792              assertEquals(q.size(), r.size());
1793 <            while (!q.isEmpty())
1793 >            while (!q.isEmpty())
1794                  assertEquals(q.remove(), r.remove());
1795 <        } catch(Exception e){
1795 >        } catch (Exception e) {
1796              unexpectedException();
1797          }
1798      }
1799  
1800      /**
1801       * drainTo(null) throws NPE
1802 <     */
1802 >     */
1803      public void testDrainToNull() {
1804          LinkedBlockingDeque q = populatedDeque(SIZE);
1805          try {
1806              q.drainTo(null);
1807              shouldThrow();
1808 <        } catch(NullPointerException success) {
1808 >        } catch (NullPointerException success) {
1809          }
1810      }
1811  
1812      /**
1813       * drainTo(this) throws IAE
1814 <     */
1814 >     */
1815      public void testDrainToSelf() {
1816          LinkedBlockingDeque q = populatedDeque(SIZE);
1817          try {
1818              q.drainTo(q);
1819              shouldThrow();
1820 <        } catch(IllegalArgumentException success) {
1820 >        } catch (IllegalArgumentException success) {
1821          }
1822      }
1823  
1824      /**
1825       * drainTo(c) empties deque into another collection c
1826 <     */
1826 >     */
1827      public void testDrainTo() {
1828          LinkedBlockingDeque q = populatedDeque(SIZE);
1829          ArrayList l = new ArrayList();
1830          q.drainTo(l);
1831          assertEquals(q.size(), 0);
1832          assertEquals(l.size(), SIZE);
1833 <        for (int i = 0; i < SIZE; ++i)
1833 >        for (int i = 0; i < SIZE; ++i)
1834              assertEquals(l.get(i), new Integer(i));
1835          q.add(zero);
1836          q.add(one);
# Line 1830 | Line 1841 | public class LinkedBlockingDequeTest ext
1841          q.drainTo(l);
1842          assertEquals(q.size(), 0);
1843          assertEquals(l.size(), 2);
1844 <        for (int i = 0; i < 2; ++i)
1844 >        for (int i = 0; i < 2; ++i)
1845              assertEquals(l.get(i), new Integer(i));
1846      }
1847  
1848      /**
1849       * drainTo empties full deque, unblocking a waiting put.
1850 <     */
1850 >     */
1851      public void testDrainToWithActivePut() {
1852          final LinkedBlockingDeque q = populatedDeque(SIZE);
1853          Thread t = new Thread(new Runnable() {
1854                  public void run() {
1855                      try {
1856                          q.put(new Integer(SIZE+1));
1857 <                    } catch (InterruptedException ie){
1857 >                    } catch (InterruptedException ie) {
1858                          threadUnexpectedException();
1859                      }
1860                  }
# Line 1853 | Line 1864 | public class LinkedBlockingDequeTest ext
1864              ArrayList l = new ArrayList();
1865              q.drainTo(l);
1866              assertTrue(l.size() >= SIZE);
1867 <            for (int i = 0; i < SIZE; ++i)
1867 >            for (int i = 0; i < SIZE; ++i)
1868                  assertEquals(l.get(i), new Integer(i));
1869              t.join();
1870              assertTrue(q.size() + l.size() >= SIZE);
1871 <        } catch(Exception e){
1871 >        } catch (Exception e) {
1872              unexpectedException();
1873          }
1874      }
1875  
1876      /**
1877       * drainTo(null, n) throws NPE
1878 <     */
1878 >     */
1879      public void testDrainToNullN() {
1880          LinkedBlockingDeque q = populatedDeque(SIZE);
1881          try {
1882              q.drainTo(null, 0);
1883              shouldThrow();
1884 <        } catch(NullPointerException success) {
1884 >        } catch (NullPointerException success) {
1885          }
1886      }
1887  
1888      /**
1889       * drainTo(this, n) throws IAE
1890 <     */
1890 >     */
1891      public void testDrainToSelfN() {
1892          LinkedBlockingDeque q = populatedDeque(SIZE);
1893          try {
1894              q.drainTo(q, 0);
1895              shouldThrow();
1896 <        } catch(IllegalArgumentException success) {
1896 >        } catch (IllegalArgumentException success) {
1897          }
1898      }
1899  
1900      /**
1901       * drainTo(c, n) empties first max {n, size} elements of deque into c
1902 <     */
1902 >     */
1903      public void testDrainToN() {
1904          LinkedBlockingDeque q = new LinkedBlockingDeque();
1905          for (int i = 0; i < SIZE + 2; ++i) {
1906 <            for(int j = 0; j < SIZE; j++)
1906 >            for (int j = 0; j < SIZE; j++)
1907                  assertTrue(q.offer(new Integer(j)));
1908              ArrayList l = new ArrayList();
1909              q.drainTo(l, i);
1910              int k = (i < SIZE)? i : SIZE;
1911              assertEquals(l.size(), k);
1912              assertEquals(q.size(), SIZE-k);
1913 <            for (int j = 0; j < k; ++j)
1913 >            for (int j = 0; j < k; ++j)
1914                  assertEquals(l.get(j), new Integer(j));
1915              while (q.poll() != null) ;
1916          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines