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

Comparing jsr166/src/test/tck/CopyOnWriteArrayListTest.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 31 | Line 31 | public class CopyOnWriteArrayListTest ex
31      }
32  
33  
34 +    /**
35 +     *
36 +     */
37      public void testConstructor() {
38          CopyOnWriteArrayList a = new CopyOnWriteArrayList();
39          assertTrue(a.isEmpty());
40      }
41  
42 +    /**
43 +     *
44 +     */
45      public void testConstructor2() {
46          Integer[] ints = new Integer[SIZE];
47          for (int i = 0; i < SIZE-1; ++i)
# Line 45 | Line 51 | public class CopyOnWriteArrayListTest ex
51              assertEquals(ints[i], a.get(i));
52      }
53  
54 +    /**
55 +     *
56 +     */
57      public void testConstructor3() {
58          Integer[] ints = new Integer[SIZE];
59          for (int i = 0; i < SIZE-1; ++i)
# Line 58 | Line 67 | public class CopyOnWriteArrayListTest ex
67      /**
68       *   addAll correctly adds each element from the given collection
69       */
70 <    public void testAddAll(){
70 >    public void testAddAll() {
71          CopyOnWriteArrayList full = populatedArray(3);
72          Vector v = new Vector();
73          v.add(three);
# Line 72 | Line 81 | public class CopyOnWriteArrayListTest ex
81       *   addAllAbsent adds each element from the given collection that did not
82       *  already exist in the List
83       */
84 <    public void testAddAllAbsent(){
84 >    public void testAddAllAbsent() {
85          CopyOnWriteArrayList full = populatedArray(3);
86          Vector v = new Vector();
87          v.add(three);
# Line 85 | Line 94 | public class CopyOnWriteArrayListTest ex
94      /**
95       *   addIfAbsent will not add the element if it already exists in the list
96       */
97 <    public void testAddIfAbsent(){
98 <        CopyOnWriteArrayList full = populatedArray(3);
97 >    public void testAddIfAbsent() {
98 >        CopyOnWriteArrayList full = populatedArray(SIZE);
99          full.addIfAbsent(one);
100 <        assertEquals(3, full.size());
100 >        assertEquals(SIZE, full.size());
101      }
102  
103      /**
104       *   addIfAbsent correctly adds the element when it does not exist in the list
105       */
106 <    public void testAddIfAbsent2(){
107 <        CopyOnWriteArrayList full = populatedArray(3);
106 >    public void testAddIfAbsent2() {
107 >        CopyOnWriteArrayList full = populatedArray(SIZE);
108          full.addIfAbsent(three);
109          assertTrue(full.contains(three));
110      }
# Line 103 | Line 112 | public class CopyOnWriteArrayListTest ex
112      /**
113       *   clear correctly removes all elements from the list
114       */
115 <    public void testClear(){
116 <        CopyOnWriteArrayList full = populatedArray(3);
115 >    public void testClear() {
116 >        CopyOnWriteArrayList full = populatedArray(SIZE);
117          full.clear();
118          assertEquals(0, full.size());
119      }
120  
121 +
122 +    /**
123 +     *  Cloned list is equal
124 +     */
125 +    public void testClone() {
126 +        CopyOnWriteArrayList l1 = populatedArray(SIZE);
127 +        CopyOnWriteArrayList l2 = (CopyOnWriteArrayList)(l1.clone());
128 +        assertEquals(l1, l2);
129 +        l1.clear();
130 +        assertFalse(l1.equals(l2));
131 +    }
132 +
133      /**
134       *   contains returns the correct values
135       */
136 <    public void testContains(){
136 >    public void testContains() {
137          CopyOnWriteArrayList full = populatedArray(3);
138          assertTrue(full.contains(one));
139          assertFalse(full.contains(five));
140      }
141  
142 +    /**
143 +     *
144 +     */
145      public void testAddIndex() {
146          CopyOnWriteArrayList full = populatedArray(3);
147          full.add(0, m1);
# Line 131 | Line 155 | public class CopyOnWriteArrayListTest ex
155          assertEquals(two, full.get(4));
156      }
157  
158 +    /**
159 +     *
160 +     */
161      public void testEquals() {
162          CopyOnWriteArrayList a = populatedArray(3);
163          CopyOnWriteArrayList b = populatedArray(3);
# Line 150 | Line 177 | public class CopyOnWriteArrayListTest ex
177      /**
178       *   containsAll returns the correct values
179       */
180 <    public void testContainsAll(){
180 >    public void testContainsAll() {
181          CopyOnWriteArrayList full = populatedArray(3);
182          Vector v = new Vector();
183          v.add(one);
# Line 163 | Line 190 | public class CopyOnWriteArrayListTest ex
190      /**
191       *   get returns the correct value for the given index
192       */
193 <    public void testGet(){
193 >    public void testGet() {
194          CopyOnWriteArrayList full = populatedArray(3);
195          assertEquals(0, ((Integer)full.get(0)).intValue());
196      }
# Line 171 | Line 198 | public class CopyOnWriteArrayListTest ex
198      /**
199       *   indexOf gives the correct index for the given object
200       */
201 <    public void testIndexOf(){
201 >    public void testIndexOf() {
202          CopyOnWriteArrayList full = populatedArray(3);
203          assertEquals(1, full.indexOf(one));
204          assertEquals(-1, full.indexOf("puppies"));
# Line 181 | Line 208 | public class CopyOnWriteArrayListTest ex
208       *   indexOf gives the correct index based on the given index
209       *  at which to start searching
210       */
211 <    public void testIndexOf2(){
211 >    public void testIndexOf2() {
212          CopyOnWriteArrayList full = populatedArray(3);
213          assertEquals(1, full.indexOf(one, 0));
214          assertEquals(-1, full.indexOf(one, 2));
# Line 190 | Line 217 | public class CopyOnWriteArrayListTest ex
217      /**
218       *   isEmpty returns the correct values
219       */
220 <    public void testIsEmpty(){
220 >    public void testIsEmpty() {
221          CopyOnWriteArrayList empty = new CopyOnWriteArrayList();
222 <        CopyOnWriteArrayList full = populatedArray(3);
222 >        CopyOnWriteArrayList full = populatedArray(SIZE);
223          assertTrue(empty.isEmpty());
224          assertFalse(full.isEmpty());
225      }
# Line 200 | Line 227 | public class CopyOnWriteArrayListTest ex
227      /**
228       *   iterator() returns an iterator containing the elements of the list
229       */
230 <    public void testIterator(){
231 <        CopyOnWriteArrayList full = populatedArray(3);
230 >    public void testIterator() {
231 >        CopyOnWriteArrayList full = populatedArray(SIZE);
232          Iterator i = full.iterator();
233          int j;
234          for(j = 0; i.hasNext(); j++)
235              assertEquals(j, ((Integer)i.next()).intValue());
236 <        assertEquals(3, j);
236 >        assertEquals(SIZE, j);
237      }
238  
239 +    /**
240 +     *
241 +     */
242      public void testIteratorRemove () {
243 <        CopyOnWriteArrayList full = populatedArray(3);
243 >        CopyOnWriteArrayList full = populatedArray(SIZE);
244          Iterator it = full.iterator();
245          it.next();
246          try {
247              it.remove();
248 <            fail("should throw");
248 >            shouldThrow();
249          }
250          catch (UnsupportedOperationException success) {}
251      }
252  
253 <    public void testToString(){
253 >    /**
254 >     *
255 >     */
256 >    public void testToString() {
257          CopyOnWriteArrayList full = populatedArray(3);
258          String s = full.toString();
259          for (int i = 0; i < 3; ++i) {
# Line 231 | Line 264 | public class CopyOnWriteArrayListTest ex
264      /**
265       *   lastIndexOf returns the correct index for the given object
266       */
267 <    public void testLastIndexOf1(){
267 >    public void testLastIndexOf1() {
268          CopyOnWriteArrayList full = populatedArray(3);
269          full.add(one);
270          full.add(three);
# Line 242 | Line 275 | public class CopyOnWriteArrayListTest ex
275      /**
276       *   lastIndexOf returns the correct index from the given starting point
277       */
278 <    public void testlastIndexOf2(){
278 >    public void testlastIndexOf2() {
279          CopyOnWriteArrayList full = populatedArray(3);
280          full.add(one);
281          full.add(three);
# Line 253 | Line 286 | public class CopyOnWriteArrayListTest ex
286      /**
287       *  Identical to testIterator, except ListInterator has more functionality
288       */
289 <    public void testListIterator1(){
290 <        CopyOnWriteArrayList full = populatedArray(3);
289 >    public void testListIterator1() {
290 >        CopyOnWriteArrayList full = populatedArray(SIZE);
291          ListIterator i = full.listIterator();
292          int j;
293          for(j = 0; i.hasNext(); j++)
294              assertEquals(j, ((Integer)i.next()).intValue());
295 <        assertEquals(3, j);
295 >        assertEquals(SIZE, j);
296      }
297  
298      /**
299 <     *  Identical to testIterator and testListIterator1, but only returns those elements
267 <     *  after the given index
299 >     *  listIterator only returns those elements after the given index
300       */
301 <    public void testListIterator2(){
301 >    public void testListIterator2() {
302          CopyOnWriteArrayList full = populatedArray(3);
303          ListIterator i = full.listIterator(1);
304          int j;
# Line 278 | Line 310 | public class CopyOnWriteArrayListTest ex
310      /**
311       *   remove correctly removes and returns the object at the given index
312       */
313 <    public void testRemove(){
313 >    public void testRemove() {
314          CopyOnWriteArrayList full = populatedArray(3);
315          assertEquals(two, full.remove(2));
316          assertEquals(2, full.size());
# Line 287 | Line 319 | public class CopyOnWriteArrayListTest ex
319      /**
320       *   removeAll correctly removes all elements from the given collection
321       */
322 <    public void testRemoveAll(){
322 >    public void testRemoveAll() {
323          CopyOnWriteArrayList full = populatedArray(3);
324          Vector v = new Vector();
325          v.add(one);
# Line 299 | Line 331 | public class CopyOnWriteArrayListTest ex
331      /**
332       *   set correctly changes the element at the given index
333       */
334 <    public void testSet(){
334 >    public void testSet() {
335          CopyOnWriteArrayList full = populatedArray(3);
336          assertEquals(two, full.set(2, four));
337          assertEquals(4, ((Integer)full.get(2)).intValue());
# Line 308 | Line 340 | public class CopyOnWriteArrayListTest ex
340      /**
341       *   size returns the correct values
342       */
343 <    public void testSize(){
343 >    public void testSize() {
344          CopyOnWriteArrayList empty = new CopyOnWriteArrayList();
345 <        CopyOnWriteArrayList full = populatedArray(3);
346 <        assertEquals(3, full.size());
345 >        CopyOnWriteArrayList full = populatedArray(SIZE);
346 >        assertEquals(SIZE, full.size());
347          assertEquals(0, empty.size());
348      }
349  
350      /**
351       *   toArray returns an Object array containing all elements from the list
352       */
353 <    public void testToArray(){
353 >    public void testToArray() {
354          CopyOnWriteArrayList full = populatedArray(3);
355          Object[] o = full.toArray();
356          assertEquals(3, o.length);
# Line 328 | Line 360 | public class CopyOnWriteArrayListTest ex
360      }
361  
362      /**
363 <     *  test to verify toArray returns an Integer array containing all elements from the list
363 >     *   toArray returns an Integer array containing all elements from
364 >     *   the list
365       */
366 <    public void testToArray2(){
366 >    public void testToArray2() {
367          CopyOnWriteArrayList full = populatedArray(3);
368          Integer[] i = new Integer[3];
369          i = (Integer[])full.toArray(i);
# Line 341 | Line 374 | public class CopyOnWriteArrayListTest ex
374      }
375  
376  
377 +    /**
378 +     *
379 +     */
380      public void testSubList() {
381          CopyOnWriteArrayList a = populatedArray(10);
382          assertTrue(a.subList(1,1).isEmpty());
# Line 367 | Line 403 | public class CopyOnWriteArrayListTest ex
403       *   toArray throws an ArrayStoreException when the given array
404       *  can not store the objects inside the list
405       */
406 <    public void testToArray_ArrayStoreException(){
407 <        try{
406 >    public void testToArray_ArrayStoreException() {
407 >        try {
408              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
409              c.add("zfasdfsdf");
410              c.add("asdadasd");
411              c.toArray(new Long[5]);
412 <            fail("Object[] toArray(Object[]) should throw ArrayStoreException");
413 <        }catch(ArrayStoreException e){}
412 >            shouldThrow();
413 >        } catch(ArrayStoreException e){}
414      }
415  
416      /**
417       *   get throws an IndexOutOfBoundsException on a negative index
418       */
419 <    public void testGet1_IndexOutOfBoundsException(){
420 <        try{
419 >    public void testGet1_IndexOutOfBoundsException() {
420 >        try {
421              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
422              c.get(-1);
423 <            fail("Object get(int) should throw IndexOutOfBounds exception");
424 <        }catch(IndexOutOfBoundsException e){}
423 >            shouldThrow();
424 >        } catch(IndexOutOfBoundsException e){}
425      }
426      
427      /**
428       *   get throws an IndexOutOfBoundsException on a too high index
429       */
430 <    public void testGet2_IndexOutOfBoundsException(){
431 <        try{
430 >    public void testGet2_IndexOutOfBoundsException() {
431 >        try {
432              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
433              c.add("asdasd");
434              c.add("asdad");
435              c.get(100);
436 <            fail("Object get(int) should throw IndexOutOfBounds exception");
437 <        }catch(IndexOutOfBoundsException e){}
436 >            shouldThrow();
437 >        } catch(IndexOutOfBoundsException e){}
438      }
439  
440      /**
441       *   set throws an IndexOutOfBoundsException on a negative index
442       */
443 <    public void testSet1_IndexOutOfBoundsException(){
444 <        try{
443 >    public void testSet1_IndexOutOfBoundsException() {
444 >        try {
445              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
446              c.set(-1,"qwerty");
447 <            fail("Object get(int, Object) should throw IndexOutOfBounds exception");
448 <        }catch(IndexOutOfBoundsException e){}
447 >            shouldThrow();
448 >        } catch(IndexOutOfBoundsException e){}
449      }
450      
451      /**
452       *   set throws an IndexOutOfBoundsException on a too high index
453       */
454 <    public void testSet2(){
455 <        try{
454 >    public void testSet2() {
455 >        try {
456              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
457              c.add("asdasd");
458              c.add("asdad");
459              c.set(100, "qwerty");
460 <            fail("Object set(int, Object) should throw IndexOutOfBounds exception");
461 <        }catch(IndexOutOfBoundsException e){}
460 >            shouldThrow();
461 >        } catch(IndexOutOfBoundsException e){}
462      }
463  
464      /**
465       *   add throws an IndexOutOfBoundsException on a negative index
466       */
467 <    public void testAdd1_IndexOutOfBoundsException(){
468 <        try{
467 >    public void testAdd1_IndexOutOfBoundsException() {
468 >        try {
469              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
470              c.add(-1,"qwerty");
471 <            fail("void add(int, Object) should throw IndexOutOfBounds exception");
472 <        }catch(IndexOutOfBoundsException e){}
471 >            shouldThrow();
472 >        } catch(IndexOutOfBoundsException e){}
473      }
474      
475      /**
476       *   add throws an IndexOutOfBoundsException on a too high index
477       */
478 <    public void testAdd2_IndexOutOfBoundsException(){
479 <        try{
478 >    public void testAdd2_IndexOutOfBoundsException() {
479 >        try {
480              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
481              c.add("asdasd");
482              c.add("asdasdasd");
483              c.add(100, "qwerty");
484 <            fail("void add(int, Object) should throw IndexOutOfBounds exception");
485 <        }catch(IndexOutOfBoundsException e){}
484 >            shouldThrow();
485 >        } catch(IndexOutOfBoundsException e){}
486      }
487  
488      /**
489       *   remove throws an IndexOutOfBoundsException on a negative index
490       */
491 <    public void testRemove1_IndexOutOfBounds(){
492 <        try{
491 >    public void testRemove1_IndexOutOfBounds() {
492 >        try {
493              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
494              c.remove(-1);
495 <            fail("Object remove(int) should throw IndexOutOfBounds exception");
496 <        }catch(IndexOutOfBoundsException e){}
495 >            shouldThrow();
496 >        } catch(IndexOutOfBoundsException e){}
497      }
498  
499      /**
500       *   remove throws an IndexOutOfBoundsException on a too high index
501       */
502 <    public void testRemove2_IndexOutOfBounds(){
503 <        try{
502 >    public void testRemove2_IndexOutOfBounds() {
503 >        try {
504              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
505              c.add("asdasd");
506              c.add("adasdasd");
507              c.remove(100);
508 <            fail("Object remove(int) should throw IndexOutOfBounds exception");
509 <        }catch(IndexOutOfBoundsException e){}
508 >            shouldThrow();
509 >        } catch(IndexOutOfBoundsException e){}
510      }
511      
512      /**
513       *   addAll throws an IndexOutOfBoundsException on a negative index
514       */
515 <    public void testAddAll1_IndexOutOfBoundsException(){
516 <        try{
515 >    public void testAddAll1_IndexOutOfBoundsException() {
516 >        try {
517              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
518              c.addAll(-1,new LinkedList());
519 <            fail("boolean add(int, Collection) should throw IndexOutOfBounds exception");
520 <        }catch(IndexOutOfBoundsException e){}
519 >            shouldThrow();
520 >        } catch(IndexOutOfBoundsException e){}
521      }
522      
523      /**
524       *   addAll throws an IndexOutOfBoundsException on a too high index
525       */
526 <    public void testAddAll2_IndexOutOfBoundsException(){
527 <        try{
526 >    public void testAddAll2_IndexOutOfBoundsException() {
527 >        try {
528              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
529              c.add("asdasd");
530              c.add("asdasdasd");
531              c.addAll(100, new LinkedList());
532 <            fail("boolean addAll(int, Collection) should throw IndexOutOfBounds exception");
533 <        }catch(IndexOutOfBoundsException e){}
532 >            shouldThrow();
533 >        } catch(IndexOutOfBoundsException e){}
534      }
535  
536      /**
537       *   listIterator throws an IndexOutOfBoundsException on a negative index
538       */
539 <    public void testListIterator1_IndexOutOfBoundsException(){
540 <        try{
539 >    public void testListIterator1_IndexOutOfBoundsException() {
540 >        try {
541              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
542              c.listIterator(-1);
543 <            fail("ListIterator listIterator(int) should throw IndexOutOfBounds exceptione");
544 <        }catch(IndexOutOfBoundsException e){}
543 >            shouldThrow();
544 >        } catch(IndexOutOfBoundsException e){}
545      }
546  
547      /**
548       *   listIterator throws an IndexOutOfBoundsException on a too high index
549       */
550 <    public void testListIterator2_IndexOutOfBoundsException(){
551 <        try{
550 >    public void testListIterator2_IndexOutOfBoundsException() {
551 >        try {
552              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
553              c.add("adasd");
554              c.add("asdasdas");
555              c.listIterator(100);
556 <            fail("ListIterator listIterator(int) should throw IndexOutOfBounds exception");
557 <        }catch(IndexOutOfBoundsException e){}
556 >            shouldThrow();
557 >        } catch(IndexOutOfBoundsException e){}
558      }
559  
560      /**
561       *   subList throws an IndexOutOfBoundsException on a negative index
562       */
563 <    public void testSubList1_IndexOutOfBoundsException(){
564 <        try{
563 >    public void testSubList1_IndexOutOfBoundsException() {
564 >        try {
565              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
566              c.subList(-1,100);
567  
568 <            fail("List subList(int, int) should throw IndexOutofBounds exception");
569 <        }catch(IndexOutOfBoundsException e){}
568 >            shouldThrow();
569 >        } catch(IndexOutOfBoundsException e){}
570      }
571  
572      /**
573       *   subList throws an IndexOutOfBoundsException on a too high index
574       */
575 <    public void testSubList2_IndexOutOfBoundsException(){
576 <        try{
575 >    public void testSubList2_IndexOutOfBoundsException() {
576 >        try {
577              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
578              c.add("asdasd");
579              c.subList(1,100);
580 <            fail("List subList(int, int) should throw IndexOutofBounds exception");
581 <        }catch(IndexOutOfBoundsException e){}
580 >            shouldThrow();
581 >        } catch(IndexOutOfBoundsException e){}
582      }
583  
584      /**
585       *   subList throws IndexOutOfBoundsException when the second index
586       *  is lower then the first
587       */
588 <    public void testSubList3_IndexOutOfBoundsException(){
589 <        try{
588 >    public void testSubList3_IndexOutOfBoundsException() {
589 >        try {
590              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
591              c.subList(3,1);
592  
593 <            fail("List subList(int, int) should throw IndexOutofBounds exception");
594 <        }catch(IndexOutOfBoundsException e){}
593 >            shouldThrow();
594 >        } catch(IndexOutOfBoundsException e){}
595      }
596  
597 +    /**
598 +     *
599 +     */
600      public void testSerialization() {
601          CopyOnWriteArrayList q = populatedArray(SIZE);
602  
# Line 574 | Line 613 | public class CopyOnWriteArrayListTest ex
613              assertTrue(q.equals(r));
614              assertTrue(r.equals(q));
615          } catch(Exception e){
616 <            e.printStackTrace();
578 <            fail("unexpected exception");
616 >            unexpectedException();
617          }
618      }
619      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines