001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections.primitives.decorators;
018
019import junit.framework.Test;
020import junit.framework.TestCase;
021import junit.framework.TestSuite;
022
023import org.apache.commons.collections.primitives.FloatCollection;
024import org.apache.commons.collections.primitives.FloatIterator;
025
026/**
027 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
028 * @author Rodney Waldhoff
029 */
030public class TestBaseProxyFloatCollection extends TestCase {
031
032    // conventional
033    // ------------------------------------------------------------------------
034
035    public TestBaseProxyFloatCollection(String testName) {
036        super(testName);
037    }
038
039    public static Test suite() {
040        return new TestSuite(TestBaseProxyFloatCollection.class);
041    }
042
043    // tests
044    // ------------------------------------------------------------------------
045    
046    public void testCollectionCallsAreProxied() {
047        final InvocationCounter proxied = new InvocationCounter();
048        FloatCollection collection = new BaseProxyFloatCollection() {
049            protected FloatCollection getProxiedCollection() {
050                return proxied;
051            }
052        };
053        
054        assertEquals(0,proxied.getAddCount());
055        collection.add((float)1);
056        assertEquals(1,proxied.getAddCount());
057
058        assertEquals(0,proxied.getAddAllCount());
059        collection.addAll(null);
060        assertEquals(1,proxied.getAddAllCount());
061        
062        assertEquals(0,proxied.getClearCount());
063        collection.clear();
064        assertEquals(1,proxied.getClearCount());
065
066        assertEquals(0,proxied.getContainsCount());
067        collection.contains((float)1);
068        assertEquals(1,proxied.getContainsCount());
069
070        assertEquals(0,proxied.getContainsAllCount());
071        collection.containsAll(null);
072        assertEquals(1,proxied.getContainsAllCount());
073
074        assertEquals(0,proxied.getIsEmptyCount());
075        collection.isEmpty();
076        assertEquals(1,proxied.getIsEmptyCount());
077
078        assertEquals(0,proxied.getIteratorCount());
079        collection.iterator();
080        assertEquals(1,proxied.getIteratorCount());
081
082        assertEquals(0,proxied.getRemoveAllCount());
083        collection.removeAll(null);
084        assertEquals(1,proxied.getRemoveAllCount());
085
086        assertEquals(0,proxied.getRetainAllCount());
087        collection.retainAll(null);
088        assertEquals(1,proxied.getRetainAllCount());
089
090        assertEquals(0,proxied.getRemoveElementCount());
091        collection.removeElement((float)1);
092        assertEquals(1,proxied.getRemoveElementCount());
093
094        assertEquals(0,proxied.getSizeCount());
095        collection.size();
096        assertEquals(1,proxied.getSizeCount());
097
098        assertEquals(0,proxied.getToArrayFloatArrayCount());
099        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 obj) {
207            _equals++;
208            return false;
209        }
210
211        public int hashCode() {
212            _hashCode++;
213            return 0;
214        }
215
216        public String 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}