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.41 by jsr166, Sat Mar 11 17:33:32 2017 UTC vs.
Revision 1.47 by jsr166, Mon May 28 21:19:50 2018 UTC

# Line 28 | Line 28 | public class PriorityQueueTest extends J
28              public boolean isConcurrent() { return false; }
29              public boolean permitsNulls() { return false; }
30          }
31 <        return newTestSuite(PriorityQueueTest.class,
32 <                            CollectionTest.testSuite(new Implementation()));
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 42 | Line 53 | public class PriorityQueueTest extends J
53       * Returns a new queue of given size containing consecutive
54       * Integers 0 ... n - 1.
55       */
56 <    private PriorityQueue<Integer> populatedQueue(int 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)
# Line 63 | 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 425 | Line 436 | public class PriorityQueueTest extends J
436       */
437      public void testToArray() {
438          PriorityQueue q = populatedQueue(SIZE);
439 <        Object[] o = q.toArray();
440 <        Arrays.sort(o);
441 <        for (int i = 0; i < o.length; i++)
442 <            assertSame(o[i], q.poll());
439 >        Object[] a = q.toArray();
440 >        assertSame(Object[].class, a.getClass());
441 >        Arrays.sort(a);
442 >        for (Object o : a)
443 >            assertSame(o, q.poll());
444 >        assertTrue(q.isEmpty());
445      }
446  
447      /**
# Line 440 | Line 453 | public class PriorityQueueTest extends J
453          Integer[] array = q.toArray(ints);
454          assertSame(ints, array);
455          Arrays.sort(ints);
456 <        for (int i = 0; i < ints.length; i++)
457 <            assertSame(ints[i], q.poll());
456 >        for (Integer o : ints)
457 >            assertSame(o, q.poll());
458 >        assertTrue(q.isEmpty());
459      }
460  
461      /**
# Line 495 | Line 509 | public class PriorityQueueTest extends J
509      }
510  
511      /**
512 <     * A deserialized serialized queue has same elements
512 >     * A deserialized/reserialized queue has same elements
513       */
514      public void testSerialization() throws Exception {
515          Queue x = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines