KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > index > VMIndexLinkedListTest


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

18 package org.apache.activemq.kaha.impl.index;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.apache.activemq.kaha.StoreEntry;
26 import org.apache.activemq.kaha.impl.index.IndexItem;
27 import org.apache.activemq.kaha.impl.index.IndexLinkedList;
28
29 /**
30 * @version $Revision: 1.2 $
31 */

32 public class VMIndexLinkedListTest extends TestCase{
33     static final int NUMBER = 10;
34     private IndexItem root;
35     private List JavaDoc testData = new ArrayList JavaDoc();
36     private IndexLinkedList list;
37     protected void setUp() throws Exception JavaDoc{
38         super.setUp();
39         for (int i =0; i < NUMBER; i++){
40             testData.add(new IndexItem());
41         }
42         root = new IndexItem();
43         list = new VMIndexLinkedList(root);
44     }
45
46     protected void tearDown() throws Exception JavaDoc{
47         super.tearDown();
48         testData.clear();
49         list = null;
50     }
51
52     /*
53      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getFirst()'
54      */

55     public void testGetFirst(){
56         for (int i =0; i < testData.size(); i++){
57             list.add((IndexItem) testData.get(i));
58         }
59         assertTrue(list.getFirst()==testData.get(0));
60     }
61
62     /*
63      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getLast()'
64      */

65     public void testGetLast(){
66         for (int i =0; i < testData.size(); i++){
67             list.add((IndexItem) testData.get(i));
68         }
69         assertTrue(list.getLast()==testData.get(testData.size()-1));
70     }
71
72     /*
73      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.removeFirst()'
74      */

75     public void testRemoveFirst(){
76         for (int i =0; i < testData.size(); i++){
77             list.add((IndexItem) testData.get(i));
78         }
79         assertTrue(list.removeFirst()==testData.get(0));
80     }
81
82     /*
83      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.removeLast()'
84      */

85     public void testRemoveLast(){
86         for (int i =0; i < testData.size(); i++){
87             list.add((IndexItem) testData.get(i));
88         }
89         assertTrue(list.removeLast()==testData.get(testData.size()-1));
90     }
91
92     /*
93      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.addFirst(IndexItem)'
94      */

95     public void testAddFirst(){
96         for (int i =0; i < testData.size(); i++){
97             list.addFirst((IndexItem) testData.get(i));
98         }
99         int count = 0;
100         for (int i =testData.size()-1; i>=0; i--){
101             assertTrue(testData.get(i)==list.get(count++));
102         }
103     }
104
105     /*
106      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.addLast(IndexItem)'
107      */

108     public void testAddLast(){
109         for (int i =0; i < testData.size(); i++){
110             list.addLast((IndexItem) testData.get(i));
111         }
112         for (int i =0; i < testData.size(); i++){
113             assertTrue(testData.get(i)==list.get(i));
114         }
115     }
116
117     /*
118      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.size()'
119      */

120     public void testSize(){
121         for (int i =0; i < testData.size(); i++){
122             list.addLast((IndexItem) testData.get(i));
123             assertTrue(list.size()==i+1);
124         }
125     }
126
127     /*
128      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.isEmpty()'
129      */

130     public void testIsEmpty(){
131         for (int i =0; i < testData.size(); i++){
132             list.addLast((IndexItem) testData.get(i));
133             assertTrue(list.size()==i+1);
134         }
135         list.clear();
136         assertTrue(list.isEmpty());
137     }
138
139     /*
140      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.add(IndexItem)'
141      */

142     public void testAddIndexItem(){
143         for (int i =0; i < testData.size(); i++){
144             list.add((IndexItem) testData.get(i));
145         }
146         for (int i =0; i < testData.size(); i++){
147             assertTrue(testData.get(i)==list.get(i));
148         }
149     }
150
151     /*
152      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.clear()'
153      */

154     public void testClear(){
155         for (int i =0; i < testData.size(); i++){
156             list.addLast((IndexItem) testData.get(i));
157             assertTrue(list.size()==i+1);
158         }
159         list.clear();
160         assertTrue(list.isEmpty());
161     }
162
163     
164     /*
165      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.add(int, IndexItem)'
166      */

167     public void testAddIntIndexItem(){
168         for (int i =0; i < testData.size(); i++){
169             list.add(i,(IndexItem) testData.get(i));
170         }
171         for (int i =0; i < testData.size(); i++){
172             assertTrue(testData.get(i)==list.get(i));
173         }
174     }
175
176     /*
177      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.remove(int)'
178      */

179     public void testRemoveInt(){
180         for (int i =0; i < testData.size(); i++){
181             list.add(i,(IndexItem) testData.get(i));
182         }
183         for (int i =0; i < testData.size(); i++){
184             list.remove(0);
185         }
186         assertTrue(list.isEmpty());
187         for (int i =0; i < testData.size(); i++){
188             list.add(i,(IndexItem) testData.get(i));
189         }
190         for (int i =0; i < testData.size(); i++){
191             list.remove(list.size()-1);
192         }
193         assertTrue(list.isEmpty());
194     }
195
196     /*
197      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.indexOf(IndexItem)'
198      */

199     public void testIndexOf(){
200         for (int i =0; i < testData.size(); i++){
201             list.add(i,(IndexItem) testData.get(i));
202         }
203         for (int i =0; i < testData.size(); i++){
204             assertTrue(list.indexOf((StoreEntry) testData.get(i))==i);
205         }
206     }
207
208     /*
209      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getNextEntry(IndexItem)'
210      */

211     public void testGetNextEntry(){
212         for (int i =0; i < testData.size(); i++){
213             list.add(i,(IndexItem) testData.get(i));
214         }
215         IndexItem next = list.getFirst();
216         int count = 0;
217         while (next != null){
218             assertTrue(next==testData.get(count++));
219             next = list.getNextEntry(next);
220             assertTrue(next != root);
221         }
222     }
223
224     /*
225      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getPrevEntry(IndexItem)'
226      */

227     public void testGetPrevEntry(){
228         for (int i =0; i < testData.size(); i++){
229             list.add(i,(IndexItem) testData.get(i));
230         }
231         IndexItem next = list.getLast();
232         int count = testData.size()-1;
233         while (next != null){
234             assertTrue(next==testData.get(count--));
235             next = list.getPrevEntry(next);
236             assertTrue(next != root);
237         }
238     }
239
240     
241
242     /*
243      * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.remove(IndexItem)'
244      */

245     public void testRemoveIndexItem(){
246         for (int i =0; i < testData.size(); i++){
247             list.add(i,(IndexItem) testData.get(i));
248         }
249         for (int i =0; i < testData.size(); i++){
250             list.remove((IndexItem)testData.get(i));
251             assertTrue(list.size()==testData.size()-i-1);
252         }
253     }
254 }
255
Popular Tags