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

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.54 by jsr166, Wed Dec 31 19:05:43 2014 UTC vs.
Revision 1.59 by jsr166, Sat Feb 28 19:59:23 2015 UTC

# Line 47 | Line 47 | public class PriorityBlockingQueueTest e
47                              new InitialCapacity().testSuite());
48      }
49  
50    private static final int NOCAP = Integer.MAX_VALUE;
51
50      /** Sample Comparator */
51      static class MyReverseComparator implements Comparator {
52          public int compare(Object x, Object y) {
# Line 64 | Line 62 | public class PriorityBlockingQueueTest e
62          PriorityBlockingQueue<Integer> q =
63              new PriorityBlockingQueue<Integer>(n);
64          assertTrue(q.isEmpty());
65 <        for (int i = n-1; i >= 0; i-=2)
65 >        for (int i = n-1; i >= 0; i -= 2)
66              assertTrue(q.offer(new Integer(i)));
67 <        for (int i = (n & 1); i < n; i+=2)
67 >        for (int i = (n & 1); i < n; i += 2)
68              assertTrue(q.offer(new Integer(i)));
69          assertFalse(q.isEmpty());
70 <        assertEquals(NOCAP, q.remainingCapacity());
70 >        assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
71          assertEquals(n, q.size());
72          return q;
73      }
# Line 78 | Line 76 | public class PriorityBlockingQueueTest e
76       * A new queue has unbounded capacity
77       */
78      public void testConstructor1() {
79 <        assertEquals(NOCAP, new PriorityBlockingQueue(SIZE).remainingCapacity());
79 >        assertEquals(Integer.MAX_VALUE,
80 >                     new PriorityBlockingQueue(SIZE).remainingCapacity());
81      }
82  
83      /**
# Line 159 | Line 158 | public class PriorityBlockingQueueTest e
158      public void testEmpty() {
159          PriorityBlockingQueue q = new PriorityBlockingQueue(2);
160          assertTrue(q.isEmpty());
161 <        assertEquals(NOCAP, q.remainingCapacity());
161 >        assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
162          q.add(one);
163          assertFalse(q.isEmpty());
164          q.add(two);
# Line 169 | Line 168 | public class PriorityBlockingQueueTest e
168      }
169  
170      /**
171 <     * remainingCapacity does not change when elements added or removed,
173 <     * but size does
171 >     * remainingCapacity() always returns Integer.MAX_VALUE
172       */
173      public void testRemainingCapacity() {
174 <        PriorityBlockingQueue q = populatedQueue(SIZE);
174 >        BlockingQueue q = populatedQueue(SIZE);
175          for (int i = 0; i < SIZE; ++i) {
176 <            assertEquals(NOCAP, q.remainingCapacity());
177 <            assertEquals(SIZE-i, q.size());
178 <            q.remove();
176 >            assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
177 >            assertEquals(SIZE - i, q.size());
178 >            assertEquals(i, q.remove());
179          }
180          for (int i = 0; i < SIZE; ++i) {
181 <            assertEquals(NOCAP, q.remainingCapacity());
181 >            assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
182              assertEquals(i, q.size());
183 <            q.add(new Integer(i));
183 >            assertTrue(q.add(i));
184          }
185      }
186  
# Line 266 | Line 264 | public class PriorityBlockingQueueTest e
264      public void testPut() {
265          PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
266          for (int i = 0; i < SIZE; ++i) {
267 <            Integer I = new Integer(i);
268 <            q.put(I);
269 <            assertTrue(q.contains(I));
267 >            Integer x = new Integer(i);
268 >            q.put(x);
269 >            assertTrue(q.contains(x));
270          }
271          assertEquals(SIZE, q.size());
272      }
# Line 530 | Line 528 | public class PriorityBlockingQueueTest e
528              assertTrue(q.removeAll(p));
529              assertEquals(SIZE-i, q.size());
530              for (int j = 0; j < i; ++j) {
531 <                Integer I = (Integer)(p.remove());
532 <                assertFalse(q.contains(I));
531 >                Integer x = (Integer)(p.remove());
532 >                assertFalse(q.contains(x));
533              }
534          }
535      }
# Line 576 | Line 574 | public class PriorityBlockingQueueTest e
574       */
575      public void testIterator() {
576          PriorityBlockingQueue q = populatedQueue(SIZE);
579        int i = 0;
577          Iterator it = q.iterator();
578 <        while (it.hasNext()) {
578 >        int i;
579 >        for (i = 0; it.hasNext(); i++)
580              assertTrue(q.contains(it.next()));
583            ++i;
584        }
581          assertEquals(i, SIZE);
582 +        assertIteratorExhausted(it);
583 +    }
584 +
585 +    /**
586 +     * iterator of empty collection has no elements
587 +     */
588 +    public void testEmptyIterator() {
589 +        assertIteratorExhausted(new PriorityBlockingQueue().iterator());
590      }
591  
592      /**
# Line 714 | Line 718 | public class PriorityBlockingQueueTest e
718              assertEquals(SIZE-k, q.size());
719              for (int j = 0; j < k; ++j)
720                  assertEquals(l.get(j), new Integer(j));
721 <            while (q.poll() != null) ;
721 >            do {} while (q.poll() != null);
722          }
723      }
724  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines