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.17 by jsr166, Sun Nov 22 00:17:37 2009 UTC vs.
Revision 1.33 by jsr166, Thu Nov 18 20:21:53 2010 UTC

# Line 11 | Line 11 | import static java.util.concurrent.TimeU
11   import java.io.*;
12  
13   public class LinkedBlockingDequeTest extends JSR166TestCase {
14 +
15 +    public static class Unbounded extends BlockingQueueTest {
16 +        protected BlockingQueue emptyCollection() {
17 +            return new LinkedBlockingDeque();
18 +        }
19 +    }
20 +
21 +    public static class Bounded extends BlockingQueueTest {
22 +        protected BlockingQueue emptyCollection() {
23 +            return new LinkedBlockingDeque(20);
24 +        }
25 +    }
26 +
27      public static void main(String[] args) {
28 <        junit.textui.TestRunner.run (suite());
28 >        junit.textui.TestRunner.run(suite());
29      }
30  
31      public static Test suite() {
32 <        return new TestSuite(LinkedBlockingDequeTest.class);
32 >        return newTestSuite(LinkedBlockingDequeTest.class,
33 >                            new Unbounded().testSuite(),
34 >                            new Bounded().testSuite());
35      }
36  
37      /**
38       * Create a deque of given size containing consecutive
39       * Integers 0 ... n.
40       */
41 <    private LinkedBlockingDeque populatedDeque(int n) {
42 <        LinkedBlockingDeque q = new LinkedBlockingDeque(n);
41 >    private LinkedBlockingDeque<Integer> populatedDeque(int n) {
42 >        LinkedBlockingDeque<Integer> q =
43 >            new LinkedBlockingDeque<Integer>(n);
44          assertTrue(q.isEmpty());
45          for (int i = 0; i < n; i++)
46              assertTrue(q.offer(new Integer(i)));
# Line 93 | Line 109 | public class LinkedBlockingDequeTest ext
109      }
110  
111      /**
112 <     *  pollFirst succeeds unless empty
112 >     * pollFirst succeeds unless empty
113       */
114      public void testPollFirst() {
115          LinkedBlockingDeque q = populatedDeque(SIZE);
116          for (int i = 0; i < SIZE; ++i) {
117 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
117 >            assertEquals(i, q.pollFirst());
118          }
119          assertNull(q.pollFirst());
120      }
121  
122      /**
123 <     *  pollLast succeeds unless empty
123 >     * pollLast succeeds unless empty
124       */
125      public void testPollLast() {
126          LinkedBlockingDeque q = populatedDeque(SIZE);
127          for (int i = SIZE-1; i >= 0; --i) {
128 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
128 >            assertEquals(i, q.pollLast());
129          }
130          assertNull(q.pollLast());
131      }
132  
133      /**
134 <     *  peekFirst returns next element, or null if empty
134 >     * peekFirst returns next element, or null if empty
135       */
136      public void testPeekFirst() {
137          LinkedBlockingDeque q = populatedDeque(SIZE);
138          for (int i = 0; i < SIZE; ++i) {
139 <            assertEquals(i, ((Integer)q.peekFirst()).intValue());
140 <            q.pollFirst();
139 >            assertEquals(i, q.peekFirst());
140 >            assertEquals(i, q.pollFirst());
141              assertTrue(q.peekFirst() == null ||
142 <                       i != ((Integer)q.peekFirst()).intValue());
142 >                       !q.peekFirst().equals(i));
143          }
144          assertNull(q.peekFirst());
145      }
146  
147      /**
148 <     *  peek returns next element, or null if empty
148 >     * peek returns next element, or null if empty
149       */
150      public void testPeek() {
151          LinkedBlockingDeque q = populatedDeque(SIZE);
152          for (int i = 0; i < SIZE; ++i) {
153 <            assertEquals(i, ((Integer)q.peek()).intValue());
154 <            q.pollFirst();
153 >            assertEquals(i, q.peek());
154 >            assertEquals(i, q.pollFirst());
155              assertTrue(q.peek() == null ||
156 <                       i != ((Integer)q.peek()).intValue());
156 >                       !q.peek().equals(i));
157          }
158          assertNull(q.peek());
159      }
160  
161      /**
162 <     *  peekLast returns next element, or null if empty
162 >     * peekLast returns next element, or null if empty
163       */
164      public void testPeekLast() {
165          LinkedBlockingDeque q = populatedDeque(SIZE);
166          for (int i = SIZE-1; i >= 0; --i) {
167 <            assertEquals(i, ((Integer)q.peekLast()).intValue());
168 <            q.pollLast();
167 >            assertEquals(i, q.peekLast());
168 >            assertEquals(i, q.pollLast());
169              assertTrue(q.peekLast() == null ||
170 <                       i != ((Integer)q.peekLast()).intValue());
170 >                       !q.peekLast().equals(i));
171          }
172          assertNull(q.peekLast());
173      }
174  
175      /**
176 <     * getFirst returns next getFirst, or throws NSEE if empty
176 >     * getFirst() returns first element, or throws NSEE if empty
177       */
178      public void testFirstElement() {
179          LinkedBlockingDeque q = populatedDeque(SIZE);
180          for (int i = 0; i < SIZE; ++i) {
181 <            assertEquals(i, ((Integer)q.getFirst()).intValue());
182 <            q.pollFirst();
181 >            assertEquals(i, q.getFirst());
182 >            assertEquals(i, q.pollFirst());
183          }
184          try {
185              q.getFirst();
# Line 173 | Line 189 | public class LinkedBlockingDequeTest ext
189      }
190  
191      /**
192 <     *  getLast returns next element, or throws NSEE if empty
192 >     * getLast() returns last element, or throws NSEE if empty
193       */
194      public void testLastElement() {
195          LinkedBlockingDeque q = populatedDeque(SIZE);
196          for (int i = SIZE-1; i >= 0; --i) {
197 <            assertEquals(i, ((Integer)q.getLast()).intValue());
198 <            q.pollLast();
197 >            assertEquals(i, q.getLast());
198 >            assertEquals(i, q.pollLast());
199          }
200          try {
201              q.getLast();
# Line 189 | Line 205 | public class LinkedBlockingDequeTest ext
205      }
206  
207      /**
208 <     *  removeFirst removes next element, or throws NSEE if empty
208 >     * removeFirst() removes first element, or throws NSEE if empty
209       */
210      public void testRemoveFirst() {
211          LinkedBlockingDeque q = populatedDeque(SIZE);
212          for (int i = 0; i < SIZE; ++i) {
213 <            assertEquals(i, ((Integer)q.removeFirst()).intValue());
213 >            assertEquals(i, q.removeFirst());
214          }
215          try {
216              q.removeFirst();
# Line 204 | Line 220 | public class LinkedBlockingDequeTest ext
220      }
221  
222      /**
223 <     *  removeLast removes last element, or throws NSEE if empty
223 >     * removeLast() removes last element, or throws NSEE if empty
224       */
225      public void testRemoveLast() {
226          LinkedBlockingDeque q = populatedDeque(SIZE);
227          for (int i = SIZE - 1; i >= 0; --i) {
228 <            assertEquals(i, ((Integer)q.removeLast()).intValue());
228 >            assertEquals(i, q.removeLast());
229          }
230          try {
231              q.removeLast();
# Line 219 | Line 235 | public class LinkedBlockingDequeTest ext
235      }
236  
237      /**
238 <     *  remove removes next element, or throws NSEE if empty
238 >     * remove removes next element, or throws NSEE if empty
239       */
240      public void testRemove() {
241          LinkedBlockingDeque q = populatedDeque(SIZE);
242          for (int i = 0; i < SIZE; ++i) {
243 <            assertEquals(i, ((Integer)q.remove()).intValue());
243 >            assertEquals(i, q.remove());
244          }
245          try {
246              q.remove();
# Line 269 | Line 285 | public class LinkedBlockingDequeTest ext
285          LinkedBlockingDeque q = populatedDeque(3);
286          q.pollLast();
287          q.addFirst(four);
288 <        assertEquals(four,q.peekFirst());
288 >        assertSame(four, q.peekFirst());
289      }
290  
291      /**
# Line 279 | Line 295 | public class LinkedBlockingDequeTest ext
295          LinkedBlockingDeque q = populatedDeque(3);
296          q.pollLast();
297          q.addLast(four);
298 <        assertEquals(four,q.peekLast());
298 >        assertSame(four, q.peekLast());
299      }
300  
301  
# Line 437 | Line 453 | public class LinkedBlockingDequeTest ext
453          LinkedBlockingDeque q = populatedDeque(3);
454          q.pollLast();
455          q.push(four);
456 <        assertEquals(four,q.peekFirst());
456 >        assertSame(four, q.peekFirst());
457      }
458  
459  
460      /**
461 <     *  pop removes next element, or throws NSEE if empty
461 >     * pop removes next element, or throws NSEE if empty
462       */
463      public void testPop() {
464          LinkedBlockingDeque q = populatedDeque(SIZE);
465          for (int i = 0; i < SIZE; ++i) {
466 <            assertEquals(i, ((Integer)q.pop()).intValue());
466 >            assertEquals(i, q.pop());
467          }
468          try {
469              q.pop();
# Line 513 | Line 529 | public class LinkedBlockingDequeTest ext
529              shouldThrow();
530          } catch (NullPointerException success) {}
531      }
532 +
533      /**
534       * addAll of a collection with any null elements throws NPE after
535       * possibly adding some elements
# Line 527 | Line 544 | public class LinkedBlockingDequeTest ext
544              shouldThrow();
545          } catch (NullPointerException success) {}
546      }
547 +
548      /**
549       * addAll throws ISE if not enough room
550       */
# Line 660 | Line 678 | public class LinkedBlockingDequeTest ext
678      public void testTake() throws InterruptedException {
679          LinkedBlockingDeque q = populatedDeque(SIZE);
680          for (int i = 0; i < SIZE; ++i) {
681 <            assertEquals(i, ((Integer)q.take()).intValue());
681 >            assertEquals(i, q.take());
682          }
683      }
684  
685      /**
668     * take blocks interruptibly when empty
669     */
670    public void testTakeFromEmpty() throws InterruptedException {
671        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
672        Thread t = new ThreadShouldThrow(InterruptedException.class) {
673            public void realRun() throws InterruptedException {
674                q.take();
675            }};
676
677        t.start();
678        Thread.sleep(SHORT_DELAY_MS);
679        t.interrupt();
680        t.join();
681    }
682
683    /**
686       * Take removes existing elements until empty, then blocks interruptibly
687       */
688      public void testBlockingTake() throws InterruptedException {
# Line 688 | Line 690 | public class LinkedBlockingDequeTest ext
690          Thread t = new Thread(new CheckedRunnable() {
691              public void realRun() throws InterruptedException {
692                  for (int i = 0; i < SIZE; ++i) {
693 <                    assertEquals(i, ((Integer)q.take()).intValue());
693 >                    assertEquals(i, q.take());
694                  }
695                  try {
696                      q.take();
# Line 709 | Line 711 | public class LinkedBlockingDequeTest ext
711      public void testPoll() {
712          LinkedBlockingDeque q = populatedDeque(SIZE);
713          for (int i = 0; i < SIZE; ++i) {
714 <            assertEquals(i, ((Integer)q.poll()).intValue());
714 >            assertEquals(i, q.poll());
715          }
716          assertNull(q.poll());
717      }
# Line 720 | Line 722 | public class LinkedBlockingDequeTest ext
722      public void testTimedPoll0() throws InterruptedException {
723          LinkedBlockingDeque q = populatedDeque(SIZE);
724          for (int i = 0; i < SIZE; ++i) {
725 <            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
725 >            assertEquals(i, q.poll(0, MILLISECONDS));
726          }
727          assertNull(q.poll(0, MILLISECONDS));
728      }
# Line 731 | Line 733 | public class LinkedBlockingDequeTest ext
733      public void testTimedPoll() throws InterruptedException {
734          LinkedBlockingDeque q = populatedDeque(SIZE);
735          for (int i = 0; i < SIZE; ++i) {
736 <            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
736 >            assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
737          }
738          assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
739      }
# Line 745 | Line 747 | public class LinkedBlockingDequeTest ext
747              public void realRun() throws InterruptedException {
748                  LinkedBlockingDeque q = populatedDeque(SIZE);
749                  for (int i = 0; i < SIZE; ++i) {
750 <                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
750 >                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
751                  }
752                  try {
753                      q.poll(SMALL_DELAY_MS, MILLISECONDS);
# Line 760 | Line 762 | public class LinkedBlockingDequeTest ext
762      }
763  
764      /**
763     *  timed poll before a delayed offer fails; after offer succeeds;
764     *  on interruption throws
765     */
766    public void testTimedPollWithOffer() throws InterruptedException {
767        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
768        Thread t = new Thread(new CheckedRunnable() {
769            public void realRun() throws InterruptedException {
770                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
771                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
772                try {
773                    q.poll(LONG_DELAY_MS, MILLISECONDS);
774                    shouldThrow();
775                } catch (InterruptedException success) {}
776            }});
777
778        t.start();
779        Thread.sleep(SMALL_DELAY_MS);
780        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
781        t.interrupt();
782        t.join();
783    }
784
785
786    /**
765       * putFirst(null) throws NPE
766       */
767       public void testPutFirstNull() throws InterruptedException {
# Line 886 | Line 864 | public class LinkedBlockingDequeTest ext
864      public void testTakeFirst() throws InterruptedException {
865          LinkedBlockingDeque q = populatedDeque(SIZE);
866          for (int i = 0; i < SIZE; ++i) {
867 <            assertEquals(i, ((Integer)q.takeFirst()).intValue());
867 >            assertEquals(i, q.takeFirst());
868          }
869      }
870  
# Line 934 | Line 912 | public class LinkedBlockingDequeTest ext
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());
915 >            assertEquals(i, q.pollFirst(0, MILLISECONDS));
916          }
917          assertNull(q.pollFirst(0, MILLISECONDS));
918      }
# Line 945 | Line 923 | public class LinkedBlockingDequeTest ext
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());
926 >            assertEquals(i, q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
927          }
928          assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
929      }
# Line 959 | Line 937 | public class LinkedBlockingDequeTest ext
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());
940 >                    assertEquals(i, q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
941                  }
942                  try {
943                      q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
# Line 974 | Line 952 | public class LinkedBlockingDequeTest ext
952      }
953  
954      /**
955 <     *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
956 <     *  on interruption throws
955 >     * timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
956 >     * on interruption throws
957       */
958      public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
959          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1099 | Line 1077 | public class LinkedBlockingDequeTest ext
1077      public void testTakeLast() throws InterruptedException {
1078          LinkedBlockingDeque q = populatedDeque(SIZE);
1079          for (int i = 0; i < SIZE; ++i) {
1080 <            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1080 >            assertEquals(SIZE-i-1, q.takeLast());
1081          }
1082      }
1083  
# Line 1146 | Line 1124 | public class LinkedBlockingDequeTest ext
1124      public void testTimedPollLast0() throws InterruptedException {
1125          LinkedBlockingDeque q = populatedDeque(SIZE);
1126          for (int i = 0; i < SIZE; ++i) {
1127 <            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1127 >            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1128          }
1129          assertNull(q.pollLast(0, MILLISECONDS));
1130      }
# Line 1157 | Line 1135 | public class LinkedBlockingDequeTest ext
1135      public void testTimedPollLast() throws InterruptedException {
1136          LinkedBlockingDeque q = populatedDeque(SIZE);
1137          for (int i = 0; i < SIZE; ++i) {
1138 <            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1138 >            assertEquals(SIZE-i-1, q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1139          }
1140          assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1141      }
# Line 1171 | Line 1149 | public class LinkedBlockingDequeTest ext
1149              public void realRun() throws InterruptedException {
1150                  LinkedBlockingDeque q = populatedDeque(SIZE);
1151                  for (int i = 0; i < SIZE; ++i) {
1152 <                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1152 >                    assertEquals(SIZE-i-1, q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1153                  }
1154                  try {
1155                      q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
# Line 1186 | Line 1164 | public class LinkedBlockingDequeTest ext
1164      }
1165  
1166      /**
1167 <     *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1168 <     *  on interruption throws
1167 >     * timed poll before a delayed offerLast fails; after offerLast succeeds;
1168 >     * on interruption throws
1169       */
1170      public void testTimedPollWithOfferLast() throws InterruptedException {
1171          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1215 | Line 1193 | public class LinkedBlockingDequeTest ext
1193      public void testElement() {
1194          LinkedBlockingDeque q = populatedDeque(SIZE);
1195          for (int i = 0; i < SIZE; ++i) {
1196 <            assertEquals(i, ((Integer)q.element()).intValue());
1196 >            assertEquals(i, q.element());
1197              q.poll();
1198          }
1199          try {
# Line 1230 | Line 1208 | public class LinkedBlockingDequeTest ext
1208      public void testRemoveElement() {
1209          LinkedBlockingDeque q = populatedDeque(SIZE);
1210          for (int i = 1; i < SIZE; i+=2) {
1211 <            assertTrue(q.remove(new Integer(i)));
1211 >            assertTrue(q.contains(i));
1212 >            assertTrue(q.remove(i));
1213 >            assertFalse(q.contains(i));
1214 >            assertTrue(q.contains(i-1));
1215          }
1216          for (int i = 0; i < SIZE; i+=2) {
1217 <            assertTrue(q.remove(new Integer(i)));
1218 <            assertFalse(q.remove(new Integer(i+1)));
1217 >            assertTrue(q.contains(i));
1218 >            assertTrue(q.remove(i));
1219 >            assertFalse(q.contains(i));
1220 >            assertFalse(q.remove(i+1));
1221 >            assertFalse(q.contains(i+1));
1222          }
1223          assertTrue(q.isEmpty());
1224      }
# Line 1317 | Line 1301 | public class LinkedBlockingDequeTest ext
1301      }
1302  
1303      /**
1304 <     * toArray contains all elements
1304 >     * toArray contains all elements in FIFO order
1305       */
1306      public void testToArray() throws InterruptedException{
1307          LinkedBlockingDeque q = populatedDeque(SIZE);
1308          Object[] o = q.toArray();
1309          for (int i = 0; i < o.length; i++)
1310 <            assertEquals(o[i], q.take());
1310 >            assertSame(o[i], q.poll());
1311      }
1312  
1313      /**
1314 <     * toArray(a) contains all elements
1314 >     * toArray(a) contains all elements in FIFO order
1315       */
1316 <    public void testToArray2() throws InterruptedException {
1317 <        LinkedBlockingDeque q = populatedDeque(SIZE);
1316 >    public void testToArray2() {
1317 >        LinkedBlockingDeque<Integer> q = populatedDeque(SIZE);
1318          Integer[] ints = new Integer[SIZE];
1319 <        ints = (Integer[])q.toArray(ints);
1319 >        Integer[] array = q.toArray(ints);
1320 >        assertSame(ints, array);
1321          for (int i = 0; i < ints.length; i++)
1322 <            assertEquals(ints[i], q.take());
1322 >            assertSame(ints[i], q.remove());
1323      }
1324  
1325      /**
1326 <     * toArray(null) throws NPE
1326 >     * toArray(null) throws NullPointerException
1327       */
1328 <    public void testToArray_BadArg() {
1328 >    public void testToArray_NullArg() {
1329 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1330          try {
1331 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1346 <            Object o[] = q.toArray(null);
1331 >            q.toArray(null);
1332              shouldThrow();
1333          } catch (NullPointerException success) {}
1334      }
1335  
1336      /**
1337 <     * toArray with incompatible array type throws CCE
1337 >     * toArray(incompatible array type) throws ArrayStoreException
1338       */
1339      public void testToArray1_BadArg() {
1340 +        LinkedBlockingDeque q = populatedDeque(SIZE);
1341          try {
1342 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1357 <            Object o[] = q.toArray(new String[10] );
1342 >            q.toArray(new String[10]);
1343              shouldThrow();
1344          } catch (ArrayStoreException success) {}
1345      }
# Line 1374 | Line 1359 | public class LinkedBlockingDequeTest ext
1359      /**
1360       * iterator.remove removes current element
1361       */
1362 <    public void testIteratorRemove () {
1362 >    public void testIteratorRemove() {
1363          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1364          q.add(two);
1365          q.add(one);
# Line 1385 | Line 1370 | public class LinkedBlockingDequeTest ext
1370          it.remove();
1371  
1372          it = q.iterator();
1373 <        assertEquals(it.next(), one);
1374 <        assertEquals(it.next(), three);
1373 >        assertSame(it.next(), one);
1374 >        assertSame(it.next(), three);
1375          assertFalse(it.hasNext());
1376      }
1377  
# Line 1402 | Line 1387 | public class LinkedBlockingDequeTest ext
1387          assertEquals(0, q.remainingCapacity());
1388          int k = 0;
1389          for (Iterator it = q.iterator(); it.hasNext();) {
1390 <            int i = ((Integer)(it.next())).intValue();
1406 <            assertEquals(++k, i);
1390 >            assertEquals(++k, it.next());
1391          }
1392          assertEquals(3, k);
1393      }
# Line 1411 | Line 1395 | public class LinkedBlockingDequeTest ext
1395      /**
1396       * Modifications do not cause iterators to fail
1397       */
1398 <    public void testWeaklyConsistentIteration () {
1398 >    public void testWeaklyConsistentIteration() {
1399          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1400          q.add(one);
1401          q.add(two);
# Line 1425 | Line 1409 | public class LinkedBlockingDequeTest ext
1409  
1410  
1411      /**
1412 <     *  Descending iterator iterates through all elements
1412 >     * Descending iterator iterates through all elements
1413       */
1414      public void testDescendingIterator() {
1415          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 1444 | Line 1428 | public class LinkedBlockingDequeTest ext
1428      }
1429  
1430      /**
1431 <     *  Descending iterator ordering is reverse FIFO
1431 >     * Descending iterator ordering is reverse FIFO
1432       */
1433      public void testDescendingIteratorOrdering() {
1434          final LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1454 | Line 1438 | public class LinkedBlockingDequeTest ext
1438              q.add(new Integer(1));
1439              int k = 0;
1440              for (Iterator it = q.descendingIterator(); it.hasNext();) {
1441 <                int i = ((Integer)(it.next())).intValue();
1458 <                assertEquals(++k, i);
1441 >                assertEquals(++k, it.next());
1442              }
1443  
1444              assertEquals(3, k);
# Line 1468 | Line 1451 | public class LinkedBlockingDequeTest ext
1451      /**
1452       * descendingIterator.remove removes current element
1453       */
1454 <    public void testDescendingIteratorRemove () {
1454 >    public void testDescendingIteratorRemove() {
1455          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1456          for (int iters = 0; iters < 100; ++iters) {
1457              q.add(new Integer(3));
# Line 1510 | Line 1493 | public class LinkedBlockingDequeTest ext
1493          ExecutorService executor = Executors.newFixedThreadPool(2);
1494          executor.execute(new CheckedRunnable() {
1495              public void realRun() throws InterruptedException {
1496 <                threadAssertFalse(q.offer(three));
1497 <                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1498 <                threadAssertEquals(0, q.remainingCapacity());
1496 >                assertFalse(q.offer(three));
1497 >                assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1498 >                assertEquals(0, q.remainingCapacity());
1499              }});
1500  
1501          executor.execute(new CheckedRunnable() {
1502              public void realRun() throws InterruptedException {
1503                  Thread.sleep(SMALL_DELAY_MS);
1504 <                threadAssertEquals(one, q.take());
1504 >                assertSame(one, q.take());
1505              }});
1506  
1507          joinPool(executor);
# Line 1532 | Line 1515 | public class LinkedBlockingDequeTest ext
1515          ExecutorService executor = Executors.newFixedThreadPool(2);
1516          executor.execute(new CheckedRunnable() {
1517              public void realRun() throws InterruptedException {
1518 <                threadAssertNull(q.poll());
1519 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1520 <                threadAssertTrue(q.isEmpty());
1518 >                assertNull(q.poll());
1519 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1520 >                assertTrue(q.isEmpty());
1521              }});
1522  
1523          executor.execute(new CheckedRunnable() {
# Line 1654 | Line 1637 | public class LinkedBlockingDequeTest ext
1637      }
1638  
1639      /**
1640 <     * drainTo(c, n) empties first max {n, size} elements of deque into c
1640 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
1641       */
1642      public void testDrainToN() {
1643          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1663 | Line 1646 | public class LinkedBlockingDequeTest ext
1646                  assertTrue(q.offer(new Integer(j)));
1647              ArrayList l = new ArrayList();
1648              q.drainTo(l, i);
1649 <            int k = (i < SIZE)? i : SIZE;
1649 >            int k = (i < SIZE) ? i : SIZE;
1650              assertEquals(l.size(), k);
1651              assertEquals(q.size(), SIZE-k);
1652              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines