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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.62 by jsr166, Sun Feb 22 04:34:44 2015 UTC vs.
Revision 1.66 by jsr166, Sat May 23 00:53:08 2015 UTC

# Line 37 | Line 37 | public class ArrayBlockingQueueTest exte
37      }
38  
39      public static void main(String[] args) {
40 <        junit.textui.TestRunner.run(suite());
40 >        main(suite(), args);
41      }
42  
43      public static Test suite() {
# Line 104 | Line 104 | public class ArrayBlockingQueueTest exte
104       */
105      public void testConstructor5() {
106          Integer[] ints = new Integer[SIZE];
107 <        for (int i = 0; i < SIZE-1; ++i)
107 >        for (int i = 0; i < SIZE - 1; ++i)
108              ints[i] = i;
109          Collection<Integer> elements = Arrays.asList(ints);
110          try {
# Line 159 | Line 159 | public class ArrayBlockingQueueTest exte
159       * remainingCapacity decreases on add, increases on remove
160       */
161      public void testRemainingCapacity() {
162 <        ArrayBlockingQueue q = populatedQueue(SIZE);
162 >        BlockingQueue q = populatedQueue(SIZE);
163          for (int i = 0; i < SIZE; ++i) {
164              assertEquals(i, q.remainingCapacity());
165 <            assertEquals(SIZE-i, q.size());
166 <            q.remove();
165 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
166 >            assertEquals(i, q.remove());
167          }
168          for (int i = 0; i < SIZE; ++i) {
169 <            assertEquals(SIZE-i, q.remainingCapacity());
170 <            assertEquals(i, q.size());
171 <            q.add(new Integer(i));
169 >            assertEquals(SIZE - i, q.remainingCapacity());
170 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
171 >            assertTrue(q.add(i));
172          }
173      }
174  
# Line 185 | Line 185 | public class ArrayBlockingQueueTest exte
185       * add succeeds if not full; throws ISE if full
186       */
187      public void testAdd() {
188 +        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
189 +        for (int i = 0; i < SIZE; ++i) {
190 +            assertTrue(q.add(new Integer(i)));
191 +        }
192 +        assertEquals(0, q.remainingCapacity());
193          try {
189            ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
190            for (int i = 0; i < SIZE; ++i) {
191                assertTrue(q.add(new Integer(i)));
192            }
193            assertEquals(0, q.remainingCapacity());
194              q.add(new Integer(SIZE));
195              shouldThrow();
196          } catch (IllegalStateException success) {}
# Line 200 | Line 200 | public class ArrayBlockingQueueTest exte
200       * addAll(this) throws IAE
201       */
202      public void testAddAllSelf() {
203 +        ArrayBlockingQueue q = populatedQueue(SIZE);
204          try {
204            ArrayBlockingQueue q = populatedQueue(SIZE);
205              q.addAll(q);
206              shouldThrow();
207          } catch (IllegalArgumentException success) {}
# Line 212 | Line 212 | public class ArrayBlockingQueueTest exte
212       * possibly adding some elements
213       */
214      public void testAddAll3() {
215 +        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
216 +        Integer[] ints = new Integer[SIZE];
217 +        for (int i = 0; i < SIZE - 1; ++i)
218 +            ints[i] = new Integer(i);
219          try {
216            ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
217            Integer[] ints = new Integer[SIZE];
218            for (int i = 0; i < SIZE-1; ++i)
219                ints[i] = new Integer(i);
220              q.addAll(Arrays.asList(ints));
221              shouldThrow();
222          } catch (NullPointerException success) {}
# Line 226 | Line 226 | public class ArrayBlockingQueueTest exte
226       * addAll throws ISE if not enough room
227       */
228      public void testAddAll4() {
229 +        ArrayBlockingQueue q = new ArrayBlockingQueue(1);
230 +        Integer[] ints = new Integer[SIZE];
231 +        for (int i = 0; i < SIZE; ++i)
232 +            ints[i] = new Integer(i);
233          try {
230            ArrayBlockingQueue q = new ArrayBlockingQueue(1);
231            Integer[] ints = new Integer[SIZE];
232            for (int i = 0; i < SIZE; ++i)
233                ints[i] = new Integer(i);
234              q.addAll(Arrays.asList(ints));
235              shouldThrow();
236          } catch (IllegalStateException success) {}
# Line 572 | Line 572 | public class ArrayBlockingQueueTest exte
572                  assertTrue(changed);
573  
574              assertTrue(q.containsAll(p));
575 <            assertEquals(SIZE-i, q.size());
575 >            assertEquals(SIZE - i, q.size());
576              p.remove();
577          }
578      }
# Line 585 | Line 585 | public class ArrayBlockingQueueTest exte
585              ArrayBlockingQueue q = populatedQueue(SIZE);
586              ArrayBlockingQueue p = populatedQueue(i);
587              assertTrue(q.removeAll(p));
588 <            assertEquals(SIZE-i, q.size());
588 >            assertEquals(SIZE - i, q.size());
589              for (int j = 0; j < i; ++j) {
590                  Integer x = (Integer)(p.remove());
591                  assertFalse(q.contains(x));
# Line 619 | Line 619 | public class ArrayBlockingQueueTest exte
619              checkToArray(q);
620              assertEquals(i, q.poll());
621              checkToArray(q);
622 <            q.add(SIZE+i);
622 >            q.add(SIZE + i);
623          }
624          for (int i = 0; i < SIZE; i++) {
625              checkToArray(q);
626 <            assertEquals(SIZE+i, q.poll());
626 >            assertEquals(SIZE + i, q.poll());
627          }
628      }
629  
# Line 673 | Line 673 | public class ArrayBlockingQueueTest exte
673              checkToArray2(q);
674              assertEquals(i, q.poll());
675              checkToArray2(q);
676 <            q.add(SIZE+i);
676 >            q.add(SIZE + i);
677          }
678          for (int i = 0; i < SIZE; i++) {
679              checkToArray2(q);
680 <            assertEquals(SIZE+i, q.poll());
680 >            assertEquals(SIZE + i, q.poll());
681          }
682      }
683  
# Line 881 | Line 881 | public class ArrayBlockingQueueTest exte
881          final ArrayBlockingQueue q = populatedQueue(SIZE);
882          Thread t = new Thread(new CheckedRunnable() {
883              public void realRun() throws InterruptedException {
884 <                q.put(new Integer(SIZE+1));
884 >                q.put(new Integer(SIZE + 1));
885              }});
886  
887          t.start();
# Line 898 | Line 898 | public class ArrayBlockingQueueTest exte
898       * drainTo(c, n) empties first min(n, size) elements of queue into c
899       */
900      public void testDrainToN() {
901 <        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2);
901 >        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE * 2);
902          for (int i = 0; i < SIZE + 2; ++i) {
903              for (int j = 0; j < SIZE; j++)
904                  assertTrue(q.offer(new Integer(j)));
# Line 906 | Line 906 | public class ArrayBlockingQueueTest exte
906              q.drainTo(l, i);
907              int k = (i < SIZE) ? i : SIZE;
908              assertEquals(k, l.size());
909 <            assertEquals(SIZE-k, q.size());
909 >            assertEquals(SIZE - k, q.size());
910              for (int j = 0; j < k; ++j)
911                  assertEquals(l.get(j), new Integer(j));
912              do {} while (q.poll() != null);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines