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.23 by jsr166, Fri Nov 5 00:17:22 2010 UTC vs.
Revision 1.30 by jsr166, Thu May 30 03:28:55 2013 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   */
8  
9   import junit.framework.*;
10 < import java.util.*;
11 < import java.util.concurrent.*;
12 < import java.io.*;
10 > import java.util.Arrays;
11 > import java.util.Collection;
12 > import java.util.Iterator;
13 > import java.util.NoSuchElementException;
14 > import java.util.Queue;
15 > import java.util.concurrent.ConcurrentLinkedQueue;
16  
17   public class ConcurrentLinkedQueueTest extends JSR166TestCase {
18  
# Line 22 | Line 25 | public class ConcurrentLinkedQueueTest e
25      }
26  
27      /**
28 <     * Create a queue of given size containing consecutive
28 >     * Returns a new queue of given size containing consecutive
29       * Integers 0 ... n.
30       */
31      private ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
# Line 139 | Line 142 | public class ConcurrentLinkedQueueTest e
142          } catch (NullPointerException success) {}
143      }
144  
142
145      /**
146       * Offer returns true
147       */
# Line 284 | Line 286 | public class ConcurrentLinkedQueueTest e
286      public void testRemoveElement() {
287          ConcurrentLinkedQueue q = populatedQueue(SIZE);
288          for (int i = 1; i < SIZE; i+=2) {
289 <            assertTrue(q.remove(new Integer(i)));
289 >            assertTrue(q.contains(i));
290 >            assertTrue(q.remove(i));
291 >            assertFalse(q.contains(i));
292 >            assertTrue(q.contains(i-1));
293          }
294          for (int i = 0; i < SIZE; i+=2) {
295 <            assertTrue(q.remove(new Integer(i)));
296 <            assertFalse(q.remove(new Integer(i+1)));
295 >            assertTrue(q.contains(i));
296 >            assertTrue(q.remove(i));
297 >            assertFalse(q.contains(i));
298 >            assertFalse(q.remove(i+1));
299 >            assertFalse(q.contains(i+1));
300          }
301          assertTrue(q.isEmpty());
302      }
# Line 477 | Line 485 | public class ConcurrentLinkedQueueTest e
485          assertFalse(it.hasNext());
486      }
487  
480
488      /**
489       * toString contains toStrings of elements
490       */
# Line 485 | Line 492 | public class ConcurrentLinkedQueueTest e
492          ConcurrentLinkedQueue q = populatedQueue(SIZE);
493          String s = q.toString();
494          for (int i = 0; i < SIZE; ++i) {
495 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
495 >            assertTrue(s.contains(String.valueOf(i)));
496          }
497      }
498  
# Line 493 | Line 500 | public class ConcurrentLinkedQueueTest e
500       * A deserialized serialized queue has same elements in same order
501       */
502      public void testSerialization() throws Exception {
503 <        ConcurrentLinkedQueue q = populatedQueue(SIZE);
504 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
505 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
506 <        out.writeObject(q);
507 <        out.close();
508 <
509 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
510 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
511 <        ConcurrentLinkedQueue r = (ConcurrentLinkedQueue)in.readObject();
512 <        assertEquals(q.size(), r.size());
513 <        while (!q.isEmpty())
514 <            assertEquals(q.remove(), r.remove());
503 >        Queue x = populatedQueue(SIZE);
504 >        Queue y = serialClone(x);
505 >
506 >        assertNotSame(x, y);
507 >        assertEquals(x.size(), y.size());
508 >        assertEquals(x.toString(), y.toString());
509 >        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
510 >        while (!x.isEmpty()) {
511 >            assertFalse(y.isEmpty());
512 >            assertEquals(x.remove(), y.remove());
513 >        }
514 >        assertTrue(y.isEmpty());
515      }
516  
517   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines