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.FloatList;
025import org.apache.commons.collections.primitives.FloatListIterator;
026
027/**
028 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
029 * @author Rodney Waldhoff
030 */
031public class TestBaseProxyFloatList extends TestCase {
032
033    // conventional
034    // ------------------------------------------------------------------------
035
036    public TestBaseProxyFloatList(String testName) {
037        super(testName);
038    }
039
040    public static Test suite() {
041        return new TestSuite(TestBaseProxyFloatList.class);
042    }
043
044    // tests
045    // ------------------------------------------------------------------------
046    
047    public void testListCallsAreProxied() {
048        final InvocationCounter proxied = new InvocationCounter();
049        BaseProxyFloatList list = new BaseProxyFloatList() {
050            protected FloatList getProxiedList() {
051                return proxied;
052            }
053        };
054        
055        assertSame(list.getProxiedList(),list.getProxiedCollection());
056        
057        assertEquals(0,proxied.getAddCount());
058        list.add(1,(float)1);
059        assertEquals(1,proxied.getAddCount());
060
061        assertEquals(0,proxied.getAddAllCount());
062        list.addAll(1,null);
063        assertEquals(1,proxied.getAddAllCount());
064
065        assertEquals(0,proxied.getGetCount());
066        list.get(1);
067        assertEquals(1,proxied.getGetCount());
068
069        assertEquals(0,proxied.getIndexOfCount());
070        list.indexOf((float)1);
071        assertEquals(1,proxied.getIndexOfCount());
072
073        assertEquals(0,proxied.getLastIndexOfCount());
074        list.lastIndexOf((float)1);
075        assertEquals(1,proxied.getLastIndexOfCount());
076
077        assertEquals(0,proxied.getListIteratorCount());
078        list.listIterator();
079        assertEquals(1,proxied.getListIteratorCount());
080
081        assertEquals(0,proxied.getListIteratorFromCount());
082        list.listIterator(1);
083        assertEquals(1,proxied.getListIteratorFromCount());
084
085        assertEquals(0,proxied.getRemoveElementAtCount());
086        list.removeElementAt(1);
087        assertEquals(1,proxied.getRemoveElementAtCount());
088
089        assertEquals(0,proxied.getSetCount());
090        list.set(1,(float)1);
091        assertEquals(1,proxied.getSetCount());
092
093        assertEquals(0,proxied.getSubListCount());
094        list.subList(1,2);
095        assertEquals(1,proxied.getSubListCount());
096    }
097    
098    // inner classes
099    // ------------------------------------------------------------------------
100
101    static class InvocationCounter extends TestBaseProxyFloatCollection.InvocationCounter implements FloatList {
102        private int addCount;
103        private int addAllCount;
104        private int getCount;
105        private int indexOfCount;
106        private int lastIndexOfCount;
107        private int listIteratorCount;
108        private int listIteratorFromCount;
109        private int removeElementAtCount;
110        private int setCount;
111        private int subListCount;
112        
113        public void add(int index, float element) {
114            addCount++;
115        }
116
117        public boolean addAll(int index, FloatCollection collection) {
118            addAllCount++;
119            return false;
120        }
121
122        public float get(int index) {
123            getCount++;
124            return 0;
125        }
126
127        public int indexOf(float element) {
128            indexOfCount++;
129            return 0;
130        }
131
132        public int lastIndexOf(float element) {
133            lastIndexOfCount++;
134            return 0;
135        }
136
137        public FloatListIterator listIterator() {
138            listIteratorCount++;
139            return null;
140        }
141
142        public FloatListIterator listIterator(int index) {
143            listIteratorFromCount++;
144            return null;
145        }
146
147        public float removeElementAt(int index) {
148            removeElementAtCount++;
149            return 0;
150        }
151
152        public float set(int index, float element) {
153            setCount++;
154            return 0;
155        }
156
157        public FloatList subList(int fromIndex, int toIndex) {
158            subListCount++;
159            return null;
160        }
161
162        public int getAddAllCount() {
163            return addAllCount;
164        }
165
166        public int getAddCount() {
167            return addCount;
168        }
169
170        public int getGetCount() {
171            return getCount;
172        }
173
174        public int getIndexOfCount() {
175            return indexOfCount;
176        }
177
178        public int getLastIndexOfCount() {
179            return lastIndexOfCount;
180        }
181
182        public int getListIteratorCount() {
183            return listIteratorCount;
184        }
185
186        public int getListIteratorFromCount() {
187            return listIteratorFromCount;
188        }
189
190        public int getRemoveElementAtCount() {
191            return removeElementAtCount;
192        }
193
194        public int getSetCount() {
195            return setCount;
196        }
197
198        public int getSubListCount() {
199            return subListCount;
200        }
201
202    }
203}