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.59 by jsr166, Tue Feb 21 01:54:04 2012 UTC vs.
Revision 1.65 by jsr166, Wed Dec 31 20:09:08 2014 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
10 < import java.util.Arrays;
9 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 >
11   import java.util.ArrayList;
12 + import java.util.Arrays;
13 + import java.util.Collection;
14   import java.util.Iterator;
15   import java.util.NoSuchElementException;
16   import java.util.concurrent.BlockingQueue;
# Line 18 | Line 20 | import java.util.concurrent.DelayQueue;
20   import java.util.concurrent.Executors;
21   import java.util.concurrent.ExecutorService;
22   import java.util.concurrent.TimeUnit;
23 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
23 >
24 > import junit.framework.Test;
25  
26   public class DelayQueueTest extends JSR166TestCase {
27  
# Line 62 | Line 65 | public class DelayQueueTest extends JSR1
65              return (other instanceof PDelay) &&
66                  this.pseudodelay == ((PDelay)other).pseudodelay;
67          }
68 +        // suppress [overrides] javac warning
69 +        public int hashCode() { return pseudodelay; }
70          public long getDelay(TimeUnit ignore) {
71              return Integer.MIN_VALUE + pseudodelay;
72          }
# Line 97 | Line 102 | public class DelayQueueTest extends JSR1
102              return other.trigger == trigger;
103          }
104  
105 +        // suppress [overrides] javac warning
106 +        public int hashCode() { return (int) trigger; }
107 +
108          public long getDelay(TimeUnit unit) {
109              long n = trigger - System.nanoTime();
110              return unit.convert(n, TimeUnit.NANOSECONDS);
# Line 112 | Line 120 | public class DelayQueueTest extends JSR1
120      }
121  
122      /**
123 <     * Creates a queue of given size containing consecutive
123 >     * Returns a new queue of given size containing consecutive
124       * PDelays 0 ... n.
125       */
126      private DelayQueue<PDelay> populatedQueue(int n) {
127          DelayQueue<PDelay> q = new DelayQueue<PDelay>();
128          assertTrue(q.isEmpty());
129 <        for (int i = n-1; i >= 0; i-=2)
129 >        for (int i = n-1; i >= 0; i -= 2)
130              assertTrue(q.offer(new PDelay(i)));
131 <        for (int i = (n & 1); i < n; i+=2)
131 >        for (int i = (n & 1); i < n; i += 2)
132              assertTrue(q.offer(new PDelay(i)));
133          assertFalse(q.isEmpty());
134          assertEquals(NOCAP, q.remainingCapacity());
# Line 646 | Line 654 | public class DelayQueueTest extends JSR1
654              public void realRun() throws InterruptedException {
655                  assertNull(q.poll());
656                  threadsStarted.await();
657 <                assertTrue(null != q.poll(LONG_DELAY_MS, MILLISECONDS));
657 >                assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS));
658                  checkEmpty(q);
659              }});
660  
# Line 766 | Line 774 | public class DelayQueueTest extends JSR1
774          }
775      }
776  
777 +    /**
778 +     * remove(null), contains(null) always return false
779 +     */
780 +    public void testNeverContainsNull() {
781 +        Collection<?> q = populatedQueue(SIZE);
782 +        assertFalse(q.contains(null));
783 +        assertFalse(q.remove(null));
784 +    }
785   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines