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.3 by dl, Sun Sep 14 20:42:40 2003 UTC vs.
Revision 1.4 by dl, Sat Sep 20 18:20:07 2003 UTC

# Line 34 | Line 34 | public class ConcurrentLinkedQueueTest e
34          return q;
35      }
36  
37 <    public void testConstructor1(){
37 >    /**
38 >     *
39 >     */
40 >    public void testConstructor1() {
41          assertEquals(0, new ConcurrentLinkedQueue().size());
42      }
43  
44 +    /**
45 +     *
46 +     */
47      public void testConstructor3() {
48          try {
49              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue((Collection)null);
50 <            fail("Cannot make from null collection");
50 >            shouldThrow();
51          }
52          catch (NullPointerException success) {}
53      }
54  
55 <    public void testConstructor4(){
55 >    /**
56 >     *
57 >     */
58 >    public void testConstructor4() {
59          try {
60              Integer[] ints = new Integer[SIZE];
61              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
62 <            fail("Cannot make with null elements");
62 >            shouldThrow();
63          }
64          catch (NullPointerException success) {}
65      }
66  
67 <    public void testConstructor5(){
67 >    /**
68 >     *
69 >     */
70 >    public void testConstructor5() {
71          try {
72              Integer[] ints = new Integer[SIZE];
73              for (int i = 0; i < SIZE-1; ++i)
74                  ints[i] = new Integer(i);
75              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
76 <            fail("Cannot make with null elements");
76 >            shouldThrow();
77          }
78          catch (NullPointerException success) {}
79      }
80  
81 <    public void testConstructor6(){
81 >    /**
82 >     *
83 >     */
84 >    public void testConstructor6() {
85          try {
86              Integer[] ints = new Integer[SIZE];
87              for (int i = 0; i < SIZE; ++i)
# Line 78 | Line 93 | public class ConcurrentLinkedQueueTest e
93          finally {}
94      }
95  
96 +    /**
97 +     *
98 +     */
99      public void testEmpty() {
100          ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
101          assertTrue(q.isEmpty());
# Line 89 | Line 107 | public class ConcurrentLinkedQueueTest e
107          assertTrue(q.isEmpty());
108      }
109  
110 +    /**
111 +     *
112 +     */
113      public void testSize() {
114          ConcurrentLinkedQueue q = populatedQueue(SIZE);
115          for (int i = 0; i < SIZE; ++i) {
# Line 101 | Line 122 | public class ConcurrentLinkedQueueTest e
122          }
123      }
124  
125 <    public void testOfferNull(){
125 >    /**
126 >     *
127 >     */
128 >    public void testOfferNull() {
129          try {
130              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
131              q.offer(null);
132 <            fail("should throw NPE");
132 >            shouldThrow();
133          } catch (NullPointerException success) { }  
134      }
135  
136 +    /**
137 +     *
138 +     */
139      public void testOffer() {
140          ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
141          assertTrue(q.offer(zero));
142          assertTrue(q.offer(one));
143      }
144  
145 <    public void testAdd(){
145 >    /**
146 >     *
147 >     */
148 >    public void testAdd() {
149          ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
150          for (int i = 0; i < SIZE; ++i) {
151              assertEquals(i, q.size());
# Line 123 | Line 153 | public class ConcurrentLinkedQueueTest e
153          }
154      }
155  
156 <    public void testAddAll1(){
156 >    /**
157 >     *
158 >     */
159 >    public void testAddAll1() {
160          try {
161              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
162              q.addAll(null);
163 <            fail("Cannot add null collection");
163 >            shouldThrow();
164          }
165          catch (NullPointerException success) {}
166      }
167 <    public void testAddAll2(){
167 >    /**
168 >     *
169 >     */
170 >    public void testAddAll2() {
171          try {
172              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
173              Integer[] ints = new Integer[SIZE];
174              q.addAll(Arrays.asList(ints));
175 <            fail("Cannot add null elements");
175 >            shouldThrow();
176          }
177          catch (NullPointerException success) {}
178      }
179 <    public void testAddAll3(){
179 >    /**
180 >     *
181 >     */
182 >    public void testAddAll3() {
183          try {
184              ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
185              Integer[] ints = new Integer[SIZE];
186              for (int i = 0; i < SIZE-1; ++i)
187                  ints[i] = new Integer(i);
188              q.addAll(Arrays.asList(ints));
189 <            fail("Cannot add null elements");
189 >            shouldThrow();
190          }
191          catch (NullPointerException success) {}
192      }
193  
194 <    public void testAddAll5(){
194 >    /**
195 >     *
196 >     */
197 >    public void testAddAll5() {
198          try {
199              Integer[] empty = new Integer[0];
200              Integer[] ints = new Integer[SIZE];
# Line 167 | Line 209 | public class ConcurrentLinkedQueueTest e
209          finally {}
210      }
211  
212 <    public void testPoll(){
212 >    /**
213 >     *
214 >     */
215 >    public void testPoll() {
216          ConcurrentLinkedQueue q = populatedQueue(SIZE);
217          for (int i = 0; i < SIZE; ++i) {
218              assertEquals(i, ((Integer)q.poll()).intValue());
# Line 175 | Line 220 | public class ConcurrentLinkedQueueTest e
220          assertNull(q.poll());
221      }
222  
223 <    public void testPeek(){
223 >    /**
224 >     *
225 >     */
226 >    public void testPeek() {
227          ConcurrentLinkedQueue q = populatedQueue(SIZE);
228          for (int i = 0; i < SIZE; ++i) {
229              assertEquals(i, ((Integer)q.peek()).intValue());
# Line 186 | Line 234 | public class ConcurrentLinkedQueueTest e
234          assertNull(q.peek());
235      }
236  
237 <    public void testElement(){
237 >    /**
238 >     *
239 >     */
240 >    public void testElement() {
241          ConcurrentLinkedQueue q = populatedQueue(SIZE);
242          for (int i = 0; i < SIZE; ++i) {
243              assertEquals(i, ((Integer)q.element()).intValue());
# Line 194 | Line 245 | public class ConcurrentLinkedQueueTest e
245          }
246          try {
247              q.element();
248 <            fail("no such element");
248 >            shouldThrow();
249          }
250          catch (NoSuchElementException success) {}
251      }
252  
253 <    public void testRemove(){
253 >    /**
254 >     *
255 >     */
256 >    public void testRemove() {
257          ConcurrentLinkedQueue q = populatedQueue(SIZE);
258          for (int i = 0; i < SIZE; ++i) {
259              assertEquals(i, ((Integer)q.remove()).intValue());
260          }
261          try {
262              q.remove();
263 <            fail("remove should throw");
263 >            shouldThrow();
264          } catch (NoSuchElementException success){
265          }  
266      }
267  
268 <    public void testRemoveElement(){
268 >    /**
269 >     *
270 >     */
271 >    public void testRemoveElement() {
272          ConcurrentLinkedQueue q = populatedQueue(SIZE);
273          for (int i = 1; i < SIZE; i+=2) {
274              assertTrue(q.remove(new Integer(i)));
# Line 223 | Line 280 | public class ConcurrentLinkedQueueTest e
280          assertTrue(q.isEmpty());
281      }
282          
283 <    public void testContains(){
283 >    /**
284 >     *
285 >     */
286 >    public void testContains() {
287          ConcurrentLinkedQueue q = populatedQueue(SIZE);
288          for (int i = 0; i < SIZE; ++i) {
289              assertTrue(q.contains(new Integer(i)));
# Line 232 | Line 292 | public class ConcurrentLinkedQueueTest e
292          }
293      }
294  
295 <    public void testClear(){
295 >    /**
296 >     *
297 >     */
298 >    public void testClear() {
299          ConcurrentLinkedQueue q = populatedQueue(SIZE);
300          q.clear();
301          assertTrue(q.isEmpty());
# Line 243 | Line 306 | public class ConcurrentLinkedQueueTest e
306          assertTrue(q.isEmpty());
307      }
308  
309 <    public void testContainsAll(){
309 >    /**
310 >     *
311 >     */
312 >    public void testContainsAll() {
313          ConcurrentLinkedQueue q = populatedQueue(SIZE);
314          ConcurrentLinkedQueue p = new ConcurrentLinkedQueue();
315          for (int i = 0; i < SIZE; ++i) {
# Line 254 | Line 320 | public class ConcurrentLinkedQueueTest e
320          assertTrue(p.containsAll(q));
321      }
322  
323 <    public void testRetainAll(){
323 >    /**
324 >     *
325 >     */
326 >    public void testRetainAll() {
327          ConcurrentLinkedQueue q = populatedQueue(SIZE);
328          ConcurrentLinkedQueue p = populatedQueue(SIZE);
329          for (int i = 0; i < SIZE; ++i) {
# Line 270 | Line 339 | public class ConcurrentLinkedQueueTest e
339          }
340      }
341  
342 <    public void testRemoveAll(){
342 >    /**
343 >     *
344 >     */
345 >    public void testRemoveAll() {
346          for (int i = 1; i < SIZE; ++i) {
347              ConcurrentLinkedQueue q = populatedQueue(SIZE);
348              ConcurrentLinkedQueue p = populatedQueue(i);
# Line 283 | Line 355 | public class ConcurrentLinkedQueueTest e
355          }
356      }
357  
358 <    public void testToArray(){
358 >    /**
359 >     *
360 >     */
361 >    public void testToArray() {
362          ConcurrentLinkedQueue q = populatedQueue(SIZE);
363          Object[] o = q.toArray();
364          Arrays.sort(o);
# Line 291 | Line 366 | public class ConcurrentLinkedQueueTest e
366              assertEquals(o[i], q.poll());
367      }
368  
369 <    public void testToArray2(){
369 >    /**
370 >     *
371 >     */
372 >    public void testToArray2() {
373          ConcurrentLinkedQueue q = populatedQueue(SIZE);
374          Integer[] ints = new Integer[SIZE];
375          ints = (Integer[])q.toArray(ints);
# Line 300 | Line 378 | public class ConcurrentLinkedQueueTest e
378              assertEquals(ints[i], q.poll());
379      }
380      
381 <    public void testIterator(){
381 >    /**
382 >     *
383 >     */
384 >    public void testIterator() {
385          ConcurrentLinkedQueue q = populatedQueue(SIZE);
386          int i = 0;
387          Iterator it = q.iterator();
# Line 311 | Line 392 | public class ConcurrentLinkedQueueTest e
392          assertEquals(i, SIZE);
393      }
394  
395 +    /**
396 +     *
397 +     */
398      public void testIteratorOrdering() {
399          final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
400          q.add(one);
# Line 320 | Line 404 | public class ConcurrentLinkedQueueTest e
404          int k = 0;
405          for (Iterator it = q.iterator(); it.hasNext();) {
406              int i = ((Integer)(it.next())).intValue();
407 <            assertEquals("items should come out in order", ++k, i);
407 >            assertEquals(++k, i);
408          }
409  
410 <        assertEquals("should go through 3 elements", 3, k);
410 >        assertEquals(3, k);
411      }
412  
413 +    /**
414 +     *
415 +     */
416      public void testWeaklyConsistentIteration () {
417          final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
418          q.add(one);
# Line 339 | Line 426 | public class ConcurrentLinkedQueueTest e
426              }
427          }
428          catch (ConcurrentModificationException e) {
429 <            fail("weakly consistent iterator; should not get CME");
429 >            shouldThrow();
430          }
431  
432          assertEquals("queue should be empty again", 0, q.size());
433      }
434  
435 +    /**
436 +     *
437 +     */
438      public void testIteratorRemove () {
439          final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
440          q.add(one);
# Line 360 | Line 450 | public class ConcurrentLinkedQueueTest e
450      }
451  
452  
453 <    public void testToString(){
453 >    /**
454 >     *
455 >     */
456 >    public void testToString() {
457          ConcurrentLinkedQueue q = populatedQueue(SIZE);
458          String s = q.toString();
459          for (int i = 0; i < SIZE; ++i) {
# Line 368 | Line 461 | public class ConcurrentLinkedQueueTest e
461          }
462      }        
463  
464 +    /**
465 +     *
466 +     */
467      public void testSerialization() {
468          ConcurrentLinkedQueue q = populatedQueue(SIZE);
469          try {
# Line 383 | Line 479 | public class ConcurrentLinkedQueueTest e
479              while (!q.isEmpty())
480                  assertEquals(q.remove(), r.remove());
481          } catch(Exception e){
482 <            e.printStackTrace();
387 <            fail("unexpected exception");
482 >            unexpectedException();
483          }
484      }
485  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines