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.25 by jsr166, Sun Nov 22 00:17:37 2009 UTC vs.
Revision 1.29 by jsr166, Tue Dec 1 09:48:12 2009 UTC

# Line 24 | Line 24 | public class DelayQueueTest extends JSR1
24  
25      /**
26       * A delayed implementation for testing.
27 <     * Most  tests use Pseudodelays, where delays are all elapsed
27 >     * Most tests use Pseudodelays, where delays are all elapsed
28       * (so, no blocking solely for delays) but are still ordered
29       */
30      static class PDelay implements Delayed {
# Line 32 | Line 32 | public class DelayQueueTest extends JSR1
32          PDelay(int i) { pseudodelay = Integer.MIN_VALUE + i; }
33          public int compareTo(PDelay y) {
34              int i = pseudodelay;
35 <            int j = ((PDelay)y).pseudodelay;
35 >            int j = y.pseudodelay;
36              if (i < j) return -1;
37              if (i > j) return 1;
38              return 0;
39          }
40  
41          public int compareTo(Delayed y) {
42 <            int i = pseudodelay;
43 <            int j = ((PDelay)y).pseudodelay;
44 <            if (i < j) return -1;
45 <            if (i > j) return 1;
46 <            return 0;
42 >            return compareTo((PDelay)y);
43          }
44  
45          public boolean equals(Object other) {
46 <            return ((PDelay)other).pseudodelay == pseudodelay;
46 >            return equals((PDelay)other);
47          }
48          public boolean equals(PDelay other) {
49 <            return ((PDelay)other).pseudodelay == pseudodelay;
49 >            return other.pseudodelay == pseudodelay;
50          }
51  
52  
# Line 77 | Line 73 | public class DelayQueueTest extends JSR1
73          }
74          public int compareTo(NanoDelay y) {
75              long i = trigger;
76 <            long j = ((NanoDelay)y).trigger;
76 >            long j = y.trigger;
77              if (i < j) return -1;
78              if (i > j) return 1;
79              return 0;
80          }
81  
82          public int compareTo(Delayed y) {
83 <            long i = trigger;
88 <            long j = ((NanoDelay)y).trigger;
89 <            if (i < j) return -1;
90 <            if (i > j) return 1;
91 <            return 0;
83 >            return compareTo((NanoDelay)y);
84          }
85  
86          public boolean equals(Object other) {
87 <            return ((NanoDelay)other).trigger == trigger;
87 >            return equals((NanoDelay)other);
88          }
89          public boolean equals(NanoDelay other) {
90 <            return ((NanoDelay)other).trigger == trigger;
90 >            return other.trigger == trigger;
91          }
92  
93          public long getDelay(TimeUnit unit) {
# Line 522 | Line 514 | public class DelayQueueTest extends JSR1
514          DelayQueue q = populatedQueue(SIZE);
515          for (int i = 0; i < SIZE; ++i) {
516              assertEquals(new PDelay(i), ((PDelay)q.peek()));
517 <            q.poll();
517 >            assertEquals(new PDelay(i), ((PDelay)q.poll()));
518              if (q.isEmpty())
519                  assertNull(q.peek());
520              else
521 <                assertTrue(i != ((PDelay)q.peek()).intValue());
521 >                assertFalse(new PDelay(i).equals(q.peek()));
522          }
523          assertNull(q.peek());
524      }
# Line 681 | Line 673 | public class DelayQueueTest extends JSR1
673       * toArray(null) throws NPE
674       */
675      public void testToArray_BadArg() {
676 +        DelayQueue q = populatedQueue(SIZE);
677          try {
685            DelayQueue q = populatedQueue(SIZE);
678              Object o[] = q.toArray(null);
679              shouldThrow();
680          } catch (NullPointerException success) {}
# Line 692 | Line 684 | public class DelayQueueTest extends JSR1
684       * toArray with incompatible array type throws CCE
685       */
686      public void testToArray1_BadArg() {
687 +        DelayQueue q = populatedQueue(SIZE);
688          try {
689 <            DelayQueue q = populatedQueue(SIZE);
697 <            Object o[] = q.toArray(new String[10] );
689 >            Object o[] = q.toArray(new String[10]);
690              shouldThrow();
691          } catch (ArrayStoreException success) {}
692      }
# Line 750 | Line 742 | public class DelayQueueTest extends JSR1
742          ExecutorService executor = Executors.newFixedThreadPool(2);
743          executor.execute(new CheckedRunnable() {
744              public void realRun() throws InterruptedException {
745 <                threadAssertNull(q.poll());
746 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
747 <                threadAssertTrue(q.isEmpty());
745 >                assertNull(q.poll());
746 >                assertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
747 >                assertTrue(q.isEmpty());
748              }});
749  
750          executor.execute(new CheckedRunnable() {
# Line 762 | Line 754 | public class DelayQueueTest extends JSR1
754              }});
755  
756          joinPool(executor);
765
757      }
758  
759  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines