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.20 by jsr166, Wed Nov 3 07:54:52 2010 UTC vs.
Revision 1.26 by jsr166, Fri May 27 19:49:56 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# 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 139 | Line 139 | public class ConcurrentLinkedQueueTest e
139          } catch (NullPointerException success) {}
140      }
141  
142
142      /**
143       * Offer returns true
144       */
# Line 284 | Line 283 | public class ConcurrentLinkedQueueTest e
283      public void testRemoveElement() {
284          ConcurrentLinkedQueue q = populatedQueue(SIZE);
285          for (int i = 1; i < SIZE; i+=2) {
286 <            assertTrue(q.remove(new Integer(i)));
286 >            assertTrue(q.contains(i));
287 >            assertTrue(q.remove(i));
288 >            assertFalse(q.contains(i));
289 >            assertTrue(q.contains(i-1));
290          }
291          for (int i = 0; i < SIZE; i+=2) {
292 <            assertTrue(q.remove(new Integer(i)));
293 <            assertFalse(q.remove(new Integer(i+1)));
292 >            assertTrue(q.contains(i));
293 >            assertTrue(q.remove(i));
294 >            assertFalse(q.contains(i));
295 >            assertFalse(q.remove(i+1));
296 >            assertFalse(q.contains(i+1));
297          }
298          assertTrue(q.isEmpty());
299      }
# Line 369 | Line 374 | public class ConcurrentLinkedQueueTest e
374      }
375  
376      /**
377 <     * toArray contains all elements
377 >     * toArray contains all elements in FIFO order
378       */
379      public void testToArray() {
380          ConcurrentLinkedQueue q = populatedQueue(SIZE);
381          Object[] o = q.toArray();
377        Arrays.sort(o);
382          for (int i = 0; i < o.length; i++)
383 <            assertEquals(o[i], q.poll());
383 >            assertSame(o[i], q.poll());
384      }
385  
386      /**
387 <     * toArray(a) contains all elements
387 >     * toArray(a) contains all elements in FIFO order
388       */
389      public void testToArray2() {
390 <        ConcurrentLinkedQueue q = populatedQueue(SIZE);
390 >        ConcurrentLinkedQueue<Integer> q = populatedQueue(SIZE);
391          Integer[] ints = new Integer[SIZE];
392 <        ints = (Integer[])q.toArray(ints);
393 <        Arrays.sort(ints);
392 >        Integer[] array = q.toArray(ints);
393 >        assertSame(ints, array);
394          for (int i = 0; i < ints.length; i++)
395 <            assertEquals(ints[i], q.poll());
395 >            assertSame(ints[i], q.poll());
396      }
397  
398      /**
399 <     * toArray(null) throws NPE
399 >     * toArray(null) throws NullPointerException
400       */
401 <    public void testToArray_BadArg() {
401 >    public void testToArray_NullArg() {
402          ConcurrentLinkedQueue q = populatedQueue(SIZE);
403          try {
404 <            Object o[] = q.toArray(null);
404 >            q.toArray(null);
405              shouldThrow();
406          } catch (NullPointerException success) {}
407      }
# Line 478 | Line 482 | public class ConcurrentLinkedQueueTest e
482          assertFalse(it.hasNext());
483      }
484  
481
485      /**
486       * toString contains toStrings of elements
487       */
# Line 486 | Line 489 | public class ConcurrentLinkedQueueTest e
489          ConcurrentLinkedQueue q = populatedQueue(SIZE);
490          String s = q.toString();
491          for (int i = 0; i < SIZE; ++i) {
492 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
492 >            assertTrue(s.contains(String.valueOf(i)));
493          }
494      }
495  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines