KickJava   Java API By Example, From Geeks To Geeks.

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


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.LongCollection;
24 import org.apache.commons.collections.primitives.LongIterator;
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 TestBaseProxyLongCollection extends TestCase {
31
32     // conventional
33
// ------------------------------------------------------------------------
34

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

46     public void testCollectionCallsAreProxied() {
47         final InvocationCounter proxied = new InvocationCounter();
48         LongCollection collection = new BaseProxyLongCollection() {
49             protected LongCollection getProxiedCollection() {
50                 return proxied;
51             }
52         };
53         
54         assertEquals(0,proxied.getAddCount());
55         collection.add(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(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(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.getToArrayLongArrayCount());
99         collection.toArray(new long[0]);
100         assertEquals(1,proxied.getToArrayLongArrayCount());
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 LongCollection {
124         private int _toArrayLongArray;
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(long element) {
143             _add++;
144             return false;
145         }
146
147         public boolean addAll(LongCollection c) {
148             _addAll++;
149             return false;
150         }
151
152         public void clear() {
153             _clear++;
154         }
155
156         public boolean contains(long element) {
157             _contains++;
158             return false;
159         }
160
161         public boolean containsAll(LongCollection c) {
162             _containsAll++;
163             return false;
164         }
165
166         public boolean isEmpty() {
167             _isEmpty++;
168             return false;
169         }
170
171         public LongIterator iterator() {
172             _iterator++;
173             return null;
174         }
175
176         public boolean removeAll(LongCollection c) {
177             _removeAll++;
178             return false;
179         }
180
181         public boolean removeElement(long element) {
182             _removeElement++;
183             return false;
184         }
185
186         public boolean retainAll(LongCollection c) {
187             _retainAll++;
188             return false;
189         }
190
191         public int size() {
192             _size++;
193             return 0;
194         }
195
196         public long[] toArray() {
197             _toArray++;
198             return null;
199         }
200
201         public long[] toArray(long[] a) {
202             _toArrayLongArray++;
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 getToArrayLongArrayCount() {
271             return _toArrayLongArray;
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