KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > list > TestGrowthList


1 /*
2  * Copyright 2005 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.list;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Arrays JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.List JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 /**
27  * Extension of {@link TestList} for exercising the {@link GrowthList}.
28  *
29  * @since Commons Collections 3.2
30  * @version $Revision: 155406 $ $Date: 2005-05-15 19:30:49 +0100 (Sun, 15 May 2005) $
31  *
32  * @author Stephen Colebourne
33  */

34 public class TestGrowthList extends AbstractTestList {
35
36     public TestGrowthList(String JavaDoc testName) {
37         super(testName);
38     }
39
40     public static Test suite() {
41         return new TestSuite(TestGrowthList.class);
42     }
43
44     public static void main(String JavaDoc args[]) {
45         String JavaDoc[] testCaseName = { TestGrowthList.class.getName()};
46         junit.textui.TestRunner.main(testCaseName);
47     }
48
49     public List JavaDoc makeEmptyList() {
50         return new GrowthList();
51     }
52
53     public List JavaDoc makeFullList() {
54         List JavaDoc list = new ArrayList JavaDoc();
55         list.addAll(Arrays.asList(getFullElements()));
56         return GrowthList.decorate(list);
57     }
58
59     //-----------------------------------------------------------------------
60
public void testGrowthAdd() {
61         Integer JavaDoc one = new Integer JavaDoc(1);
62         GrowthList grower = new GrowthList();
63         assertEquals(0, grower.size());
64         grower.add(1, one);
65         assertEquals(2, grower.size());
66         assertEquals(null, grower.get(0));
67         assertEquals(one, grower.get(1));
68     }
69
70     public void testGrowthAddAll() {
71         Integer JavaDoc one = new Integer JavaDoc(1);
72         Integer JavaDoc two = new Integer JavaDoc(2);
73         Collection JavaDoc coll = new ArrayList JavaDoc();
74         coll.add(one);
75         coll.add(two);
76         GrowthList grower = new GrowthList();
77         assertEquals(0, grower.size());
78         grower.addAll(1, coll);
79         assertEquals(3, grower.size());
80         assertEquals(null, grower.get(0));
81         assertEquals(one, grower.get(1));
82         assertEquals(two, grower.get(2));
83     }
84
85     public void testGrowthSet1() {
86         Integer JavaDoc one = new Integer JavaDoc(1);
87         GrowthList grower = new GrowthList();
88         assertEquals(0, grower.size());
89         grower.set(1, one);
90         assertEquals(2, grower.size());
91         assertEquals(null, grower.get(0));
92         assertEquals(one, grower.get(1));
93     }
94
95     public void testGrowthSet2() {
96         Integer JavaDoc one = new Integer JavaDoc(1);
97         GrowthList grower = new GrowthList();
98         assertEquals(0, grower.size());
99         grower.set(0, one);
100         assertEquals(1, grower.size());
101         assertEquals(one, grower.get(0));
102     }
103
104     //-----------------------------------------------------------------------
105
/**
106      * Override.
107      */

108     public void testListAddByIndexBoundsChecking() {
109         List JavaDoc list;
110         Object JavaDoc element = getOtherElements()[0];
111         try {
112             list = makeEmptyList();
113             list.add(-1, element);
114             fail("List.add should throw IndexOutOfBoundsException [-1]");
115         } catch (IndexOutOfBoundsException JavaDoc e) {
116             // expected
117
}
118     }
119
120     /**
121      * Override.
122      */

123     public void testListAddByIndexBoundsChecking2() {
124         List JavaDoc list;
125         Object JavaDoc element = getOtherElements()[0];
126         try {
127             list = makeFullList();
128             list.add(-1, element);
129             fail("List.add should throw IndexOutOfBoundsException [-1]");
130         } catch (IndexOutOfBoundsException JavaDoc e) {
131             // expected
132
}
133     }
134
135     /**
136      * Override.
137      */

138     public void testListSetByIndexBoundsChecking() {
139         List JavaDoc list = makeEmptyList();
140         Object JavaDoc element = getOtherElements()[0];
141         try {
142             list.set(-1, element);
143             fail("List.set should throw IndexOutOfBoundsException [-1]");
144         } catch (IndexOutOfBoundsException JavaDoc e) {
145             // expected
146
}
147     }
148
149     /**
150      * Override.
151      */

152     public void testListSetByIndexBoundsChecking2() {
153         List JavaDoc list = makeFullList();
154         Object JavaDoc element = getOtherElements()[0];
155         try {
156             list.set(-1, element);
157             fail("List.set should throw IndexOutOfBoundsException [-1]");
158         } catch(IndexOutOfBoundsException JavaDoc e) {
159             // expected
160
}
161     }
162
163     //-----------------------------------------------------------------------
164
public String JavaDoc getCompatibilityVersion() {
165         return "3.2";
166     }
167
168 // public void testCreate() throws Exception {
169
// resetEmpty();
170
// writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/GrowthList.emptyCollection.version3.2.obj");
171
// resetFull();
172
// writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/GrowthList.fullCollection.version3.2.obj");
173
// }
174

175 }
176
Popular Tags