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

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.44 by jsr166, Fri May 27 20:07:24 2011 UTC vs.
Revision 1.46 by jsr166, Tue May 31 16:16:24 2011 UTC

# Line 7 | Line 7
7   */
8  
9   import junit.framework.*;
10 < import java.util.*;
11 < import java.util.concurrent.*;
10 > import java.util.Arrays;
11 > import java.util.ArrayList;
12 > import java.util.Collection;
13 > import java.util.Comparator;
14 > import java.util.Iterator;
15 > import java.util.NoSuchElementException;
16 > import java.util.Queue;
17 > import java.util.concurrent.PriorityBlockingQueue;
18 > import java.util.concurrent.BlockingQueue;
19 > import java.util.concurrent.CountDownLatch;
20 > import java.util.concurrent.Executors;
21 > import java.util.concurrent.ExecutorService;
22   import static java.util.concurrent.TimeUnit.MILLISECONDS;
13 import java.io.*;
23  
24   public class PriorityBlockingQueueTest extends JSR166TestCase {
25  
# Line 75 | Line 84 | public class PriorityBlockingQueueTest e
84       */
85      public void testConstructor2() {
86          try {
87 <            PriorityBlockingQueue q = new PriorityBlockingQueue(0);
87 >            new PriorityBlockingQueue(0);
88              shouldThrow();
89          } catch (IllegalArgumentException success) {}
90      }
# Line 85 | Line 94 | public class PriorityBlockingQueueTest e
94       */
95      public void testConstructor3() {
96          try {
97 <            PriorityBlockingQueue q = new PriorityBlockingQueue(null);
97 >            new PriorityBlockingQueue(null);
98              shouldThrow();
99          } catch (NullPointerException success) {}
100      }
# Line 94 | Line 103 | public class PriorityBlockingQueueTest e
103       * Initializing from Collection of null elements throws NPE
104       */
105      public void testConstructor4() {
106 +        Collection<Integer> elements = Arrays.asList(new Integer[SIZE]);
107          try {
108 <            Integer[] ints = new Integer[SIZE];
99 <            PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints));
108 >            new PriorityBlockingQueue(elements);
109              shouldThrow();
110          } catch (NullPointerException success) {}
111      }
# Line 105 | Line 114 | public class PriorityBlockingQueueTest e
114       * Initializing from Collection with some null elements throws NPE
115       */
116      public void testConstructor5() {
117 +        Integer[] ints = new Integer[SIZE];
118 +        for (int i = 0; i < SIZE-1; ++i)
119 +            ints[i] = i;
120 +        Collection<Integer> elements = Arrays.asList(ints);
121          try {
122 <            Integer[] ints = new Integer[SIZE];
110 <            for (int i = 0; i < SIZE-1; ++i)
111 <                ints[i] = new Integer(i);
112 <            PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints));
122 >            new PriorityBlockingQueue(elements);
123              shouldThrow();
124          } catch (NullPointerException success) {}
125      }
# Line 120 | Line 130 | public class PriorityBlockingQueueTest e
130      public void testConstructor6() {
131          Integer[] ints = new Integer[SIZE];
132          for (int i = 0; i < SIZE; ++i)
133 <            ints[i] = new Integer(i);
133 >            ints[i] = i;
134          PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints));
135          for (int i = 0; i < SIZE; ++i)
136              assertEquals(ints[i], q.poll());
# Line 175 | Line 185 | public class PriorityBlockingQueueTest e
185      }
186  
187      /**
178     * offer(null) throws NPE
179     */
180    public void testOfferNull() {
181        try {
182            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
183            q.offer(null);
184            shouldThrow();
185        } catch (NullPointerException success) {}
186    }
187
188    /**
189     * add(null) throws NPE
190     */
191    public void testAddNull() {
192        try {
193            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
194            q.add(null);
195            shouldThrow();
196        } catch (NullPointerException success) {}
197    }
198
199    /**
188       * Offer of comparable element succeeds
189       */
190      public void testOffer() {
# Line 230 | Line 218 | public class PriorityBlockingQueueTest e
218      }
219  
220      /**
233     * addAll(null) throws NPE
234     */
235    public void testAddAll1() {
236        try {
237            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
238            q.addAll(null);
239            shouldThrow();
240        } catch (NullPointerException success) {}
241    }
242
243    /**
221       * addAll(this) throws IAE
222       */
223      public void testAddAllSelf() {
# Line 252 | Line 229 | public class PriorityBlockingQueueTest e
229      }
230  
231      /**
255     * addAll of a collection with null elements throws NPE
256     */
257    public void testAddAll2() {
258        try {
259            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
260            Integer[] ints = new Integer[SIZE];
261            q.addAll(Arrays.asList(ints));
262            shouldThrow();
263        } catch (NullPointerException success) {}
264    }
265
266    /**
232       * addAll of a collection with any null elements throws NPE after
233       * possibly adding some elements
234       */
# Line 294 | Line 259 | public class PriorityBlockingQueueTest e
259      }
260  
261      /**
297     * put(null) throws NPE
298     */
299    public void testPutNull() {
300        try {
301            PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
302            q.put(null);
303            shouldThrow();
304        } catch (NullPointerException success) {}
305    }
306
307    /**
262       * all elements successfully put are contained
263       */
264      public void testPut() {
# Line 626 | Line 580 | public class PriorityBlockingQueueTest e
580      }
581  
582      /**
629     * toArray(null) throws NullPointerException
630     */
631    public void testToArray_NullArg() {
632        PriorityBlockingQueue q = populatedQueue(SIZE);
633        try {
634            q.toArray(null);
635            shouldThrow();
636        } catch (NullPointerException success) {}
637    }
638
639    /**
583       * toArray(incompatible array type) throws ArrayStoreException
584       */
585      public void testToArray1_BadArg() {
# Line 719 | Line 662 | public class PriorityBlockingQueueTest e
662       * A deserialized serialized queue has same elements
663       */
664      public void testSerialization() throws Exception {
665 <        PriorityBlockingQueue q = populatedQueue(SIZE);
666 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
724 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
725 <        out.writeObject(q);
726 <        out.close();
665 >        Queue x = populatedQueue(SIZE);
666 >        Queue y = serialClone(x);
667  
668 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
669 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
670 <        PriorityBlockingQueue r = (PriorityBlockingQueue)in.readObject();
671 <        assertEquals(q.size(), r.size());
672 <        while (!q.isEmpty())
673 <            assertEquals(q.remove(), r.remove());
674 <    }
735 <
736 <    /**
737 <     * drainTo(null) throws NPE
738 <     */
739 <    public void testDrainToNull() {
740 <        PriorityBlockingQueue q = populatedQueue(SIZE);
741 <        try {
742 <            q.drainTo(null);
743 <            shouldThrow();
744 <        } catch (NullPointerException success) {}
745 <    }
746 <
747 <    /**
748 <     * drainTo(this) throws IAE
749 <     */
750 <    public void testDrainToSelf() {
751 <        PriorityBlockingQueue q = populatedQueue(SIZE);
752 <        try {
753 <            q.drainTo(q);
754 <            shouldThrow();
755 <        } catch (IllegalArgumentException success) {}
668 >        assertTrue(x != y);
669 >        assertEquals(x.size(), y.size());
670 >        while (!x.isEmpty()) {
671 >            assertFalse(y.isEmpty());
672 >            assertEquals(x.remove(), y.remove());
673 >        }
674 >        assertTrue(y.isEmpty());
675      }
676  
677      /**
# Line 800 | Line 719 | public class PriorityBlockingQueueTest e
719      }
720  
721      /**
803     * drainTo(null, n) throws NPE
804     */
805    public void testDrainToNullN() {
806        PriorityBlockingQueue q = populatedQueue(SIZE);
807        try {
808            q.drainTo(null, 0);
809            shouldThrow();
810        } catch (NullPointerException success) {}
811    }
812
813    /**
814     * drainTo(this, n) throws IAE
815     */
816    public void testDrainToSelfN() {
817        PriorityBlockingQueue q = populatedQueue(SIZE);
818        try {
819            q.drainTo(q, 0);
820            shouldThrow();
821        } catch (IllegalArgumentException success) {}
822    }
823
824    /**
722       * drainTo(c, n) empties first min(n, size) elements of queue into c
723       */
724      public void testDrainToN() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines