KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > decorators > TestBaseProxyFloatCollection


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.decorators;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 import org.apache.commons.collections.primitives.FloatCollection;
24 import org.apache.commons.collections.primitives.FloatIterator;
25
26 /**
27  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
28  * @author Rodney Waldhoff
29  */

30 public class TestBaseProxyFloatCollection extends TestCase {
31
32     // conventional
33
// ------------------------------------------------------------------------
34

35     public TestBaseProxyFloatCollection(String JavaDoc testName) {
36         super(testName);
37     }
38
39     public static Test suite() {
40         return new TestSuite(TestBaseProxyFloatCollection.class);
41     }
42
43     // tests
44
// ------------------------------------------------------------------------
45

46     public void testCollectionCallsAreProxied() {
47         final InvocationCounter proxied = new InvocationCounter();
48         FloatCollection collection = new BaseProxyFloatCollection() {
49             protected FloatCollection getProxiedCollection() {
50                 return proxied;
51             }
52         };
53         
54         assertEquals(0,proxied.getAddCount());
55         collection.add((float)1);
56         assertEquals(1,proxied.getAddCount());
57
58         assertEquals(0,proxied.getAddAllCount());
59         collection.addAll(null);
60         assertEquals(1,proxied.getAddAllCount());
61         
62         assertEquals(0,proxied.getClearCount());
63         collection.clear();
64         assertEquals(1,proxied.getClearCount());
65
66         assertEquals(0,proxied.getContainsCount());
67         collection.contains((float)1);
68         assertEquals(1,proxied.getContainsCount());
69
70         assertEquals(0,proxied.getContainsAllCount());
71         collection.containsAll(null);
72         assertEquals(1,proxied.getContainsAllCount());
73
74         assertEquals(0,proxied.getIsEmptyCount());
75         collection.isEmpty();
76         assertEquals(1,proxied.getIsEmptyCount());
77
78         assertEquals(0,proxied.getIteratorCount());
79         collection.iterator();
80         assertEquals(1,proxied.getIteratorCount());
81
82         assertEquals(0,proxied.getRemoveAllCount());
83         collection.removeAll(null);
84         assertEquals(1,proxied.getRemoveAllCount());
85
86         assertEquals(0,proxied.getRetainAllCount());
87         collection.retainAll(null);
88         assertEquals(1,proxied.getRetainAllCount());
89
90         assertEquals(0,proxied.getRemoveElementCount());
91         collection.removeElement((float)1);
92         assertEquals(1,proxied.getRemoveElementCount());
93
94         assertEquals(0,proxied.getSizeCount());
95         collection.size();
96         assertEquals(1,proxied.getSizeCount());
97
98         assertEquals(0,proxied.getToArrayFloatArrayCount());
99         collection.toArray(new float[0]);
100         assertEquals(1,proxied.getToArrayFloatArrayCount());
101         
102         assertEquals(0,proxied.getToArrayCount());
103         collection.toArray();
104         assertEquals(1,proxied.getToArrayCount());
105         
106         assertEquals(0,proxied.getToStringCount());
107         collection.toString();
108         assertEquals(1,proxied.getToStringCount());
109         
110         assertEquals(0,proxied.getEqualsCount());
111         collection.equals(null);
112         assertEquals(1,proxied.getEqualsCount());
113         
114         assertEquals(0,proxied.getHashCodeCount());
115         collection.hashCode();
116         assertEquals(1,proxied.getHashCodeCount());
117         
118     }
119     
120     // inner classes
121
// ------------------------------------------------------------------------
122

123     static class InvocationCounter implements FloatCollection {
124         private int _toArrayFloatArray;
125         private int _toArray;
126         private int _size;
127         private int _retainAll;
128         private int _removeElement;
129         private int _removeAll;
130         private int _iterator;
131         private int _isEmpty;
132         private int _containsAll;
133         private int _contains;
134         private int _clear;
135         private int _addAll;
136         private int _add;
137
138         private int _equals;
139         private int _toString;
140         private int _hashCode;
141
142         public boolean add(float element) {
143             _add++;
144             return false;
145         }
146
147         public boolean addAll(FloatCollection c) {
148             _addAll++;
149             return false;
150         }
151
152         public void clear() {
153             _clear++;
154         }
155
156         public boolean contains(float element) {
157             _contains++;
158             return false;
159         }
160
161         public boolean containsAll(FloatCollection c) {
162             _containsAll++;
163             return false;
164         }
165
166         public boolean isEmpty() {
167             _isEmpty++;
168             return false;
169         }
170
171         public FloatIterator iterator() {
172             _iterator++;
173             return null;
174         }
175
176         public boolean removeAll(FloatCollection c) {
177             _removeAll++;
178             return false;
179         }
180
181         public boolean removeElement(float element) {
182             _removeElement++;
183             return false;
184         }
185
186         public boolean retainAll(FloatCollection c) {
187             _retainAll++;
188             return false;
189         }
190
191         public int size() {
192             _size++;
193             return 0;
194         }
195
196         public float[] toArray() {
197             _toArray++;
198             return null;
199         }
200
201         public float[] toArray(float[] a) {
202             _toArrayFloatArray++;
203             return null;
204         }
205
206         public boolean equals(Object JavaDoc obj) {
207             _equals++;
208             return false;
209         }
210
211         public int hashCode() {
212             _hashCode++;
213             return 0;
214         }
215
216         public String JavaDoc toString() {
217             _toString++;
218             return null;
219         }
220
221
222         public int getAddCount() {
223             return _add;
224         }
225
226         public int getAddAllCount() {
227             return _addAll;
228         }
229
230         public int getClearCount() {
231             return _clear;
232         }
233
234         public int getContainsCount() {
235             return _contains;
236         }
237
238         public int getContainsAllCount() {
239             return _containsAll;
240         }
241
242         public int getIsEmptyCount() {
243             return _isEmpty;
244         }
245
246         public int getIteratorCount() {
247             return _iterator;
248         }
249
250         public int getRemoveAllCount() {
251             return _removeAll;
252         }
253
254         public int getRemoveElementCount() {
255             return _removeElement;
256         }
257
258         public int getRetainAllCount() {
259             return _retainAll;
260         }
261
262         public int getSizeCount() {
263             return _size;
264         }
265
266         public int getToArrayCount() {
267             return _toArray;
268         }
269
270         public int getToArrayFloatArrayCount() {
271             return _toArrayFloatArray;
272         }
273
274         public int getEqualsCount() {
275             return _equals;
276         }
277
278         public int getHashCodeCount() {
279             return _hashCode;
280         }
281
282         public int getToStringCount() {
283             return _toString;
284         }
285
286     }
287 }
Popular Tags