ArrayListTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17package tests.api.java.util;
18
19import dalvik.annotation.TestTarget;
20import dalvik.annotation.TestInfo;
21import dalvik.annotation.TestLevel;
22import dalvik.annotation.TestTargetClass;
23
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.Collection;
27import java.util.HashSet;
28import java.util.Iterator;
29import java.util.List;
30import java.util.Set;
31import java.util.ConcurrentModificationException;
32import java.util.Vector;
33
34import tests.support.Support_ListTest;
35
36@TestTargetClass(ArrayList.class)
37public class ArrayListTest extends junit.framework.TestCase {
38
39    List alist;
40
41    static Object[] objArray;
42    {
43        objArray = new Object[100];
44        for (int i = 0; i < objArray.length; i++)
45            objArray[i] = new Integer(i);
46    }
47
48    /**
49     * @tests java.util.ArrayList#ArrayList()
50     */
51    @TestInfo(
52      level = TestLevel.COMPLETE,
53      purpose = "",
54      targets = {
55        @TestTarget(
56          methodName = "ArrayList",
57          methodArgs = {}
58        )
59    })
60    public void test_Constructor() {
61        // Test for method java.util.ArrayList()
62        new Support_ListTest("", alist).runTest();
63
64        ArrayList subList = new ArrayList();
65        for (int i = -50; i < 150; i++)
66            subList.add(new Integer(i));
67        new Support_ListTest("", subList.subList(50, 150)).runTest();
68    }
69
70    /**
71     * @tests java.util.ArrayList#ArrayList(int)
72     */
73    @TestInfo(
74          level = TestLevel.PARTIAL,
75          purpose = "Doesn't verify IllegalArgumentException.",
76          targets = {
77            @TestTarget(
78              methodName = "ArrayList",
79              methodArgs = {int.class}
80            )
81        })
82    public void test_ConstructorI() {
83        // Test for method java.util.ArrayList(int)
84        ArrayList al = new ArrayList(5);
85        assertEquals("Incorrect arrayList created", 0, al.size());
86    }
87
88    /**
89     * @tests java.util.ArrayList#ArrayList(java.util.Collection)
90     */
91    @TestInfo(
92      level = TestLevel.PARTIAL,
93      purpose = "Doesn't verify NullPointerException.",
94      targets = {
95        @TestTarget(
96          methodName = "ArrayList",
97          methodArgs = {java.util.Collection.class}
98        )
99    })
100    public void test_ConstructorLjava_util_Collection() {
101        // Test for method java.util.ArrayList(java.util.Collection)
102        ArrayList al = new ArrayList(Arrays.asList(objArray));
103        assertTrue("arrayList created from collection has incorrect size", al
104                .size() == objArray.length);
105        for (int counter = 0; counter < objArray.length; counter++)
106            assertTrue(
107                    "arrayList created from collection has incorrect elements",
108                    al.get(counter) == objArray[counter]);
109
110    }
111
112    /**
113     * @tests java.util.ArrayList#add(int, java.lang.Object)
114     */
115    @TestInfo(
116      level = TestLevel.PARTIAL,
117      purpose = "Doesn't verify IndexOutOfBoundsException.",
118      targets = {
119        @TestTarget(
120          methodName = "add",
121          methodArgs = {int.class, Object.class}
122        )
123    })
124    public void test_addILjava_lang_Object() {
125        // Test for method void java.util.ArrayList.add(int, java.lang.Object)
126        Object o;
127        alist.add(50, o = new Object());
128        assertTrue("Failed to add Object", alist.get(50) == o);
129        assertTrue("Failed to fix up list after insert",
130                alist.get(51) == objArray[50]
131                        && (alist.get(52) == objArray[51]));
132        Object oldItem = alist.get(25);
133        alist.add(25, null);
134        assertNull("Should have returned null", alist.get(25));
135        assertTrue("Should have returned the old item from slot 25", alist
136                .get(26) == oldItem);
137    }
138
139    /**
140     * @tests java.util.ArrayList#add(java.lang.Object)
141     */
142    @TestInfo(
143      level = TestLevel.COMPLETE,
144      purpose = "",
145      targets = {
146        @TestTarget(
147          methodName = "add",
148          methodArgs = {Object.class}
149        )
150    })
151    public void test_addLjava_lang_Object() {
152        // Test for method boolean java.util.ArrayList.add(java.lang.Object)
153        Object o = new Object();
154        alist.add(o);
155        assertTrue("Failed to add Object", alist.get(alist.size() - 1) == o);
156        alist.add(null);
157        assertNull("Failed to add null", alist.get(alist.size() - 1));
158    }
159
160    /**
161     * @tests java.util.ArrayList#addAll(int, java.util.Collection)
162     */
163    @TestInfo(
164      level = TestLevel.PARTIAL,
165      purpose = "Doesn't verify NullPointerException.",
166      targets = {
167        @TestTarget(
168          methodName = "addAll",
169          methodArgs = {int.class, java.util.Collection.class}
170        )
171    })
172    public void test_addAllILjava_util_Collection() {
173        // Test for method boolean java.util.ArrayList.addAll(int,
174        // java.util.Collection)
175        alist.addAll(50, alist);
176        assertEquals("Returned incorrect size after adding to existing list",
177                200, alist.size());
178        for (int i = 0; i < 50; i++)
179            assertTrue("Manipulated elements < index",
180                    alist.get(i) == objArray[i]);
181        for (int i = 0; i >= 50 && (i < 150); i++)
182            assertTrue("Failed to ad elements properly",
183                    alist.get(i) == objArray[i - 50]);
184        for (int i = 0; i >= 150 && (i < 200); i++)
185            assertTrue("Failed to ad elements properly",
186                    alist.get(i) == objArray[i - 100]);
187        ArrayList listWithNulls = new ArrayList();
188        listWithNulls.add(null);
189        listWithNulls.add(null);
190        listWithNulls.add("yoink");
191        listWithNulls.add("kazoo");
192        listWithNulls.add(null);
193        alist.addAll(100, listWithNulls);
194        assertTrue("Incorrect size: " + alist.size(), alist.size() == 205);
195        assertNull("Item at slot 100 should be null", alist.get(100));
196        assertNull("Item at slot 101 should be null", alist.get(101));
197        assertEquals("Item at slot 102 should be 'yoink'",
198                "yoink", alist.get(102));
199        assertEquals("Item at slot 103 should be 'kazoo'",
200                "kazoo", alist.get(103));
201        assertNull("Item at slot 104 should be null", alist.get(104));
202        alist.addAll(205, listWithNulls);
203        assertTrue("Incorrect size2: " + alist.size(), alist.size() == 210);
204    }
205
206    /**
207     * @tests java.util.ArrayList#addAll(int, java.util.Collection)
208     */
209    @TestInfo(
210      level = TestLevel.PARTIAL,
211      purpose = "Verifies IndexOutOfBoundsException.",
212      targets = {
213        @TestTarget(
214          methodName = "addAll",
215          methodArgs = {int.class, java.util.Collection.class}
216        )
217    })
218    public void test_addAllILjava_util_Collection_2() {
219        // Regression for HARMONY-467
220        ArrayList obj = new ArrayList();
221        try {
222            obj.addAll((int) -1, (Collection) null);
223            fail("IndexOutOfBoundsException expected");
224        } catch (IndexOutOfBoundsException e) {
225        }
226    }
227
228    /**
229     * @tests java.util.ArrayList#addAll(java.util.Collection)
230     */
231    @TestInfo(
232      level = TestLevel.PARTIAL,
233      purpose = "Doesn't verify NullPointerException.",
234      targets = {
235        @TestTarget(
236          methodName = "addAll",
237          methodArgs = {java.util.Collection.class}
238        )
239    })
240    public void test_addAllLjava_util_Collection() {
241        // Test for method boolean
242        // java.util.ArrayList.addAll(java.util.Collection)
243        List l = new ArrayList();
244        l.addAll(alist);
245        for (int i = 0; i < alist.size(); i++)
246            assertTrue("Failed to add elements properly", l.get(i).equals(
247                    alist.get(i)));
248        alist.addAll(alist);
249        assertEquals("Returned incorrect size after adding to existing list",
250                200, alist.size());
251        for (int i = 0; i < 100; i++) {
252            assertTrue("Added to list in incorrect order", alist.get(i)
253                    .equals(l.get(i)));
254            assertTrue("Failed to add to existing list", alist.get(i + 100)
255                    .equals(l.get(i)));
256        }
257        Set setWithNulls = new HashSet();
258        setWithNulls.add(null);
259        setWithNulls.add(null);
260        setWithNulls.add("yoink");
261        setWithNulls.add("kazoo");
262        setWithNulls.add(null);
263        alist.addAll(100, setWithNulls);
264        Iterator i = setWithNulls.iterator();
265        assertTrue("Item at slot 100 is wrong: " + alist.get(100), alist
266                .get(100) == i.next());
267        assertTrue("Item at slot 101 is wrong: " + alist.get(101), alist
268                .get(101) == i.next());
269        assertTrue("Item at slot 103 is wrong: " + alist.get(102), alist
270                .get(102) == i.next());
271
272
273        // Regression test for Harmony-3481
274        ArrayList<Integer> originalList = new ArrayList<Integer>(12);
275        for (int j = 0; j < 12; j++) {
276            originalList.add(j);
277        }
278
279        originalList.remove(0);
280        originalList.remove(0);
281
282        ArrayList<Integer> additionalList = new ArrayList<Integer>(11);
283        for (int j = 0; j < 11; j++) {
284            additionalList.add(j);
285        }
286        assertTrue(originalList.addAll(additionalList));
287        assertEquals(21, originalList.size());
288
289    }
290
291    /**
292     * @tests java.util.ArrayList#clear()
293     */
294    @TestInfo(
295      level = TestLevel.COMPLETE,
296      purpose = "",
297      targets = {
298        @TestTarget(
299          methodName = "clear",
300          methodArgs = {}
301        )
302    })
303    public void test_clear() {
304        // Test for method void java.util.ArrayList.clear()
305        alist.clear();
306        assertEquals("List did not clear", 0, alist.size());
307        alist.add(null);
308        alist.add(null);
309        alist.add(null);
310        alist.add("bam");
311        alist.clear();
312        assertEquals("List with nulls did not clear", 0, alist.size());
313        /*
314         * for (int i = 0; i < alist.size(); i++) assertNull("Failed to clear
315         * list", alist.get(i));
316         */
317
318    }
319
320    /**
321     * @tests java.util.ArrayList#clone()
322     */
323    @TestInfo(
324      level = TestLevel.COMPLETE,
325      purpose = "",
326      targets = {
327        @TestTarget(
328          methodName = "clone",
329          methodArgs = {}
330        )
331    })
332    public void test_clone() {
333        // Test for method java.lang.Object java.util.ArrayList.clone()
334        ArrayList x = (ArrayList) (((ArrayList) (alist)).clone());
335        assertTrue("Cloned list was inequal to original", x.equals(alist));
336        for (int i = 0; i < alist.size(); i++)
337            assertTrue("Cloned list contains incorrect elements",
338                    alist.get(i) == x.get(i));
339
340        alist.add(null);
341        alist.add(25, null);
342        x = (ArrayList) (((ArrayList) (alist)).clone());
343        assertTrue("nulls test - Cloned list was inequal to original", x
344                .equals(alist));
345        for (int i = 0; i < alist.size(); i++)
346            assertTrue("nulls test - Cloned list contains incorrect elements",
347                    alist.get(i) == x.get(i));
348
349    }
350
351    /**
352     * @tests java.util.ArrayList#contains(java.lang.Object)
353     */
354    @TestInfo(
355      level = TestLevel.COMPLETE,
356      purpose = "",
357      targets = {
358        @TestTarget(
359          methodName = "contains",
360          methodArgs = {java.lang.Object.class}
361        )
362    })
363    public void test_containsLjava_lang_Object() {
364        // Test for method boolean
365        // java.util.ArrayList.contains(java.lang.Object)
366        assertTrue("Returned false for valid element", alist
367                .contains(objArray[99]));
368        assertTrue("Returned false for equal element", alist
369                .contains(new Integer(8)));
370        assertTrue("Returned true for invalid element", !alist
371                .contains(new Object()));
372        assertTrue("Returned true for null but should have returned false",
373                !alist.contains(null));
374        alist.add(null);
375        assertTrue("Returned false for null but should have returned true",
376                alist.contains(null));
377    }
378
379    /**
380     * @tests java.util.ArrayList#ensureCapacity(int)
381     */
382    @TestInfo(
383      level = TestLevel.COMPLETE,
384      purpose = "",
385      targets = {
386        @TestTarget(
387          methodName = "ensureCapacity",
388          methodArgs = {int.class}
389        )
390    })
391    public void test_ensureCapacityI() {
392        // Test for method void java.util.ArrayList.ensureCapacity(int)
393        // TODO : There is no good way to test this as it only really impacts on
394        // the private implementation.
395
396        Object testObject = new Object();
397        int capacity = 20;
398        ArrayList al = new ArrayList(capacity);
399        int i;
400        for (i = 0; i < capacity / 2; i++) {
401            al.add(i, new Object());
402        }
403        al.add(i, testObject);
404        int location = al.indexOf(testObject);
405        try {
406            al.ensureCapacity(capacity);
407            assertTrue("EnsureCapacity moved objects around in array1.",
408                    location == al.indexOf(testObject));
409            al.remove(0);
410            al.ensureCapacity(capacity);
411            assertTrue("EnsureCapacity moved objects around in array2.",
412                    --location == al.indexOf(testObject));
413            al.ensureCapacity(capacity + 2);
414            assertTrue("EnsureCapacity did not change location.",
415                    location == al.indexOf(testObject));
416        } catch (Exception e) {
417            fail("Exception during test : " + e.getMessage());
418        }
419    }
420
421    /**
422     * @tests java.util.ArrayList#get(int)
423     */
424    @TestInfo(
425      level = TestLevel.COMPLETE,
426      purpose = "",
427      targets = {
428        @TestTarget(
429          methodName = "get",
430          methodArgs = {int.class}
431        )
432    })
433    public void test_getI() {
434        // Test for method java.lang.Object java.util.ArrayList.get(int)
435        assertTrue("Returned incorrect element", alist.get(22) == objArray[22]);
436        try {
437            alist.get(8765);
438            fail("Failed to throw expected exception for index > size");
439        } catch (IndexOutOfBoundsException e) {
440        }
441    }
442
443    /**
444     * @tests java.util.ArrayList#indexOf(java.lang.Object)
445     */
446    @TestInfo(
447      level = TestLevel.COMPLETE,
448      purpose = "",
449      targets = {
450        @TestTarget(
451          methodName = "indexOf",
452          methodArgs = {java.lang.Object.class}
453        )
454    })
455    public void test_indexOfLjava_lang_Object() {
456        // Test for method int java.util.ArrayList.indexOf(java.lang.Object)
457        assertEquals("Returned incorrect index",
458                87, alist.indexOf(objArray[87]));
459        assertEquals("Returned index for invalid Object", -1, alist
460                .indexOf(new Object()));
461        alist.add(25, null);
462        alist.add(50, null);
463        assertTrue("Wrong indexOf for null.  Wanted 25 got: "
464                + alist.indexOf(null), alist.indexOf(null) == 25);
465    }
466
467    /**
468     * @tests java.util.ArrayList#isEmpty()
469     */
470    @TestInfo(
471      level = TestLevel.COMPLETE,
472      purpose = "",
473      targets = {
474        @TestTarget(
475          methodName = "isEmpty",
476          methodArgs = {}
477        )
478    })
479    public void test_isEmpty() {
480        // Test for method boolean java.util.ArrayList.isEmpty()
481        assertTrue("isEmpty returned false for new list", new ArrayList()
482                .isEmpty());
483        assertTrue("Returned true for existing list with elements", !alist
484                .isEmpty());
485    }
486
487    /**
488     * @tests java.util.ArrayList#lastIndexOf(java.lang.Object)
489     */
490    @TestInfo(
491      level = TestLevel.COMPLETE,
492      purpose = "",
493      targets = {
494        @TestTarget(
495          methodName = "lastIndexOf",
496          methodArgs = {java.lang.Object.class}
497        )
498    })
499    public void test_lastIndexOfLjava_lang_Object() {
500        // Test for method int java.util.ArrayList.lastIndexOf(java.lang.Object)
501        alist.add(new Integer(99));
502        assertEquals("Returned incorrect index",
503                100, alist.lastIndexOf(objArray[99]));
504        assertEquals("Returned index for invalid Object", -1, alist
505                .lastIndexOf(new Object()));
506        alist.add(25, null);
507        alist.add(50, null);
508        assertTrue("Wrong lastIndexOf for null.  Wanted 50 got: "
509                + alist.lastIndexOf(null), alist.lastIndexOf(null) == 50);
510    }
511
512    /**
513     * @tests java.util.ArrayList#remove(int)
514     */
515    @TestInfo(
516      level = TestLevel.PARTIAL,
517      purpose = "Doesn't verify IndexOutOfBoundsException.",
518      targets = {
519        @TestTarget(
520          methodName = "remove",
521          methodArgs = {int.class}
522        )
523    })
524    public void test_removeI() {
525        // Test for method java.lang.Object java.util.ArrayList.remove(int)
526        alist.remove(10);
527        assertEquals("Failed to remove element",
528                -1, alist.indexOf(objArray[10]));
529        try {
530            alist.remove(999);
531            fail("Failed to throw exception when index out of range");
532        } catch (IndexOutOfBoundsException e) {
533        }
534
535        ArrayList myList = (ArrayList) (((ArrayList) (alist)).clone());
536        alist.add(25, null);
537        alist.add(50, null);
538        alist.remove(50);
539        alist.remove(25);
540        assertTrue("Removing nulls did not work", alist.equals(myList));
541
542        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c",
543                "d", "e", "f", "g" }));
544        assertTrue("Removed wrong element 1", list.remove(0) == "a");
545        assertTrue("Removed wrong element 2", list.remove(4) == "f");
546        String[] result = new String[5];
547        list.toArray(result);
548        assertTrue("Removed wrong element 3", Arrays.equals(result,
549                new String[] { "b", "c", "d", "e", "g" }));
550
551        List l = new ArrayList(0);
552        l.add(new Object());
553        l.add(new Object());
554        l.remove(0);
555        l.remove(0);
556        try {
557            l.remove(-1);
558            fail("-1 should cause exception");
559        } catch (IndexOutOfBoundsException e) {
560        }
561        try {
562            l.remove(0);
563            fail("0 should case exception");
564        } catch (IndexOutOfBoundsException e) {
565        }
566    }
567
568    /**
569     * @tests java.util.ArrayList#set(int, java.lang.Object)
570     */
571    @TestInfo(
572      level = TestLevel.PARTIAL,
573      purpose = "Doesn't verify IndexOutOfBoundsException.",
574      targets = {
575        @TestTarget(
576          methodName = "set",
577          methodArgs = {int.class, Object.class}
578        )
579    })
580    public void test_setILjava_lang_Object() {
581        // Test for method java.lang.Object java.util.ArrayList.set(int,
582        // java.lang.Object)
583        Object obj;
584        alist.set(65, obj = new Object());
585        assertTrue("Failed to set object", alist.get(65) == obj);
586        alist.set(50, null);
587        assertNull("Setting to null did not work", alist.get(50));
588        assertTrue("Setting increased the list's size to: " + alist.size(),
589                alist.size() == 100);
590    }
591
592    /**
593     * @tests java.util.ArrayList#size()
594     */
595    @TestInfo(
596      level = TestLevel.COMPLETE,
597      purpose = "",
598      targets = {
599        @TestTarget(
600          methodName = "size",
601          methodArgs = {}
602        )
603    })
604    public void test_size() {
605        // Test for method int java.util.ArrayList.size()
606        assertEquals("Returned incorrect size for exiting list",
607                100, alist.size());
608        assertEquals("Returned incorrect size for new list", 0, new ArrayList()
609                .size());
610    }
611
612    /**
613     * @tests java.util.ArrayList#toArray()
614     */
615    @TestInfo(
616      level = TestLevel.COMPLETE,
617      purpose = "",
618      targets = {
619        @TestTarget(
620          methodName = "toArray",
621          methodArgs = {}
622        )
623    })
624    public void test_toArray() {
625        // Test for method java.lang.Object [] java.util.ArrayList.toArray()
626        alist.set(25, null);
627        alist.set(75, null);
628        Object[] obj = alist.toArray();
629        assertEquals("Returned array of incorrect size", objArray.length,
630                obj.length);
631
632        for (int i = 0; i < obj.length; i++) {
633            if ((i == 25) || (i == 75))
634                assertNull("Should be null at: " + i + " but instead got: "
635                        + obj[i], obj[i]);
636            else
637                assertTrue("Returned incorrect array: " + i,
638                        obj[i] == objArray[i]);
639        }
640
641    }
642
643    /**
644     * @tests java.util.ArrayList#toArray(java.lang.Object[])
645     */
646    @TestInfo(
647      level = TestLevel.PARTIAL,
648      purpose = "Doesn't verify ArrayStoreException.",
649      targets = {
650        @TestTarget(
651          methodName = "toArray",
652          methodArgs = {Object[].class}
653        )
654    })
655    public void test_toArray$Ljava_lang_Object() {
656        // Test for method java.lang.Object []
657        // java.util.ArrayList.toArray(java.lang.Object [])
658        alist.set(25, null);
659        alist.set(75, null);
660        Integer[] argArray = new Integer[100];
661        Object[] retArray;
662        retArray = alist.toArray(argArray);
663        assertTrue("Returned different array than passed", retArray == argArray);
664        argArray = new Integer[1000];
665        retArray = alist.toArray(argArray);
666        assertNull("Failed to set first extra element to null", argArray[alist
667                .size()]);
668        for (int i = 0; i < 100; i++) {
669            if ((i == 25) || (i == 75))
670                assertNull("Should be null: " + i, retArray[i]);
671            else
672                assertTrue("Returned incorrect array: " + i,
673                        retArray[i] == objArray[i]);
674        }
675    }
676
677    /**
678     * @tests java.util.ArrayList#trimToSize()
679     */
680    @TestInfo(
681      level = TestLevel.COMPLETE,
682      purpose = "",
683      targets = {
684        @TestTarget(
685          methodName = "trimToSize",
686          methodArgs = {}
687        )
688    })
689    public void _test_trimToSize() {
690        // Test for method void java.util.ArrayList.trimToSize()
691        for (int i = 99; i > 24; i--)
692            alist.remove(i);
693        ((ArrayList) alist).trimToSize();
694        assertEquals("Returned incorrect size after trim", 25, alist.size());
695        for (int i = 0; i < alist.size(); i++)
696            assertTrue("Trimmed list contained incorrect elements", alist
697                    .get(i) == objArray[i]);
698        Vector v = new Vector();
699        v.add("a");
700        ArrayList al = new ArrayList(v);
701        Iterator it = al.iterator();
702        al.trimToSize();
703        try {
704            it.next();
705            fail("should throw a ConcurrentModificationException");
706        } catch (ConcurrentModificationException ioobe) {
707            // expected
708        }
709    }
710
711    /**
712     * @test java.util.ArrayList#addAll(int, Collection)
713     */
714    @TestInfo(
715      level = TestLevel.PARTIAL,
716      purpose = "Doesn't verify NullPointerException.",
717      targets = {
718        @TestTarget(
719          methodName = "addAll",
720          methodArgs = {int.class, java.util.Collection.class}
721        )
722    })
723    public void test_addAll() {
724        ArrayList list = new ArrayList();
725        list.add("one");
726        list.add("two");
727        assertEquals(2, list.size());
728
729        list.remove(0);
730        assertEquals(1, list.size());
731
732        ArrayList collection = new ArrayList();
733        collection.add("1");
734        collection.add("2");
735        collection.add("3");
736        assertEquals(3, collection.size());
737
738        list.addAll(0, collection);
739        assertEquals(4, list.size());
740
741        list.remove(0);
742        list.remove(0);
743        assertEquals(2, list.size());
744
745        collection.add("4");
746        collection.add("5");
747        collection.add("6");
748        collection.add("7");
749        collection.add("8");
750        collection.add("9");
751        collection.add("10");
752        collection.add("11");
753        collection.add("12");
754
755        assertEquals(12, collection.size());
756
757        list.addAll(0, collection);
758        assertEquals(14, list.size());
759    }
760
761
762
763    /**
764     * Sets up the fixture, for example, open a network connection. This method
765     * is called before a test is executed.
766     */
767    protected void setUp() throws Exception {
768        super.setUp();
769        alist = new ArrayList();
770        for (int i = 0; i < objArray.length; i++)
771            alist.add(objArray[i]);
772    }
773}
774