KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > adapters > TestAdapt


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  */

17 package org.apache.commons.collections.primitives.adapters;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.ListIterator JavaDoc;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.apache.commons.collections.primitives.ArrayByteList;
30 import org.apache.commons.collections.primitives.ArrayCharList;
31 import org.apache.commons.collections.primitives.ArrayDoubleList;
32 import org.apache.commons.collections.primitives.ArrayFloatList;
33 import org.apache.commons.collections.primitives.ArrayIntList;
34 import org.apache.commons.collections.primitives.ArrayLongList;
35 import org.apache.commons.collections.primitives.ArrayShortList;
36 import org.apache.commons.collections.primitives.ByteCollection;
37 import org.apache.commons.collections.primitives.ByteIterator;
38 import org.apache.commons.collections.primitives.ByteList;
39 import org.apache.commons.collections.primitives.ByteListIterator;
40 import org.apache.commons.collections.primitives.CharCollection;
41 import org.apache.commons.collections.primitives.CharIterator;
42 import org.apache.commons.collections.primitives.CharList;
43 import org.apache.commons.collections.primitives.CharListIterator;
44 import org.apache.commons.collections.primitives.DoubleCollection;
45 import org.apache.commons.collections.primitives.DoubleIterator;
46 import org.apache.commons.collections.primitives.DoubleList;
47 import org.apache.commons.collections.primitives.DoubleListIterator;
48 import org.apache.commons.collections.primitives.FloatCollection;
49 import org.apache.commons.collections.primitives.FloatIterator;
50 import org.apache.commons.collections.primitives.FloatList;
51 import org.apache.commons.collections.primitives.FloatListIterator;
52 import org.apache.commons.collections.primitives.IntCollection;
53 import org.apache.commons.collections.primitives.IntIterator;
54 import org.apache.commons.collections.primitives.IntList;
55 import org.apache.commons.collections.primitives.IntListIterator;
56 import org.apache.commons.collections.primitives.LongCollection;
57 import org.apache.commons.collections.primitives.LongIterator;
58 import org.apache.commons.collections.primitives.LongList;
59 import org.apache.commons.collections.primitives.LongListIterator;
60 import org.apache.commons.collections.primitives.ShortCollection;
61 import org.apache.commons.collections.primitives.ShortIterator;
62 import org.apache.commons.collections.primitives.ShortList;
63 import org.apache.commons.collections.primitives.ShortListIterator;
64
65 /**
66  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
67  * @author Rodney Waldhoff
68  */

69 public class TestAdapt extends TestCase {
70
71     // conventional
72
// ------------------------------------------------------------------------
73

74     public TestAdapt(String JavaDoc testName) {
75         super(testName);
76     }
77
78     public static Test suite() {
79         return new TestSuite(TestAdapt.class);
80     }
81
82     // tests
83
// ------------------------------------------------------------------------
84

85     public void testHasPublicConstructorForReflectionBasedAPIs() {
86         assertNotNull(new Adapt());
87     }
88     
89     // to object based
90
//---------------------------------------------------------------
91

92     public void testToCollection() {
93         assertNull(Adapt.toCollection((ArrayByteList)null));
94         assertTrue(Adapt.toCollection(new ArrayByteList()) instanceof Collection JavaDoc);
95         assertNull(Adapt.toCollection((ArrayCharList)null));
96         assertTrue(Adapt.toCollection(new ArrayCharList()) instanceof Collection JavaDoc);
97         assertNull(Adapt.toCollection((ArrayDoubleList)null));
98         assertTrue(Adapt.toCollection(new ArrayDoubleList()) instanceof Collection JavaDoc);
99         assertNull(Adapt.toCollection((ArrayFloatList)null));
100         assertTrue(Adapt.toCollection(new ArrayFloatList()) instanceof Collection JavaDoc);
101         assertNull(Adapt.toCollection((ArrayIntList)null));
102         assertTrue(Adapt.toCollection(new ArrayIntList()) instanceof Collection JavaDoc);
103         assertNull(Adapt.toCollection((ArrayLongList)null));
104         assertTrue(Adapt.toCollection(new ArrayLongList()) instanceof Collection JavaDoc);
105         assertNull(Adapt.toCollection((ArrayShortList)null));
106         assertTrue(Adapt.toCollection(new ArrayShortList()) instanceof Collection JavaDoc);
107     }
108     
109     public void testToList() {
110         assertNull(Adapt.toList((ArrayByteList)null));
111         assertTrue(Adapt.toList(new ArrayByteList()) instanceof List JavaDoc);
112         assertNull(Adapt.toList((ArrayCharList)null));
113         assertTrue(Adapt.toList(new ArrayCharList()) instanceof List JavaDoc);
114         assertNull(Adapt.toList((ArrayDoubleList)null));
115         assertTrue(Adapt.toList(new ArrayDoubleList()) instanceof List JavaDoc);
116         assertNull(Adapt.toList((ArrayFloatList)null));
117         assertTrue(Adapt.toList(new ArrayFloatList()) instanceof List JavaDoc);
118         assertNull(Adapt.toList((ArrayIntList)null));
119         assertTrue(Adapt.toList(new ArrayIntList()) instanceof List JavaDoc);
120         assertNull(Adapt.toList((ArrayLongList)null));
121         assertTrue(Adapt.toList(new ArrayLongList()) instanceof List JavaDoc);
122         assertNull(Adapt.toList((ArrayShortList)null));
123         assertTrue(Adapt.toList(new ArrayShortList()) instanceof List JavaDoc);
124     }
125     
126     public void testToIterator() {
127         assertNull(Adapt.toIterator((ByteIterator)null));
128         assertTrue(Adapt.toIterator(new ArrayByteList().iterator()) instanceof Iterator JavaDoc);
129         assertNull(Adapt.toIterator((CharIterator)null));
130         assertTrue(Adapt.toIterator(new ArrayCharList().iterator()) instanceof Iterator JavaDoc);
131         assertNull(Adapt.toIterator((DoubleIterator)null));
132         assertTrue(Adapt.toIterator(new ArrayDoubleList().iterator()) instanceof Iterator JavaDoc);
133         assertNull(Adapt.toIterator((FloatIterator)null));
134         assertTrue(Adapt.toIterator(new ArrayFloatList().iterator()) instanceof Iterator JavaDoc);
135         assertNull(Adapt.toIterator((IntIterator)null));
136         assertTrue(Adapt.toIterator(new ArrayIntList().iterator()) instanceof Iterator JavaDoc);
137         assertNull(Adapt.toIterator((LongIterator)null));
138         assertTrue(Adapt.toIterator(new ArrayLongList().iterator()) instanceof Iterator JavaDoc);
139         assertNull(Adapt.toIterator((ShortIterator)null));
140         assertTrue(Adapt.toIterator(new ArrayShortList().iterator()) instanceof Iterator JavaDoc);
141     }
142
143     public void testToListIterator() {
144         assertNull(Adapt.toListIterator((ByteListIterator)null));
145         assertTrue(Adapt.toListIterator(new ArrayByteList().listIterator()) instanceof ListIterator JavaDoc);
146         assertNull(Adapt.toListIterator((CharListIterator)null));
147         assertTrue(Adapt.toListIterator(new ArrayCharList().listIterator()) instanceof ListIterator JavaDoc);
148         assertNull(Adapt.toListIterator((DoubleListIterator)null));
149         assertTrue(Adapt.toListIterator(new ArrayDoubleList().listIterator()) instanceof ListIterator JavaDoc);
150         assertNull(Adapt.toListIterator((FloatListIterator)null));
151         assertTrue(Adapt.toListIterator(new ArrayFloatList().listIterator()) instanceof ListIterator JavaDoc);
152         assertNull(Adapt.toListIterator((IntListIterator)null));
153         assertTrue(Adapt.toListIterator(new ArrayIntList().listIterator()) instanceof ListIterator JavaDoc);
154         assertNull(Adapt.toListIterator((LongListIterator)null));
155         assertTrue(Adapt.toListIterator(new ArrayLongList().listIterator()) instanceof ListIterator JavaDoc);
156         assertNull(Adapt.toListIterator((ShortListIterator)null));
157         assertTrue(Adapt.toListIterator(new ArrayShortList().listIterator()) instanceof ListIterator JavaDoc);
158     }
159
160     // to byte based
161
//---------------------------------------------------------------
162

163     public void testToByteType() {
164         assertTrue(Adapt.toByteCollection(new ArrayList JavaDoc()) instanceof ByteCollection);
165         assertTrue(Adapt.toByteList(new ArrayList JavaDoc()) instanceof ByteList);
166         assertTrue(Adapt.toByteIterator(new ArrayList JavaDoc().iterator()) instanceof ByteIterator);
167         assertTrue(Adapt.toByteListIterator(new ArrayList JavaDoc().listIterator()) instanceof ByteListIterator);
168     }
169
170     public void testToByteTypeFromNull() {
171         assertNull(Adapt.toByteCollection(null));
172         assertNull(Adapt.toByteList(null));
173         assertNull(Adapt.toByteIterator(null));
174         assertNull(Adapt.toByteListIterator(null));
175     }
176
177     // to char based
178
//---------------------------------------------------------------
179

180     public void testToCharType() {
181         assertTrue(Adapt.toCharCollection(new ArrayList JavaDoc()) instanceof CharCollection);
182         assertTrue(Adapt.toCharList(new ArrayList JavaDoc()) instanceof CharList);
183         assertTrue(Adapt.toCharIterator(new ArrayList JavaDoc().iterator()) instanceof CharIterator);
184         assertTrue(Adapt.toCharListIterator(new ArrayList JavaDoc().listIterator()) instanceof CharListIterator);
185     }
186
187     public void testToCharTypeFromNull() {
188         assertNull(Adapt.toCharCollection(null));
189         assertNull(Adapt.toCharList(null));
190         assertNull(Adapt.toCharIterator(null));
191         assertNull(Adapt.toCharListIterator(null));
192     }
193
194     // to double based
195
//---------------------------------------------------------------
196

197     public void testToDoubleType() {
198         assertTrue(Adapt.toDoubleCollection(new ArrayList JavaDoc()) instanceof DoubleCollection);
199         assertTrue(Adapt.toDoubleList(new ArrayList JavaDoc()) instanceof DoubleList);
200         assertTrue(Adapt.toDoubleIterator(new ArrayList JavaDoc().iterator()) instanceof DoubleIterator);
201         assertTrue(Adapt.toDoubleListIterator(new ArrayList JavaDoc().listIterator()) instanceof DoubleListIterator);
202     }
203
204     public void testToDoubleTypeFromNull() {
205         assertNull(Adapt.toDoubleCollection(null));
206         assertNull(Adapt.toDoubleList(null));
207         assertNull(Adapt.toDoubleIterator(null));
208         assertNull(Adapt.toDoubleListIterator(null));
209     }
210
211     // to float based
212
//---------------------------------------------------------------
213

214     public void testToFloatType() {
215         assertTrue(Adapt.toFloatCollection(new ArrayList JavaDoc()) instanceof FloatCollection);
216         assertTrue(Adapt.toFloatList(new ArrayList JavaDoc()) instanceof FloatList);
217         assertTrue(Adapt.toFloatIterator(new ArrayList JavaDoc().iterator()) instanceof FloatIterator);
218         assertTrue(Adapt.toFloatListIterator(new ArrayList JavaDoc().listIterator()) instanceof FloatListIterator);
219     }
220
221     public void testToFloatTypeFromNull() {
222         assertNull(Adapt.toFloatCollection(null));
223         assertNull(Adapt.toFloatList(null));
224         assertNull(Adapt.toFloatIterator(null));
225         assertNull(Adapt.toFloatListIterator(null));
226     }
227
228     // to int based
229
//---------------------------------------------------------------
230

231     public void testToIntType() {
232         assertTrue(Adapt.toIntCollection(new ArrayList JavaDoc()) instanceof IntCollection);
233         assertTrue(Adapt.toIntList(new ArrayList JavaDoc()) instanceof IntList);
234         assertTrue(Adapt.toIntIterator(new ArrayList JavaDoc().iterator()) instanceof IntIterator);
235         assertTrue(Adapt.toIntListIterator(new ArrayList JavaDoc().listIterator()) instanceof IntListIterator);
236     }
237
238     public void testToIntTypeFromNull() {
239         assertNull(Adapt.toIntCollection(null));
240         assertNull(Adapt.toIntList(null));
241         assertNull(Adapt.toIntIterator(null));
242         assertNull(Adapt.toIntListIterator(null));
243     }
244
245     // to long based
246
//---------------------------------------------------------------
247

248     public void testToLongType() {
249         assertTrue(Adapt.toLongCollection(new ArrayList JavaDoc()) instanceof LongCollection);
250         assertTrue(Adapt.toLongList(new ArrayList JavaDoc()) instanceof LongList);
251         assertTrue(Adapt.toLongIterator(new ArrayList JavaDoc().iterator()) instanceof LongIterator);
252         assertTrue(Adapt.toLongListIterator(new ArrayList JavaDoc().listIterator()) instanceof LongListIterator);
253     }
254
255     public void testToLongTypeFromNull() {
256         assertNull(Adapt.toLongCollection(null));
257         assertNull(Adapt.toLongList(null));
258         assertNull(Adapt.toLongIterator(null));
259         assertNull(Adapt.toLongListIterator(null));
260     }
261
262     // to short based
263
//---------------------------------------------------------------
264

265     public void testToShortType() {
266         assertTrue(Adapt.toShortCollection(new ArrayList JavaDoc()) instanceof ShortCollection);
267         assertTrue(Adapt.toShortList(new ArrayList JavaDoc()) instanceof ShortList);
268         assertTrue(Adapt.toShortIterator(new ArrayList JavaDoc().iterator()) instanceof ShortIterator);
269         assertTrue(Adapt.toShortListIterator(new ArrayList JavaDoc().listIterator()) instanceof ShortListIterator);
270     }
271
272     public void testToShortTypeFromNull() {
273         assertNull(Adapt.toShortCollection(null));
274         assertNull(Adapt.toShortList(null));
275         assertNull(Adapt.toShortIterator(null));
276         assertNull(Adapt.toShortListIterator(null));
277     }
278 }
279
Popular Tags