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.12 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.16 by jsr166, Sun Nov 22 18:57:17 2009 UTC

# Line 49 | Line 49 | public class ConcurrentLinkedQueueTest e
49          try {
50              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue((Collection)null);
51              shouldThrow();
52 <        }
53 <        catch (NullPointerException success) {}
52 >        } catch (NullPointerException success) {}
53      }
54  
55      /**
# Line 61 | Line 60 | public class ConcurrentLinkedQueueTest e
60              Integer[] ints = new Integer[SIZE];
61              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
62              shouldThrow();
63 <        }
65 <        catch (NullPointerException success) {}
63 >        } catch (NullPointerException success) {}
64      }
65  
66      /**
# Line 75 | Line 73 | public class ConcurrentLinkedQueueTest e
73                  ints[i] = new Integer(i);
74              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
75              shouldThrow();
76 <        }
79 <        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)
92 <                assertEquals(ints[i], q.poll());
93 <        }
94 <        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 131 | Line 125 | public class ConcurrentLinkedQueueTest e
125              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
126              q.offer(null);
127              shouldThrow();
128 <        } catch (NullPointerException success) { }
128 >        } catch (NullPointerException success) {}
129      }
130  
131      /**
# Line 142 | Line 136 | public class ConcurrentLinkedQueueTest e
136              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
137              q.add(null);
138              shouldThrow();
139 <        } catch (NullPointerException success) { }
139 >        } catch (NullPointerException success) {}
140      }
141  
142  
# Line 174 | Line 168 | public class ConcurrentLinkedQueueTest e
168              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
169              q.addAll(null);
170              shouldThrow();
171 <        }
178 <        catch (NullPointerException success) {}
171 >        } catch (NullPointerException success) {}
172      }
173  
174      /**
# Line 186 | Line 179 | public class ConcurrentLinkedQueueTest e
179              ConcurrentLinkedQueue q = populatedQueue(SIZE);
180              q.addAll(q);
181              shouldThrow();
182 <        }
190 <        catch (IllegalArgumentException success) {}
182 >        } catch (IllegalArgumentException success) {}
183      }
184  
185      /**
# Line 199 | Line 191 | public class ConcurrentLinkedQueueTest e
191              Integer[] ints = new Integer[SIZE];
192              q.addAll(Arrays.asList(ints));
193              shouldThrow();
194 <        }
203 <        catch (NullPointerException success) {}
194 >        } catch (NullPointerException success) {}
195      }
196      /**
197       *  addAll of a collection with any null elements throws NPE after
# Line 214 | Line 205 | public class ConcurrentLinkedQueueTest e
205                  ints[i] = new Integer(i);
206              q.addAll(Arrays.asList(ints));
207              shouldThrow();
208 <        }
218 <        catch (NullPointerException success) {}
208 >        } catch (NullPointerException success) {}
209      }
210  
211      /**
212       * Queue contains all elements, in traversal order, of successful addAll
213       */
214      public void testAddAll5() {
215 <        try {
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)
234 <                assertEquals(ints[i], q.poll());
235 <        }
236 <        finally {}
215 >        Integer[] empty = new Integer[0];
216 >        Integer[] ints = new Integer[SIZE];
217 >        for (int i = 0; i < SIZE; ++i)
218 >            ints[i] = new Integer(i);
219 >        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
220 >        assertFalse(q.addAll(Arrays.asList(empty)));
221 >        assertTrue(q.addAll(Arrays.asList(ints)));
222 >        for (int i = 0; i < SIZE; ++i)
223 >            assertEquals(ints[i], q.poll());
224      }
225  
226      /**
# Line 242 | Line 229 | public class ConcurrentLinkedQueueTest e
229      public void testPoll() {
230          ConcurrentLinkedQueue q = populatedQueue(SIZE);
231          for (int i = 0; i < SIZE; ++i) {
232 <            assertEquals(i, ((Integer)q.poll()).intValue());
232 >            assertEquals(i, q.poll());
233          }
234          assertNull(q.poll());
235      }
# Line 253 | Line 240 | public class ConcurrentLinkedQueueTest e
240      public void testPeek() {
241          ConcurrentLinkedQueue q = populatedQueue(SIZE);
242          for (int i = 0; i < SIZE; ++i) {
243 <            assertEquals(i, ((Integer)q.peek()).intValue());
244 <            q.poll();
243 >            assertEquals(i, q.peek());
244 >            assertEquals(i, q.poll());
245              assertTrue(q.peek() == null ||
246 <                       i != ((Integer)q.peek()).intValue());
246 >                       !q.peek().equals(i));
247          }
248          assertNull(q.peek());
249      }
# Line 267 | Line 254 | public class ConcurrentLinkedQueueTest e
254      public void testElement() {
255          ConcurrentLinkedQueue q = populatedQueue(SIZE);
256          for (int i = 0; i < SIZE; ++i) {
257 <            assertEquals(i, ((Integer)q.element()).intValue());
258 <            q.poll();
257 >            assertEquals(i, q.element());
258 >            assertEquals(i, q.poll());
259          }
260          try {
261              q.element();
262              shouldThrow();
263 <        }
277 <        catch (NoSuchElementException success) {}
263 >        } catch (NoSuchElementException success) {}
264      }
265  
266      /**
# Line 283 | Line 269 | public class ConcurrentLinkedQueueTest e
269      public void testRemove() {
270          ConcurrentLinkedQueue q = populatedQueue(SIZE);
271          for (int i = 0; i < SIZE; ++i) {
272 <            assertEquals(i, ((Integer)q.remove()).intValue());
272 >            assertEquals(i, q.remove());
273          }
274          try {
275              q.remove();
276              shouldThrow();
277 <        } catch (NoSuchElementException success) {
292 <        }
277 >        } catch (NoSuchElementException success) {}
278      }
279  
280      /**
# Line 409 | Line 394 | public class ConcurrentLinkedQueueTest e
394       * toArray(null) throws NPE
395       */
396      public void testToArray_BadArg() {
397 +        ConcurrentLinkedQueue q = populatedQueue(SIZE);
398          try {
413            ConcurrentLinkedQueue q = populatedQueue(SIZE);
399              Object o[] = q.toArray(null);
400              shouldThrow();
401          } catch (NullPointerException success) {}
# Line 420 | Line 405 | public class ConcurrentLinkedQueueTest e
405       * toArray with incompatible array type throws ArrayStoreException
406       */
407      public void testToArray1_BadArg() {
408 +        ConcurrentLinkedQueue q = populatedQueue(SIZE);
409          try {
410 <            ConcurrentLinkedQueue q = populatedQueue(SIZE);
425 <            Object o[] = q.toArray(new String[10] );
410 >            Object o[] = q.toArray(new String[10]);
411              shouldThrow();
412          } catch (ArrayStoreException success) {}
413      }
# Line 452 | Line 437 | public class ConcurrentLinkedQueueTest e
437  
438          int k = 0;
439          for (Iterator it = q.iterator(); it.hasNext();) {
440 <            int i = ((Integer)(it.next())).intValue();
456 <            assertEquals(++k, i);
440 >            assertEquals(++k, it.next());
441          }
442  
443          assertEquals(3, k);
# Line 468 | Line 452 | public class ConcurrentLinkedQueueTest e
452          q.add(two);
453          q.add(three);
454  
455 <        try {
456 <            for (Iterator it = q.iterator(); it.hasNext();) {
457 <                q.remove();
474 <                it.next();
475 <            }
476 <        }
477 <        catch (ConcurrentModificationException e) {
478 <            shouldThrow();
455 >        for (Iterator it = q.iterator(); it.hasNext();) {
456 >            q.remove();
457 >            it.next();
458          }
459  
460          assertEquals("queue should be empty again", 0, q.size());
# Line 513 | Line 492 | public class ConcurrentLinkedQueueTest e
492      /**
493       * A deserialized serialized queue has same elements in same order
494       */
495 <    public void testSerialization() {
495 >    public void testSerialization() throws Exception {
496          ConcurrentLinkedQueue q = populatedQueue(SIZE);
497 <        try {
498 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
499 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
500 <            out.writeObject(q);
501 <            out.close();
502 <
503 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
504 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
505 <            ConcurrentLinkedQueue r = (ConcurrentLinkedQueue)in.readObject();
506 <            assertEquals(q.size(), r.size());
507 <            while (!q.isEmpty())
529 <                assertEquals(q.remove(), r.remove());
530 <        } catch (Exception e) {
531 <            unexpectedException();
532 <        }
497 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
498 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
499 >        out.writeObject(q);
500 >        out.close();
501 >
502 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
503 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
504 >        ConcurrentLinkedQueue r = (ConcurrentLinkedQueue)in.readObject();
505 >        assertEquals(q.size(), r.size());
506 >        while (!q.isEmpty())
507 >            assertEquals(q.remove(), r.remove());
508      }
509  
510   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines