KickJava   Java API By Example, From Geeks To Geeks.

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


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.ByteCollection;
24 import org.apache.commons.collections.primitives.ByteList;
25 import org.apache.commons.collections.primitives.ByteListIterator;
26
27 /**
28  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
29  * @author Rodney Waldhoff
30  */

31 public class TestBaseProxyByteList extends TestCase {
32
33     // conventional
34
// ------------------------------------------------------------------------
35

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

47     public void testListCallsAreProxied() {
48         final InvocationCounter proxied = new InvocationCounter();
49         BaseProxyByteList list = new BaseProxyByteList() {
50             protected ByteList getProxiedList() {
51                 return proxied;
52             }
53         };
54         
55         assertSame(list.getProxiedList(),list.getProxiedCollection());
56         
57         assertEquals(0,proxied.getAddCount());
58         list.add(1,(byte)1);
59         assertEquals(1,proxied.getAddCount());
60
61         assertEquals(0,proxied.getAddAllCount());
62         list.addAll(1,null);
63         assertEquals(1,proxied.getAddAllCount());
64
65         assertEquals(0,proxied.getGetCount());
66         list.get(1);
67         assertEquals(1,proxied.getGetCount());
68
69         assertEquals(0,proxied.getIndexOfCount());
70         list.indexOf((byte)1);
71         assertEquals(1,proxied.getIndexOfCount());
72
73         assertEquals(0,proxied.getLastIndexOfCount());
74         list.lastIndexOf((byte)1);
75         assertEquals(1,proxied.getLastIndexOfCount());
76
77         assertEquals(0,proxied.getListIteratorCount());
78         list.listIterator();
79         assertEquals(1,proxied.getListIteratorCount());
80
81         assertEquals(0,proxied.getListIteratorFromCount());
82         list.listIterator(1);
83         assertEquals(1,proxied.getListIteratorFromCount());
84
85         assertEquals(0,proxied.getRemoveElementAtCount());
86         list.removeElementAt(1);
87         assertEquals(1,proxied.getRemoveElementAtCount());
88
89         assertEquals(0,proxied.getSetCount());
90         list.set(1,(byte)1);
91         assertEquals(1,proxied.getSetCount());
92
93         assertEquals(0,proxied.getSubListCount());
94         list.subList(1,2);
95         assertEquals(1,proxied.getSubListCount());
96     }
97     
98     // inner classes
99
// ------------------------------------------------------------------------
100

101     static class InvocationCounter extends TestBaseProxyByteCollection.InvocationCounter implements ByteList {
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, byte element) {
114             addCount++;
115         }
116
117         public boolean addAll(int index, ByteCollection collection) {
118             addAllCount++;
119             return false;
120         }
121
122         public byte get(int index) {
123             getCount++;
124             return 0;
125         }
126
127         public int indexOf(byte element) {
128             indexOfCount++;
129             return 0;
130         }
131
132         public int lastIndexOf(byte element) {
133             lastIndexOfCount++;
134             return 0;
135         }
136
137         public ByteListIterator listIterator() {
138             listIteratorCount++;
139             return null;
140         }
141
142         public ByteListIterator listIterator(int index) {
143             listIteratorFromCount++;
144             return null;
145         }
146
147         public byte removeElementAt(int index) {
148             removeElementAtCount++;
149             return 0;
150         }
151
152         public byte set(int index, byte element) {
153             setCount++;
154             return 0;
155         }
156
157         public ByteList 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 }
Popular Tags