1 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.ShortCollection; 24 import org.apache.commons.collections.primitives.ShortIterator; 25 26 30 public class TestBaseProxyShortCollection extends TestCase { 31 32 35 public TestBaseProxyShortCollection(String testName) { 36 super(testName); 37 } 38 39 public static Test suite() { 40 return new TestSuite(TestBaseProxyShortCollection.class); 41 } 42 43 46 public void testCollectionCallsAreProxied() { 47 final InvocationCounter proxied = new InvocationCounter(); 48 ShortCollection collection = new BaseProxyShortCollection() { 49 protected ShortCollection getProxiedCollection() { 50 return proxied; 51 } 52 }; 53 54 assertEquals(0,proxied.getAddCount()); 55 collection.add((short)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((short)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((short)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.getToArrayShortArrayCount()); 99 collection.toArray(new short[0]); 100 assertEquals(1,proxied.getToArrayShortArrayCount()); 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 123 static class InvocationCounter implements ShortCollection { 124 private int _toArrayShortArray; 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(short element) { 143 _add++; 144 return false; 145 } 146 147 public boolean addAll(ShortCollection c) { 148 _addAll++; 149 return false; 150 } 151 152 public void clear() { 153 _clear++; 154 } 155 156 public boolean contains(short element) { 157 _contains++; 158 return false; 159 } 160 161 public boolean containsAll(ShortCollection c) { 162 _containsAll++; 163 return false; 164 } 165 166 public boolean isEmpty() { 167 _isEmpty++; 168 return false; 169 } 170 171 public ShortIterator iterator() { 172 _iterator++; 173 return null; 174 } 175 176 public boolean removeAll(ShortCollection c) { 177 _removeAll++; 178 return false; 179 } 180 181 public boolean removeElement(short element) { 182 _removeElement++; 183 return false; 184 } 185 186 public boolean retainAll(ShortCollection c) { 187 _retainAll++; 188 return false; 189 } 190 191 public int size() { 192 _size++; 193 return 0; 194 } 195 196 public short[] toArray() { 197 _toArray++; 198 return null; 199 } 200 201 public short[] toArray(short[] a) { 202 _toArrayShortArray++; 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 getToArrayShortArrayCount() { 271 return _toArrayShortArray; 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 |