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

Comparing jsr166/src/test/tck/PriorityQueueTest.java (file contents):
Revision 1.36 by jsr166, Sun May 24 01:42:14 2015 UTC vs.
Revision 1.46 by jsr166, Sun May 6 22:26:24 2018 UTC

# Line 15 | Line 15 | import java.util.PriorityQueue;
15   import java.util.Queue;
16  
17   import junit.framework.Test;
18 import junit.framework.TestSuite;
18  
19   public class PriorityQueueTest extends JSR166TestCase {
20      public static void main(String[] args) {
21          main(suite(), args);
22      }
23      public static Test suite() {
24 <        return new TestSuite(PriorityQueueTest.class);
24 >        class Implementation implements CollectionImplementation {
25 >            public Class<?> klazz() { return PriorityQueue.class; }
26 >            public Collection emptyCollection() { return new PriorityQueue(); }
27 >            public Object makeElement(int i) { return i; }
28 >            public boolean isConcurrent() { return false; }
29 >            public boolean permitsNulls() { return false; }
30 >        }
31 >        class ComparatorImplementation implements CollectionImplementation {
32 >            public Class<?> klazz() { return PriorityQueue.class; }
33 >            public Collection emptyCollection() {
34 >                return new PriorityQueue(new MyReverseComparator());
35 >            }
36 >            public Object makeElement(int i) { return i; }
37 >            public boolean isConcurrent() { return false; }
38 >            public boolean permitsNulls() { return false; }
39 >        }
40 >        return newTestSuite(
41 >            PriorityQueueTest.class,
42 >            CollectionTest.testSuite(new Implementation()),
43 >            CollectionTest.testSuite(new ComparatorImplementation()));
44      }
45  
46 <    static class MyReverseComparator implements Comparator {
46 >    static class MyReverseComparator implements Comparator, java.io.Serializable {
47          public int compare(Object x, Object y) {
48              return ((Comparable)y).compareTo(x);
49          }
# Line 33 | Line 51 | public class PriorityQueueTest extends J
51  
52      /**
53       * Returns a new queue of given size containing consecutive
54 <     * Integers 0 ... n.
54 >     * Integers 0 ... n - 1.
55       */
56 <    private PriorityQueue<Integer> populatedQueue(int n) {
57 <        PriorityQueue<Integer> q = new PriorityQueue<Integer>(n);
56 >    private static PriorityQueue<Integer> populatedQueue(int n) {
57 >        PriorityQueue<Integer> q = new PriorityQueue<>(n);
58          assertTrue(q.isEmpty());
59          for (int i = n - 1; i >= 0; i -= 2)
60              assertTrue(q.offer(new Integer(i)));
# Line 44 | Line 62 | public class PriorityQueueTest extends J
62              assertTrue(q.offer(new Integer(i)));
63          assertFalse(q.isEmpty());
64          assertEquals(n, q.size());
65 +        assertEquals((Integer) 0, q.peek());
66          return q;
67      }
68  
# Line 55 | Line 74 | public class PriorityQueueTest extends J
74      }
75  
76      /**
77 <     * Constructor throws IAE if capacity argument nonpositive
77 >     * Constructor throws IllegalArgumentException if capacity argument nonpositive
78       */
79      public void testConstructor2() {
80          try {
# Line 191 | Line 210 | public class PriorityQueueTest extends J
210          PriorityQueue q = new PriorityQueue(1);
211          try {
212              q.offer(new Object());
194            q.offer(new Object());
213              shouldThrow();
214 <        } catch (ClassCastException success) {}
214 >        } catch (ClassCastException success) {
215 >            assertTrue(q.isEmpty());
216 >            assertEquals(0, q.size());
217 >            assertNull(q.poll());
218 >        }
219      }
220  
221      /**
# Line 484 | Line 506 | public class PriorityQueueTest extends J
506      }
507  
508      /**
509 <     * A deserialized serialized queue has same elements
509 >     * A deserialized/reserialized queue has same elements
510       */
511      public void testSerialization() throws Exception {
512          Queue x = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines