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

Comparing jsr166/src/test/tck/BlockingQueueTest.java (file contents):
Revision 1.10 by jsr166, Tue Jun 14 03:22:38 2011 UTC vs.
Revision 1.12 by jsr166, Fri Jul 15 18:49:31 2011 UTC

# Line 181 | Line 181 | public abstract class BlockingQueueTest
181      }
182  
183      /**
184 <     * drainTo(c, -n) returns 0
184 >     * drainTo(c, n) returns 0 and does nothing when n <= 0
185       */
186 <    public void testDrainToNegativeMaxElements() {
186 >    public void testDrainToNonPositiveMaxElements() {
187          final BlockingQueue q = emptyCollection();
188 <        assertEquals(0, q.drainTo(new ArrayList(), -42));
189 <    }
190 <
191 <    /**
192 <     * drainTo(c, 0) returns 0 and does nothing
193 <     */
194 <    public void testDrainToZeroMaxElements() {
195 <        final BlockingQueue q = emptyCollection();
196 <        if (q.remainingCapacity() == 0) {
197 <            // SynchronousQueue, for example
198 <            assertEquals(0, q.drainTo(new ArrayList(), 0));
199 <        } else {
188 >        final int[] ns = { 0, -1, -42, Integer.MIN_VALUE };
189 >        for (int n : ns)
190 >            assertEquals(0, q.drainTo(new ArrayList(), n));
191 >        if (q.remainingCapacity() > 0) {
192 >            // Not SynchronousQueue, that is
193              Object one = makeElement(1);
194              q.add(one);
195              ArrayList c = new ArrayList();
196 <            assertEquals(0, q.drainTo(c, 0));
196 >            for (int n : ns)
197 >                assertEquals(0, q.drainTo(new ArrayList(), n));
198              assertEquals(1, q.size());
199              assertSame(one, q.poll());
200              assertTrue(c.isEmpty());
# Line 333 | Line 327 | public abstract class BlockingQueueTest
327          awaitTermination(t);
328      }
329  
330 +    /**
331 +     * remove(x) removes x and returns true if present
332 +     * TODO: move to superclass CollectionTest.java
333 +     */
334 +    public void testRemoveElement() {
335 +        final BlockingQueue q = emptyCollection();
336 +        final int size = Math.min(q.remainingCapacity(), SIZE);
337 +        final Object[] elts = new Object[size];
338 +        assertFalse(q.contains(makeElement(99)));
339 +        assertFalse(q.remove(makeElement(99)));
340 +        checkEmpty(q);
341 +        for (int i = 0; i < size; i++)
342 +            q.add(elts[i] = makeElement(i));
343 +        for (int i = 1; i < size; i+=2) {
344 +            for (int pass = 0; pass < 2; pass++) {
345 +                assertEquals((pass == 0), q.contains(elts[i]));
346 +                assertEquals((pass == 0), q.remove(elts[i]));
347 +                assertFalse(q.contains(elts[i]));
348 +                assertTrue(q.contains(elts[i-1]));
349 +                if (i < size - 1)
350 +                    assertTrue(q.contains(elts[i+1]));
351 +            }
352 +        }
353 +        if (size > 0)
354 +            assertTrue(q.contains(elts[0]));
355 +        for (int i = size-2; i >= 0; i-=2) {
356 +            assertTrue(q.contains(elts[i]));
357 +            assertFalse(q.contains(elts[i+1]));
358 +            assertTrue(q.remove(elts[i]));
359 +            assertFalse(q.contains(elts[i]));
360 +            assertFalse(q.remove(elts[i+1]));
361 +            assertFalse(q.contains(elts[i+1]));
362 +        }
363 +        checkEmpty(q);
364 +    }
365 +
366      /** For debugging. */
367      public void XXXXtestFails() {
368          fail(emptyCollection().getClass().toString());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines