ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/DelayQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/DelayQueueTest.java (file contents):
Revision 1.66 by jsr166, Wed Dec 31 20:17:39 2014 UTC vs.
Revision 1.71 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 35 | Line 35 | public class DelayQueueTest extends JSR1
35      }
36  
37      public static void main(String[] args) {
38 <        junit.textui.TestRunner.run(suite());
38 >        main(suite(), args);
39      }
40  
41      public static Test suite() {
# Line 43 | Line 43 | public class DelayQueueTest extends JSR1
43                              new Generic().testSuite());
44      }
45  
46    private static final int NOCAP = Integer.MAX_VALUE;
47
46      /**
47       * A delayed implementation for testing.
48       * Most tests use Pseudodelays, where delays are all elapsed
# Line 131 | Line 129 | public class DelayQueueTest extends JSR1
129          for (int i = (n & 1); i < n; i += 2)
130              assertTrue(q.offer(new PDelay(i)));
131          assertFalse(q.isEmpty());
132 <        assertEquals(NOCAP, q.remainingCapacity());
132 >        assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
133          assertEquals(n, q.size());
134          return q;
135      }
# Line 140 | Line 138 | public class DelayQueueTest extends JSR1
138       * A new queue has unbounded capacity
139       */
140      public void testConstructor1() {
141 <        assertEquals(NOCAP, new DelayQueue().remainingCapacity());
141 >        assertEquals(Integer.MAX_VALUE, new DelayQueue().remainingCapacity());
142      }
143  
144      /**
# Line 148 | Line 146 | public class DelayQueueTest extends JSR1
146       */
147      public void testConstructor3() {
148          try {
149 <            DelayQueue q = new DelayQueue(null);
149 >            new DelayQueue(null);
150              shouldThrow();
151          } catch (NullPointerException success) {}
152      }
# Line 159 | Line 157 | public class DelayQueueTest extends JSR1
157      public void testConstructor4() {
158          try {
159              PDelay[] ints = new PDelay[SIZE];
160 <            DelayQueue q = new DelayQueue(Arrays.asList(ints));
160 >            new DelayQueue(Arrays.asList(ints));
161              shouldThrow();
162          } catch (NullPointerException success) {}
163      }
# Line 172 | Line 170 | public class DelayQueueTest extends JSR1
170              PDelay[] ints = new PDelay[SIZE];
171              for (int i = 0; i < SIZE-1; ++i)
172                  ints[i] = new PDelay(i);
173 <            DelayQueue q = new DelayQueue(Arrays.asList(ints));
173 >            new DelayQueue(Arrays.asList(ints));
174              shouldThrow();
175          } catch (NullPointerException success) {}
176      }
# Line 195 | Line 193 | public class DelayQueueTest extends JSR1
193      public void testEmpty() {
194          DelayQueue q = new DelayQueue();
195          assertTrue(q.isEmpty());
196 <        assertEquals(NOCAP, q.remainingCapacity());
196 >        assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
197          q.add(new PDelay(1));
198          assertFalse(q.isEmpty());
199          q.add(new PDelay(2));
# Line 205 | Line 203 | public class DelayQueueTest extends JSR1
203      }
204  
205      /**
206 <     * remainingCapacity does not change when elements added or removed,
209 <     * but size does
206 >     * remainingCapacity() always returns Integer.MAX_VALUE
207       */
208      public void testRemainingCapacity() {
209 <        DelayQueue q = populatedQueue(SIZE);
209 >        BlockingQueue q = populatedQueue(SIZE);
210          for (int i = 0; i < SIZE; ++i) {
211 <            assertEquals(NOCAP, q.remainingCapacity());
211 >            assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
212              assertEquals(SIZE-i, q.size());
213 <            q.remove();
213 >            assertTrue(q.remove() instanceof PDelay);
214          }
215          for (int i = 0; i < SIZE; ++i) {
216 <            assertEquals(NOCAP, q.remainingCapacity());
216 >            assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
217              assertEquals(i, q.size());
218 <            q.add(new PDelay(i));
218 >            assertTrue(q.add(new PDelay(i)));
219          }
220      }
221  
# Line 335 | Line 332 | public class DelayQueueTest extends JSR1
332      public void testTake() throws InterruptedException {
333          DelayQueue q = populatedQueue(SIZE);
334          for (int i = 0; i < SIZE; ++i) {
335 <            assertEquals(new PDelay(i), ((PDelay)q.take()));
335 >            assertEquals(new PDelay(i), q.take());
336          }
337      }
338  
# Line 378 | Line 375 | public class DelayQueueTest extends JSR1
375      public void testPoll() {
376          DelayQueue q = populatedQueue(SIZE);
377          for (int i = 0; i < SIZE; ++i) {
378 <            assertEquals(new PDelay(i), ((PDelay)q.poll()));
378 >            assertEquals(new PDelay(i), q.poll());
379          }
380          assertNull(q.poll());
381      }
# Line 389 | Line 386 | public class DelayQueueTest extends JSR1
386      public void testTimedPoll0() throws InterruptedException {
387          DelayQueue q = populatedQueue(SIZE);
388          for (int i = 0; i < SIZE; ++i) {
389 <            assertEquals(new PDelay(i), ((PDelay)q.poll(0, MILLISECONDS)));
389 >            assertEquals(new PDelay(i), q.poll(0, MILLISECONDS));
390          }
391          assertNull(q.poll(0, MILLISECONDS));
392      }
# Line 401 | Line 398 | public class DelayQueueTest extends JSR1
398          DelayQueue q = populatedQueue(SIZE);
399          for (int i = 0; i < SIZE; ++i) {
400              long startTime = System.nanoTime();
401 <            assertEquals(new PDelay(i), ((PDelay)q.poll(LONG_DELAY_MS, MILLISECONDS)));
401 >            assertEquals(new PDelay(i), q.poll(LONG_DELAY_MS, MILLISECONDS));
402              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
403          }
404          long startTime = System.nanoTime();
# Line 450 | Line 447 | public class DelayQueueTest extends JSR1
447      public void testPeek() {
448          DelayQueue q = populatedQueue(SIZE);
449          for (int i = 0; i < SIZE; ++i) {
450 <            assertEquals(new PDelay(i), ((PDelay)q.peek()));
451 <            assertEquals(new PDelay(i), ((PDelay)q.poll()));
450 >            assertEquals(new PDelay(i), q.peek());
451 >            assertEquals(new PDelay(i), q.poll());
452              if (q.isEmpty())
453                  assertNull(q.peek());
454              else
# Line 466 | Line 463 | public class DelayQueueTest extends JSR1
463      public void testElement() {
464          DelayQueue q = populatedQueue(SIZE);
465          for (int i = 0; i < SIZE; ++i) {
466 <            assertEquals(new PDelay(i), ((PDelay)q.element()));
466 >            assertEquals(new PDelay(i), q.element());
467              q.poll();
468          }
469          try {
# Line 481 | Line 478 | public class DelayQueueTest extends JSR1
478      public void testRemove() {
479          DelayQueue q = populatedQueue(SIZE);
480          for (int i = 0; i < SIZE; ++i) {
481 <            assertEquals(new PDelay(i), ((PDelay)q.remove()));
481 >            assertEquals(new PDelay(i), q.remove());
482          }
483          try {
484              q.remove();
# Line 509 | Line 506 | public class DelayQueueTest extends JSR1
506          q.clear();
507          assertTrue(q.isEmpty());
508          assertEquals(0, q.size());
509 <        assertEquals(NOCAP, q.remainingCapacity());
509 >        assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
510          PDelay x = new PDelay(1);
511          q.add(x);
512          assertFalse(q.isEmpty());
# Line 614 | Line 611 | public class DelayQueueTest extends JSR1
611              ++i;
612          }
613          assertEquals(i, SIZE);
614 +        assertIteratorExhausted(it);
615 +    }
616 +
617 +    /**
618 +     * iterator of empty collection has no elements
619 +     */
620 +    public void testEmptyIterator() {
621 +        assertIteratorExhausted(new DelayQueue().iterator());
622      }
623  
624      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines