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

Comparing jsr166/src/test/tck/ConcurrentLinkedQueueTest.java (file contents):
Revision 1.19 by jsr166, Sat Oct 9 19:30:34 2010 UTC vs.
Revision 1.24 by jsr166, Thu Nov 18 20:21:53 2010 UTC

# Line 25 | Line 25 | public class ConcurrentLinkedQueueTest e
25       * Create a queue of given size containing consecutive
26       * Integers 0 ... n.
27       */
28 <    private ConcurrentLinkedQueue populatedQueue(int n) {
29 <        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
28 >    private ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
29 >        ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<Integer>();
30          assertTrue(q.isEmpty());
31          for (int i = 0; i < n; ++i)
32              assertTrue(q.offer(new Integer(i)));
# Line 284 | Line 284 | public class ConcurrentLinkedQueueTest e
284      public void testRemoveElement() {
285          ConcurrentLinkedQueue q = populatedQueue(SIZE);
286          for (int i = 1; i < SIZE; i+=2) {
287 <            assertTrue(q.remove(new Integer(i)));
287 >            assertTrue(q.contains(i));
288 >            assertTrue(q.remove(i));
289 >            assertFalse(q.contains(i));
290 >            assertTrue(q.contains(i-1));
291          }
292          for (int i = 0; i < SIZE; i+=2) {
293 <            assertTrue(q.remove(new Integer(i)));
294 <            assertFalse(q.remove(new Integer(i+1)));
293 >            assertTrue(q.contains(i));
294 >            assertTrue(q.remove(i));
295 >            assertFalse(q.contains(i));
296 >            assertFalse(q.remove(i+1));
297 >            assertFalse(q.contains(i+1));
298          }
299          assertTrue(q.isEmpty());
300      }
# Line 369 | Line 375 | public class ConcurrentLinkedQueueTest e
375      }
376  
377      /**
378 <     * toArray contains all elements
378 >     * toArray contains all elements in FIFO order
379       */
380      public void testToArray() {
381          ConcurrentLinkedQueue q = populatedQueue(SIZE);
382          Object[] o = q.toArray();
377        Arrays.sort(o);
383          for (int i = 0; i < o.length; i++)
384 <            assertEquals(o[i], q.poll());
384 >            assertSame(o[i], q.poll());
385      }
386  
387      /**
388 <     * toArray(a) contains all elements
388 >     * toArray(a) contains all elements in FIFO order
389       */
390      public void testToArray2() {
391 <        ConcurrentLinkedQueue q = populatedQueue(SIZE);
391 >        ConcurrentLinkedQueue<Integer> q = populatedQueue(SIZE);
392          Integer[] ints = new Integer[SIZE];
393 <        ints = (Integer[])q.toArray(ints);
394 <        Arrays.sort(ints);
393 >        Integer[] array = q.toArray(ints);
394 >        assertSame(ints, array);
395          for (int i = 0; i < ints.length; i++)
396 <            assertEquals(ints[i], q.poll());
396 >            assertSame(ints[i], q.poll());
397      }
398  
399      /**
400 <     * toArray(null) throws NPE
400 >     * toArray(null) throws NullPointerException
401       */
402 <    public void testToArray_BadArg() {
402 >    public void testToArray_NullArg() {
403          ConcurrentLinkedQueue q = populatedQueue(SIZE);
404          try {
405 <            Object o[] = q.toArray(null);
405 >            q.toArray(null);
406              shouldThrow();
407          } catch (NullPointerException success) {}
408      }
409  
410      /**
411 <     * toArray with incompatible array type throws ArrayStoreException
411 >     * toArray(incompatible array type) throws ArrayStoreException
412       */
413      public void testToArray1_BadArg() {
414          ConcurrentLinkedQueue q = populatedQueue(SIZE);
415          try {
416 <            Object o[] = q.toArray(new String[10]);
416 >            q.toArray(new String[10]);
417              shouldThrow();
418          } catch (ArrayStoreException success) {}
419      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines