1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
package com.jeantessier.classreader; |
34 | |
|
35 | |
import java.util.*; |
36 | |
|
37 | |
import org.jmock.integration.junit3.*; |
38 | |
import org.jmock.*; |
39 | |
import org.apache.oro.text.*; |
40 | |
|
41 | 72 | public class TestFilteringSymbolGathererStrategy extends MockObjectTestCase { |
42 | |
private static final String SOME_PACKAGE_NAME = "some.package"; |
43 | |
private static final String SOME_CLASS_NAME = SOME_PACKAGE_NAME + ".SomeClass"; |
44 | |
private static final String SOME_FIELD_SIGNATURE = SOME_CLASS_NAME + ".someField"; |
45 | |
private static final String SOME_METHOD_SIGNATURE = SOME_CLASS_NAME + ".someMethod()"; |
46 | |
private static final String SOME_LOCAL_VARIABLE_NAME = "someLocalVariable"; |
47 | |
private static final String ANOTHER_PACKAGE_NAME = "another.package"; |
48 | |
private static final String ANOTHER_CLASS_NAME = ANOTHER_PACKAGE_NAME + ".AnotherClass"; |
49 | |
private static final String ANOTHER_FIELD_SIGNATURE = ANOTHER_CLASS_NAME + ".anotherField"; |
50 | |
private static final String ANOTHER_METHOD_SIGNATURE = ANOTHER_CLASS_NAME + ".anotherMethod()"; |
51 | |
private static final String ANOTHER_LOCAL_VARIABLE_NAME = "anotherLocalVariable"; |
52 | |
|
53 | |
private Classfile mockClassfile; |
54 | |
private Field_info mockField; |
55 | |
private Method_info mockMethod; |
56 | |
private LocalVariable mockLocalVariable; |
57 | |
private SymbolGathererStrategy mockStrategy; |
58 | |
|
59 | |
protected void setUp() throws Exception { |
60 | 28 | super.setUp(); |
61 | |
|
62 | 28 | mockClassfile = mock(Classfile.class); |
63 | 28 | mockField = mock(Field_info.class); |
64 | 28 | mockMethod = mock(Method_info.class); |
65 | 28 | mockLocalVariable = mock(LocalVariable.class); |
66 | 28 | mockStrategy = mock(SymbolGathererStrategy.class); |
67 | 28 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public void testIsMatching_class_matchingincludes() { |
74 | 1 | checking(new Expectations() {{ |
75 | 1 | one (mockClassfile).getClassName(); |
76 | 1 | will(returnValue(SOME_CLASS_NAME)); |
77 | 1 | one (mockStrategy).isMatching(mockClassfile); |
78 | 1 | }}); |
79 | |
|
80 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
81 | 1 | sut.isMatching(mockClassfile); |
82 | 1 | } |
83 | |
|
84 | |
public void testIsMatching_class_notmatchingincludes() { |
85 | 1 | checking(new Expectations() {{ |
86 | 1 | one (mockClassfile).getClassName(); |
87 | 1 | will(returnValue(ANOTHER_CLASS_NAME)); |
88 | 1 | }}); |
89 | |
|
90 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
91 | 1 | assertFalse(sut.isMatching(mockClassfile)); |
92 | 1 | } |
93 | |
|
94 | |
public void testIsMatching_class_noincludes() { |
95 | 1 | checking(new Expectations() {{ |
96 | 1 | one (mockClassfile).getClassName(); |
97 | 1 | }}); |
98 | |
|
99 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList()); |
100 | 1 | assertFalse(sut.isMatching(mockClassfile)); |
101 | 1 | } |
102 | |
|
103 | |
public void testIsMatching_class_badincludes() { |
104 | 1 | checking(new Expectations() {{ |
105 | 1 | one (mockClassfile).getClassName(); |
106 | 1 | }}); |
107 | |
|
108 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList()); |
109 | |
try { |
110 | 1 | sut.isMatching(mockClassfile); |
111 | 0 | fail("did not throw expection for bad excludes regular expression"); |
112 | 1 | } catch (MalformedCachePatternException ex) { |
113 | |
|
114 | 0 | } |
115 | 1 | } |
116 | |
|
117 | |
public void testIsMatching_class_matchingexcludes() { |
118 | 1 | checking(new Expectations() {{ |
119 | 1 | one (mockClassfile).getClassName(); |
120 | 1 | will(returnValue(SOME_CLASS_NAME)); |
121 | 1 | }}); |
122 | |
|
123 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
124 | 1 | assertFalse(sut.isMatching(mockClassfile)); |
125 | 1 | } |
126 | |
|
127 | |
public void testIsMatching_class_notmatchingexcludes() { |
128 | 1 | checking(new Expectations() {{ |
129 | 1 | one (mockClassfile).getClassName(); |
130 | 1 | will(returnValue(ANOTHER_CLASS_NAME)); |
131 | 1 | one (mockStrategy).isMatching(mockClassfile); |
132 | 1 | }}); |
133 | |
|
134 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
135 | 1 | sut.isMatching(mockClassfile); |
136 | 1 | } |
137 | |
|
138 | |
public void testIsMatching_class_badexcludes() { |
139 | 1 | checking(new Expectations() {{ |
140 | 1 | one (mockClassfile).getClassName(); |
141 | 1 | }}); |
142 | |
|
143 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some")); |
144 | |
try { |
145 | 1 | sut.isMatching(mockClassfile); |
146 | 0 | fail("did not throw expection for bad includes regular expression"); |
147 | 1 | } catch (MalformedCachePatternException ex) { |
148 | |
|
149 | 0 | } |
150 | 1 | } |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public void testIsMatching_field_matchingincludes() { |
157 | 1 | checking(new Expectations() {{ |
158 | 1 | one (mockField).getFullSignature(); |
159 | 1 | will(returnValue(SOME_FIELD_SIGNATURE)); |
160 | 1 | one (mockStrategy).isMatching(mockField); |
161 | 1 | }}); |
162 | |
|
163 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
164 | 1 | sut.isMatching(mockField); |
165 | 1 | } |
166 | |
|
167 | |
public void testIsMatching_field_notmatchingincludes() { |
168 | 1 | checking(new Expectations() {{ |
169 | 1 | one (mockField).getFullSignature(); |
170 | 1 | will(returnValue(ANOTHER_FIELD_SIGNATURE)); |
171 | 1 | }}); |
172 | |
|
173 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
174 | 1 | assertFalse(sut.isMatching(mockField)); |
175 | 1 | } |
176 | |
|
177 | |
public void testIsMatching_field_noincludes() { |
178 | 1 | checking(new Expectations() {{ |
179 | 1 | one (mockField).getFullSignature(); |
180 | 1 | }}); |
181 | |
|
182 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList()); |
183 | 1 | assertFalse(sut.isMatching(mockField)); |
184 | 1 | } |
185 | |
|
186 | |
public void testIsMatching_field_badincludes() { |
187 | 1 | checking(new Expectations() {{ |
188 | 1 | one (mockField).getFullSignature(); |
189 | 1 | }}); |
190 | |
|
191 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList()); |
192 | |
try { |
193 | 1 | sut.isMatching(mockField); |
194 | 0 | fail("did not throw expection for bad excludes regular expression"); |
195 | 1 | } catch (MalformedCachePatternException ex) { |
196 | |
|
197 | 0 | } |
198 | 1 | } |
199 | |
|
200 | |
public void testIsMatching_field_matchingexcludes() { |
201 | 1 | checking(new Expectations() {{ |
202 | 1 | one (mockField).getFullSignature(); |
203 | 1 | will(returnValue(SOME_FIELD_SIGNATURE)); |
204 | 1 | }}); |
205 | |
|
206 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
207 | 1 | assertFalse(sut.isMatching(mockField)); |
208 | 1 | } |
209 | |
|
210 | |
public void testIsMatching_field_notmatchingexcludes() { |
211 | 1 | checking(new Expectations() {{ |
212 | 1 | one (mockField).getFullSignature(); |
213 | 1 | will(returnValue(ANOTHER_FIELD_SIGNATURE)); |
214 | 1 | one (mockStrategy).isMatching(mockField); |
215 | 1 | }}); |
216 | |
|
217 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
218 | 1 | sut.isMatching(mockField); |
219 | 1 | } |
220 | |
|
221 | |
public void testIsMatching_field_badexcludes() { |
222 | 1 | checking(new Expectations() {{ |
223 | 1 | one (mockField).getFullSignature(); |
224 | 1 | }}); |
225 | |
|
226 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some")); |
227 | |
try { |
228 | 1 | sut.isMatching(mockField); |
229 | 0 | fail("did not throw expection for bad includes regular expression"); |
230 | 1 | } catch (MalformedCachePatternException ex) { |
231 | |
|
232 | 0 | } |
233 | 1 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
public void testIsMatching_method_matchingincludes() { |
240 | 1 | checking(new Expectations() {{ |
241 | 1 | one (mockMethod).getFullSignature(); |
242 | 1 | will(returnValue(SOME_METHOD_SIGNATURE)); |
243 | 1 | one (mockStrategy).isMatching(mockMethod); |
244 | 1 | }}); |
245 | |
|
246 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
247 | 1 | sut.isMatching(mockMethod); |
248 | 1 | } |
249 | |
|
250 | |
public void testIsMatching_method_notmatchingincludes() { |
251 | 1 | checking(new Expectations() {{ |
252 | 1 | one (mockMethod).getFullSignature(); |
253 | 1 | will(returnValue(ANOTHER_METHOD_SIGNATURE)); |
254 | 1 | }}); |
255 | |
|
256 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
257 | 1 | assertFalse(sut.isMatching(mockMethod)); |
258 | 1 | } |
259 | |
|
260 | |
public void testIsMatching_method_noincludes() { |
261 | 1 | checking(new Expectations() {{ |
262 | 1 | one (mockMethod).getFullSignature(); |
263 | 1 | }}); |
264 | |
|
265 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList()); |
266 | 1 | assertFalse(sut.isMatching(mockMethod)); |
267 | 1 | } |
268 | |
|
269 | |
public void testIsMatching_method_badincludes() { |
270 | 1 | checking(new Expectations() {{ |
271 | 1 | one (mockMethod).getFullSignature(); |
272 | 1 | }}); |
273 | |
|
274 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList()); |
275 | |
try { |
276 | 1 | sut.isMatching(mockMethod); |
277 | 0 | fail("did not throw expection for bad excludes regular expression"); |
278 | 1 | } catch (MalformedCachePatternException ex) { |
279 | |
|
280 | 0 | } |
281 | 1 | } |
282 | |
|
283 | |
public void testIsMatching_method_matchingexcludes() { |
284 | 1 | checking(new Expectations() {{ |
285 | 1 | one (mockMethod).getFullSignature(); |
286 | 1 | will(returnValue(SOME_METHOD_SIGNATURE)); |
287 | 1 | }}); |
288 | |
|
289 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
290 | 1 | assertFalse(sut.isMatching(mockMethod)); |
291 | 1 | } |
292 | |
|
293 | |
public void testIsMatching_method_notmatchingexcludes() { |
294 | 1 | checking(new Expectations() {{ |
295 | 1 | one (mockMethod).getFullSignature(); |
296 | 1 | will(returnValue(ANOTHER_METHOD_SIGNATURE)); |
297 | 1 | one (mockStrategy).isMatching(mockMethod); |
298 | 1 | }}); |
299 | |
|
300 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
301 | 1 | sut.isMatching(mockMethod); |
302 | 1 | } |
303 | |
|
304 | |
public void testIsMatching_method_badexcludes() { |
305 | 1 | checking(new Expectations() {{ |
306 | 1 | one (mockMethod).getFullSignature(); |
307 | 1 | }}); |
308 | |
|
309 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some")); |
310 | |
try { |
311 | 1 | sut.isMatching(mockMethod); |
312 | 0 | fail("did not throw expection for bad includes regular expression"); |
313 | 1 | } catch (MalformedCachePatternException ex) { |
314 | |
|
315 | 0 | } |
316 | 1 | } |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
public void testIsMatching_local_matchingincludes() { |
323 | 1 | checking(new Expectations() {{ |
324 | 1 | one (mockLocalVariable).getName(); |
325 | 1 | will(returnValue(SOME_LOCAL_VARIABLE_NAME)); |
326 | 1 | one (mockStrategy).isMatching(mockLocalVariable); |
327 | 1 | }}); |
328 | |
|
329 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
330 | 1 | sut.isMatching(mockLocalVariable); |
331 | 1 | } |
332 | |
|
333 | |
public void testIsMatching_local_notmatchingincludes() { |
334 | 1 | checking(new Expectations() {{ |
335 | 1 | one (mockLocalVariable).getName(); |
336 | 1 | will(returnValue(ANOTHER_LOCAL_VARIABLE_NAME)); |
337 | 1 | }}); |
338 | |
|
339 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some/"), Collections.<String>emptyList()); |
340 | 1 | assertFalse(sut.isMatching(mockLocalVariable)); |
341 | 1 | } |
342 | |
|
343 | |
public void testIsMatching_local_noincludes() { |
344 | 1 | checking(new Expectations() {{ |
345 | 1 | one (mockLocalVariable).getName(); |
346 | 1 | }}); |
347 | |
|
348 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.<String>emptyList(), Collections.<String>emptyList()); |
349 | 1 | assertFalse(sut.isMatching(mockLocalVariable)); |
350 | 1 | } |
351 | |
|
352 | |
public void testIsMatching_local_badincludes() { |
353 | 1 | checking(new Expectations() {{ |
354 | 1 | one (mockLocalVariable).getName(); |
355 | 1 | }}); |
356 | |
|
357 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("/some"), Collections.<String>emptyList()); |
358 | |
try { |
359 | 1 | sut.isMatching(mockLocalVariable); |
360 | 0 | fail("did not throw expection for bad excludes regular expression"); |
361 | 1 | } catch (MalformedCachePatternException ex) { |
362 | |
|
363 | 0 | } |
364 | 1 | } |
365 | |
|
366 | |
public void testIsMatching_local_matchingexcludes() { |
367 | 1 | checking(new Expectations() {{ |
368 | 1 | one (mockLocalVariable).getName(); |
369 | 1 | will(returnValue(SOME_LOCAL_VARIABLE_NAME)); |
370 | 1 | }}); |
371 | |
|
372 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
373 | 1 | assertFalse(sut.isMatching(mockLocalVariable)); |
374 | 1 | } |
375 | |
|
376 | |
public void testIsMatching_local_notmatchingexcludes() { |
377 | 1 | checking(new Expectations() {{ |
378 | 1 | one (mockLocalVariable).getName(); |
379 | 1 | will(returnValue(ANOTHER_LOCAL_VARIABLE_NAME)); |
380 | 1 | one (mockStrategy).isMatching(mockLocalVariable); |
381 | 1 | }}); |
382 | |
|
383 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some/")); |
384 | 1 | sut.isMatching(mockLocalVariable); |
385 | 1 | } |
386 | |
|
387 | |
public void testIsMatching_local_badexcludes() { |
388 | 1 | checking(new Expectations() {{ |
389 | 1 | one (mockLocalVariable).getName(); |
390 | 1 | }}); |
391 | |
|
392 | 1 | FilteringSymbolGathererStrategy sut = new FilteringSymbolGathererStrategy(mockStrategy, Collections.singletonList("//"), Collections.singletonList("/some")); |
393 | |
try { |
394 | 1 | sut.isMatching(mockLocalVariable); |
395 | 0 | fail("did not throw expection for bad includes regular expression"); |
396 | 1 | } catch (MalformedCachePatternException ex) { |
397 | |
|
398 | 0 | } |
399 | 1 | } |
400 | |
} |