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.13 by jsr166, Sat Nov 21 10:25:05 2009 UTC vs.
Revision 1.22 by jsr166, Thu Nov 4 01:04:54 2010 UTC

# Line 14 | Line 14 | import java.io.*;
14   public class ConcurrentLinkedQueueTest extends JSR166TestCase {
15  
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19  
20      public static Test suite() {
# Line 43 | Line 43 | public class ConcurrentLinkedQueueTest e
43      }
44  
45      /**
46 <     *  Initializing from null Collection throws NPE
46 >     * Initializing from null Collection throws NPE
47       */
48      public void testConstructor3() {
49          try {
# Line 73 | Line 73 | public class ConcurrentLinkedQueueTest e
73                  ints[i] = new Integer(i);
74              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
75              shouldThrow();
76 <        }
77 <        catch (NullPointerException success) {}
76 >        } catch (NullPointerException success) {}
77      }
78  
79      /**
80       * Queue contains all elements of collection used to initialize
81       */
82      public void testConstructor6() {
83 <        try {
84 <            Integer[] ints = new Integer[SIZE];
85 <            for (int i = 0; i < SIZE; ++i)
86 <                ints[i] = new Integer(i);
87 <            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
88 <            for (int i = 0; i < SIZE; ++i)
90 <                assertEquals(ints[i], q.poll());
91 <        }
92 <        finally {}
83 >        Integer[] ints = new Integer[SIZE];
84 >        for (int i = 0; i < SIZE; ++i)
85 >            ints[i] = new Integer(i);
86 >        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
87 >        for (int i = 0; i < SIZE; ++i)
88 >            assertEquals(ints[i], q.poll());
89      }
90  
91      /**
# Line 197 | Line 193 | public class ConcurrentLinkedQueueTest e
193              shouldThrow();
194          } catch (NullPointerException success) {}
195      }
196 +
197      /**
198 <     *  addAll of a collection with any null elements throws NPE after
198 >     * addAll of a collection with any null elements throws NPE after
199       * possibly adding some elements
200       */
201      public void testAddAll3() {
# Line 216 | Line 213 | public class ConcurrentLinkedQueueTest e
213       * Queue contains all elements, in traversal order, of successful addAll
214       */
215      public void testAddAll5() {
216 <        try {
217 <            Integer[] empty = new Integer[0];
218 <            Integer[] ints = new Integer[SIZE];
219 <            for (int i = 0; i < SIZE; ++i)
220 <                ints[i] = new Integer(i);
221 <            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
222 <            assertFalse(q.addAll(Arrays.asList(empty)));
223 <            assertTrue(q.addAll(Arrays.asList(ints)));
224 <            for (int i = 0; i < SIZE; ++i)
228 <                assertEquals(ints[i], q.poll());
229 <        }
230 <        finally {}
216 >        Integer[] empty = new Integer[0];
217 >        Integer[] ints = new Integer[SIZE];
218 >        for (int i = 0; i < SIZE; ++i)
219 >            ints[i] = new Integer(i);
220 >        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
221 >        assertFalse(q.addAll(Arrays.asList(empty)));
222 >        assertTrue(q.addAll(Arrays.asList(ints)));
223 >        for (int i = 0; i < SIZE; ++i)
224 >            assertEquals(ints[i], q.poll());
225      }
226  
227      /**
# Line 236 | Line 230 | public class ConcurrentLinkedQueueTest e
230      public void testPoll() {
231          ConcurrentLinkedQueue q = populatedQueue(SIZE);
232          for (int i = 0; i < SIZE; ++i) {
233 <            assertEquals(i, ((Integer)q.poll()).intValue());
233 >            assertEquals(i, q.poll());
234          }
235          assertNull(q.poll());
236      }
# Line 247 | Line 241 | public class ConcurrentLinkedQueueTest e
241      public void testPeek() {
242          ConcurrentLinkedQueue q = populatedQueue(SIZE);
243          for (int i = 0; i < SIZE; ++i) {
244 <            assertEquals(i, ((Integer)q.peek()).intValue());
245 <            q.poll();
244 >            assertEquals(i, q.peek());
245 >            assertEquals(i, q.poll());
246              assertTrue(q.peek() == null ||
247 <                       i != ((Integer)q.peek()).intValue());
247 >                       !q.peek().equals(i));
248          }
249          assertNull(q.peek());
250      }
# Line 261 | Line 255 | public class ConcurrentLinkedQueueTest e
255      public void testElement() {
256          ConcurrentLinkedQueue q = populatedQueue(SIZE);
257          for (int i = 0; i < SIZE; ++i) {
258 <            assertEquals(i, ((Integer)q.element()).intValue());
259 <            q.poll();
258 >            assertEquals(i, q.element());
259 >            assertEquals(i, q.poll());
260          }
261          try {
262              q.element();
# Line 271 | Line 265 | public class ConcurrentLinkedQueueTest e
265      }
266  
267      /**
268 <     *  remove removes next element, or throws NSEE if empty
268 >     * remove removes next element, or throws NSEE if empty
269       */
270      public void testRemove() {
271          ConcurrentLinkedQueue q = populatedQueue(SIZE);
272          for (int i = 0; i < SIZE; ++i) {
273 <            assertEquals(i, ((Integer)q.remove()).intValue());
273 >            assertEquals(i, q.remove());
274          }
275          try {
276              q.remove();
# Line 375 | Line 369 | public class ConcurrentLinkedQueueTest e
369      }
370  
371      /**
372 <     * toArray contains all elements
372 >     * toArray contains all elements in FIFO order
373       */
374      public void testToArray() {
375          ConcurrentLinkedQueue q = populatedQueue(SIZE);
376          Object[] o = q.toArray();
383        Arrays.sort(o);
377          for (int i = 0; i < o.length; i++)
378 <            assertEquals(o[i], q.poll());
378 >            assertSame(o[i], q.poll());
379      }
380  
381      /**
382 <     *  toArray(a) contains all elements
382 >     * toArray(a) contains all elements in FIFO order
383       */
384      public void testToArray2() {
385          ConcurrentLinkedQueue q = populatedQueue(SIZE);
386          Integer[] ints = new Integer[SIZE];
387 <        ints = (Integer[])q.toArray(ints);
395 <        Arrays.sort(ints);
387 >        assertSame(ints, q.toArray(ints));
388          for (int i = 0; i < ints.length; i++)
389 <            assertEquals(ints[i], q.poll());
389 >            assertSame(ints[i], q.poll());
390      }
391  
392      /**
393 <     * toArray(null) throws NPE
393 >     * toArray(null) throws NullPointerException
394       */
395 <    public void testToArray_BadArg() {
395 >    public void testToArray_NullArg() {
396 >        ConcurrentLinkedQueue q = populatedQueue(SIZE);
397          try {
398 <            ConcurrentLinkedQueue q = populatedQueue(SIZE);
406 <            Object o[] = q.toArray(null);
398 >            q.toArray(null);
399              shouldThrow();
400          } catch (NullPointerException success) {}
401      }
402  
403      /**
404 <     * toArray with incompatible array type throws ArrayStoreException
404 >     * toArray(incompatible array type) throws ArrayStoreException
405       */
406      public void testToArray1_BadArg() {
407 +        ConcurrentLinkedQueue q = populatedQueue(SIZE);
408          try {
409 <            ConcurrentLinkedQueue q = populatedQueue(SIZE);
417 <            Object o[] = q.toArray(new String[10] );
409 >            q.toArray(new String[10]);
410              shouldThrow();
411          } catch (ArrayStoreException success) {}
412      }
413  
414      /**
415 <     *  iterator iterates through all elements
415 >     * iterator iterates through all elements
416       */
417      public void testIterator() {
418          ConcurrentLinkedQueue q = populatedQueue(SIZE);
# Line 444 | Line 436 | public class ConcurrentLinkedQueueTest e
436  
437          int k = 0;
438          for (Iterator it = q.iterator(); it.hasNext();) {
439 <            int i = ((Integer)(it.next())).intValue();
448 <            assertEquals(++k, i);
439 >            assertEquals(++k, it.next());
440          }
441  
442          assertEquals(3, k);
# Line 454 | Line 445 | public class ConcurrentLinkedQueueTest e
445      /**
446       * Modifications do not cause iterators to fail
447       */
448 <    public void testWeaklyConsistentIteration () {
448 >    public void testWeaklyConsistentIteration() {
449          final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
450          q.add(one);
451          q.add(two);
# Line 471 | Line 462 | public class ConcurrentLinkedQueueTest e
462      /**
463       * iterator.remove removes current element
464       */
465 <    public void testIteratorRemove () {
465 >    public void testIteratorRemove() {
466          final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
467          q.add(one);
468          q.add(two);
# Line 480 | Line 471 | public class ConcurrentLinkedQueueTest e
471          it.next();
472          it.remove();
473          it = q.iterator();
474 <        assertEquals(it.next(), two);
475 <        assertEquals(it.next(), three);
474 >        assertSame(it.next(), two);
475 >        assertSame(it.next(), three);
476          assertFalse(it.hasNext());
477      }
478  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines