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.metrics; |
34 |
| |
35 |
| import java.util.*; |
36 |
| |
37 |
| import org.jmock.*; |
38 |
| import org.jmock.integration.junit3.*; |
39 |
| import org.jmock.lib.legacy.*; |
40 |
| |
41 |
| import com.jeantessier.classreader.*; |
42 |
| |
43 |
| public class TestMetricsGathererAccumulators extends MockObjectTestCase { |
44 |
| private static final String PACKAGE_NAME = "test.package"; |
45 |
| private static final String CLASS_NAME = PACKAGE_NAME + ".TestClass"; |
46 |
| private static final String FIELD_NAME = CLASS_NAME + ".testField"; |
47 |
| private static final String METHOD_SIGNATURE = CLASS_NAME + ".testMethod()"; |
48 |
| private static final String INNER_CLASS_NAME = CLASS_NAME + "$InnerClass"; |
49 |
| private static final String ANONYMOUS_INNER_CLASS_NAME = CLASS_NAME + "$1"; |
50 |
| |
51 |
48
| protected void setUp() throws Exception {
|
52 |
48
| super.setUp();
|
53 |
| |
54 |
48
| setImposteriser(ClassImposteriser.INSTANCE);
|
55 |
| } |
56 |
| |
57 |
1
| public void testVisitClassfile_public() throws Exception {
|
58 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
59 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
60 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
61 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
62 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
63 |
| |
64 |
1
| checking(new Expectations() {{
|
65 |
1
| one (mockFactory).createProjectMetrics();
|
66 |
1
| will(returnValue(mockProjectMetrics));
|
67 |
1
| one (mockClassfile).getClassName();
|
68 |
1
| will(returnValue(CLASS_NAME));
|
69 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
70 |
1
| will(returnValue(mockClassMetrics));
|
71 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
72 |
1
| one (mockClassMetrics).getParent();
|
73 |
1
| will(returnValue(mockGroupMetrics));
|
74 |
1
| one (mockGroupMetrics).getParent();
|
75 |
1
| will(returnValue(mockProjectMetrics));
|
76 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
77 |
1
| will(returnValue(PACKAGE_NAME));
|
78 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
79 |
| |
80 |
1
| allowing (mockClassfile).isPublic();
|
81 |
1
| will(returnValue(true));
|
82 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PUBLIC_CLASSES, CLASS_NAME);
|
83 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PUBLIC_CLASSES, CLASS_NAME);
|
84 |
1
| ignoring (mockClassfile).isPackage();
|
85 |
1
| ignoring (mockClassfile).isFinal();
|
86 |
1
| ignoring (mockClassfile).isSuper();
|
87 |
1
| ignoring (mockClassfile).isInterface();
|
88 |
1
| ignoring (mockClassfile).isAbstract();
|
89 |
| |
90 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
91 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
92 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
93 |
1
| ignoring (mockClassfile).getAllFields();
|
94 |
1
| ignoring (mockClassfile).getAllMethods();
|
95 |
| |
96 |
1
| ignoring (mockClassfile).isAnnotation();
|
97 |
1
| ignoring (mockClassfile).isEnum();
|
98 |
1
| ignoring (mockClassfile).isSynthetic();
|
99 |
1
| ignoring (mockClassfile).isDeprecated();
|
100 |
1
| ignoring (mockClassfile).isGeneric();
|
101 |
| |
102 |
1
| ignoring (mockClassfile).getAttributes();
|
103 |
| |
104 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
105 |
| }}); |
106 |
| |
107 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
108 |
1
| sut.visitClassfile(mockClassfile);
|
109 |
| } |
110 |
| |
111 |
1
| public void testVisitClassfile_package() throws Exception {
|
112 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
113 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
114 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
115 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
116 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
117 |
| |
118 |
1
| checking(new Expectations() {{
|
119 |
1
| one (mockFactory).createProjectMetrics();
|
120 |
1
| will(returnValue(mockProjectMetrics));
|
121 |
1
| one (mockClassfile).getClassName();
|
122 |
1
| will(returnValue(CLASS_NAME));
|
123 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
124 |
1
| will(returnValue(mockClassMetrics));
|
125 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
126 |
1
| one (mockClassMetrics).getParent();
|
127 |
1
| will(returnValue(mockGroupMetrics));
|
128 |
1
| one (mockGroupMetrics).getParent();
|
129 |
1
| will(returnValue(mockProjectMetrics));
|
130 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
131 |
1
| will(returnValue(PACKAGE_NAME));
|
132 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
133 |
| |
134 |
1
| ignoring (mockClassfile).isPublic();
|
135 |
1
| allowing (mockClassfile).isPackage();
|
136 |
1
| will(returnValue(true));
|
137 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
138 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
139 |
1
| ignoring (mockClassfile).isFinal();
|
140 |
1
| ignoring (mockClassfile).isSuper();
|
141 |
1
| ignoring (mockClassfile).isInterface();
|
142 |
1
| ignoring (mockClassfile).isAbstract();
|
143 |
| |
144 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
145 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
146 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
147 |
1
| ignoring (mockClassfile).getAllFields();
|
148 |
1
| ignoring (mockClassfile).getAllMethods();
|
149 |
| |
150 |
1
| ignoring (mockClassfile).isAnnotation();
|
151 |
1
| ignoring (mockClassfile).isEnum();
|
152 |
1
| ignoring (mockClassfile).isSynthetic();
|
153 |
1
| ignoring (mockClassfile).isDeprecated();
|
154 |
1
| ignoring (mockClassfile).isGeneric();
|
155 |
| |
156 |
1
| ignoring (mockClassfile).getAttributes();
|
157 |
| |
158 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
159 |
| }}); |
160 |
| |
161 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
162 |
1
| sut.visitClassfile(mockClassfile);
|
163 |
| } |
164 |
| |
165 |
1
| public void testVisitClassfile_final() throws Exception {
|
166 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
167 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
168 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
169 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
170 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
171 |
| |
172 |
1
| checking(new Expectations() {{
|
173 |
1
| one (mockFactory).createProjectMetrics();
|
174 |
1
| will(returnValue(mockProjectMetrics));
|
175 |
1
| one (mockClassfile).getClassName();
|
176 |
1
| will(returnValue(CLASS_NAME));
|
177 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
178 |
1
| will(returnValue(mockClassMetrics));
|
179 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
180 |
1
| one (mockClassMetrics).getParent();
|
181 |
1
| will(returnValue(mockGroupMetrics));
|
182 |
1
| one (mockGroupMetrics).getParent();
|
183 |
1
| will(returnValue(mockProjectMetrics));
|
184 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
185 |
1
| will(returnValue(PACKAGE_NAME));
|
186 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
187 |
| |
188 |
1
| ignoring (mockClassfile).isPublic();
|
189 |
1
| ignoring (mockClassfile).isPackage();
|
190 |
1
| ignoring (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
191 |
1
| ignoring (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
192 |
1
| allowing (mockClassfile).isFinal();
|
193 |
1
| will(returnValue(true));
|
194 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.FINAL_CLASSES, CLASS_NAME);
|
195 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.FINAL_CLASSES, CLASS_NAME);
|
196 |
1
| ignoring (mockClassfile).isSuper();
|
197 |
1
| ignoring (mockClassfile).isInterface();
|
198 |
1
| ignoring (mockClassfile).isAbstract();
|
199 |
| |
200 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
201 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
202 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
203 |
1
| ignoring (mockClassfile).getAllFields();
|
204 |
1
| ignoring (mockClassfile).getAllMethods();
|
205 |
| |
206 |
1
| ignoring (mockClassfile).isAnnotation();
|
207 |
1
| ignoring (mockClassfile).isEnum();
|
208 |
1
| ignoring (mockClassfile).isSynthetic();
|
209 |
1
| ignoring (mockClassfile).isDeprecated();
|
210 |
1
| ignoring (mockClassfile).isGeneric();
|
211 |
| |
212 |
1
| ignoring (mockClassfile).getAttributes();
|
213 |
| |
214 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
215 |
| }}); |
216 |
| |
217 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
218 |
1
| sut.visitClassfile(mockClassfile);
|
219 |
| } |
220 |
| |
221 |
1
| public void testVisitClassfile_super() throws Exception {
|
222 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
223 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
224 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
225 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
226 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
227 |
| |
228 |
1
| checking(new Expectations() {{
|
229 |
1
| one (mockFactory).createProjectMetrics();
|
230 |
1
| will(returnValue(mockProjectMetrics));
|
231 |
1
| one (mockClassfile).getClassName();
|
232 |
1
| will(returnValue(CLASS_NAME));
|
233 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
234 |
1
| will(returnValue(mockClassMetrics));
|
235 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
236 |
1
| one (mockClassMetrics).getParent();
|
237 |
1
| will(returnValue(mockGroupMetrics));
|
238 |
1
| one (mockGroupMetrics).getParent();
|
239 |
1
| will(returnValue(mockProjectMetrics));
|
240 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
241 |
1
| will(returnValue(PACKAGE_NAME));
|
242 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
243 |
| |
244 |
1
| ignoring (mockClassfile).isPublic();
|
245 |
1
| ignoring (mockClassfile).isPackage();
|
246 |
1
| ignoring (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
247 |
1
| ignoring (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
248 |
1
| ignoring (mockClassfile).isFinal();
|
249 |
1
| allowing (mockClassfile).isSuper();
|
250 |
1
| will(returnValue(true));
|
251 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.SUPER_CLASSES, CLASS_NAME);
|
252 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.SUPER_CLASSES, CLASS_NAME);
|
253 |
1
| ignoring (mockClassfile).isInterface();
|
254 |
1
| ignoring (mockClassfile).isAbstract();
|
255 |
| |
256 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
257 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
258 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
259 |
1
| ignoring (mockClassfile).getAllFields();
|
260 |
1
| ignoring (mockClassfile).getAllMethods();
|
261 |
| |
262 |
1
| ignoring (mockClassfile).isAnnotation();
|
263 |
1
| ignoring (mockClassfile).isEnum();
|
264 |
1
| ignoring (mockClassfile).isSynthetic();
|
265 |
1
| ignoring (mockClassfile).isDeprecated();
|
266 |
1
| ignoring (mockClassfile).isGeneric();
|
267 |
| |
268 |
1
| ignoring (mockClassfile).getAttributes();
|
269 |
| |
270 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
271 |
| }}); |
272 |
| |
273 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
274 |
1
| sut.visitClassfile(mockClassfile);
|
275 |
| } |
276 |
| |
277 |
1
| public void testVisitClassfile_interface() throws Exception {
|
278 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
279 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
280 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
281 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
282 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
283 |
| |
284 |
1
| checking(new Expectations() {{
|
285 |
1
| one (mockFactory).createProjectMetrics();
|
286 |
1
| will(returnValue(mockProjectMetrics));
|
287 |
1
| one (mockClassfile).getClassName();
|
288 |
1
| will(returnValue(CLASS_NAME));
|
289 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
290 |
1
| will(returnValue(mockClassMetrics));
|
291 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
292 |
1
| one (mockClassMetrics).getParent();
|
293 |
1
| will(returnValue(mockGroupMetrics));
|
294 |
1
| one (mockGroupMetrics).getParent();
|
295 |
1
| will(returnValue(mockProjectMetrics));
|
296 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
297 |
1
| will(returnValue(PACKAGE_NAME));
|
298 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
299 |
| |
300 |
1
| ignoring (mockClassfile).isPublic();
|
301 |
1
| ignoring (mockClassfile).isPackage();
|
302 |
1
| ignoring (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
303 |
1
| ignoring (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
304 |
1
| ignoring (mockClassfile).isFinal();
|
305 |
1
| ignoring (mockClassfile).isSuper();
|
306 |
1
| allowing (mockClassfile).isInterface();
|
307 |
1
| will(returnValue(true));
|
308 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INTERFACES, CLASS_NAME);
|
309 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INTERFACES, CLASS_NAME);
|
310 |
1
| ignoring (mockClassfile).isAbstract();
|
311 |
| |
312 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
313 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
314 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
315 |
1
| ignoring (mockClassfile).getAllFields();
|
316 |
1
| ignoring (mockClassfile).getAllMethods();
|
317 |
| |
318 |
1
| ignoring (mockClassfile).isAnnotation();
|
319 |
1
| ignoring (mockClassfile).isEnum();
|
320 |
1
| ignoring (mockClassfile).isSynthetic();
|
321 |
1
| ignoring (mockClassfile).isDeprecated();
|
322 |
1
| ignoring (mockClassfile).isGeneric();
|
323 |
| |
324 |
1
| ignoring (mockClassfile).getAttributes();
|
325 |
| |
326 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
327 |
| }}); |
328 |
| |
329 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
330 |
1
| sut.visitClassfile(mockClassfile);
|
331 |
| } |
332 |
| |
333 |
1
| public void testVisitClassfile_abstract() throws Exception {
|
334 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
335 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
336 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
337 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
338 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
339 |
| |
340 |
1
| checking(new Expectations() {{
|
341 |
1
| one (mockFactory).createProjectMetrics();
|
342 |
1
| will(returnValue(mockProjectMetrics));
|
343 |
1
| one (mockClassfile).getClassName();
|
344 |
1
| will(returnValue(CLASS_NAME));
|
345 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
346 |
1
| will(returnValue(mockClassMetrics));
|
347 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
348 |
1
| one (mockClassMetrics).getParent();
|
349 |
1
| will(returnValue(mockGroupMetrics));
|
350 |
1
| one (mockGroupMetrics).getParent();
|
351 |
1
| will(returnValue(mockProjectMetrics));
|
352 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
353 |
1
| will(returnValue(PACKAGE_NAME));
|
354 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
355 |
| |
356 |
1
| ignoring (mockClassfile).isPublic();
|
357 |
1
| ignoring (mockClassfile).isPackage();
|
358 |
1
| ignoring (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
359 |
1
| ignoring (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
360 |
1
| ignoring (mockClassfile).isFinal();
|
361 |
1
| ignoring (mockClassfile).isSuper();
|
362 |
1
| ignoring (mockClassfile).isInterface();
|
363 |
1
| allowing (mockClassfile).isAbstract();
|
364 |
1
| will(returnValue(true));
|
365 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.ABSTRACT_CLASSES, CLASS_NAME);
|
366 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.ABSTRACT_CLASSES, CLASS_NAME);
|
367 |
| |
368 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
369 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
370 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
371 |
1
| ignoring (mockClassfile).getAllFields();
|
372 |
1
| ignoring (mockClassfile).getAllMethods();
|
373 |
| |
374 |
1
| ignoring (mockClassfile).isAnnotation();
|
375 |
1
| ignoring (mockClassfile).isEnum();
|
376 |
1
| ignoring (mockClassfile).isSynthetic();
|
377 |
1
| ignoring (mockClassfile).isDeprecated();
|
378 |
1
| ignoring (mockClassfile).isGeneric();
|
379 |
| |
380 |
1
| ignoring (mockClassfile).getAttributes();
|
381 |
| |
382 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
383 |
| }}); |
384 |
| |
385 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
386 |
1
| sut.visitClassfile(mockClassfile);
|
387 |
| } |
388 |
| |
389 |
1
| public void testVisitClassfile_synthetic_withSyntheticAttribute() throws Exception {
|
390 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
391 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
392 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
393 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
394 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
395 |
1
| final Synthetic_attribute mockSynthetic_attribute = mock(Synthetic_attribute.class);
|
396 |
| |
397 |
1
| checking(new Expectations() {{
|
398 |
1
| one (mockFactory).createProjectMetrics();
|
399 |
1
| will(returnValue(mockProjectMetrics));
|
400 |
1
| one (mockClassfile).getClassName();
|
401 |
1
| will(returnValue(CLASS_NAME));
|
402 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
403 |
1
| will(returnValue(mockClassMetrics));
|
404 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
405 |
1
| one (mockClassMetrics).getParent();
|
406 |
1
| will(returnValue(mockGroupMetrics));
|
407 |
1
| one (mockGroupMetrics).getParent();
|
408 |
1
| will(returnValue(mockProjectMetrics));
|
409 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
410 |
1
| will(returnValue(PACKAGE_NAME));
|
411 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
412 |
| |
413 |
1
| ignoring (mockClassfile).isPublic();
|
414 |
1
| ignoring (mockClassfile).isPackage();
|
415 |
1
| ignoring (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
416 |
1
| ignoring (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
417 |
1
| ignoring (mockClassfile).isFinal();
|
418 |
1
| ignoring (mockClassfile).isSuper();
|
419 |
1
| ignoring (mockClassfile).isInterface();
|
420 |
1
| ignoring (mockClassfile).isAbstract();
|
421 |
| |
422 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
423 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
424 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
425 |
1
| ignoring (mockClassfile).getAllFields();
|
426 |
1
| ignoring (mockClassfile).getAllMethods();
|
427 |
| |
428 |
1
| ignoring (mockClassfile).isAnnotation();
|
429 |
1
| ignoring (mockClassfile).isEnum();
|
430 |
1
| allowing (mockClassfile).isSynthetic();
|
431 |
1
| will(returnValue(true));
|
432 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.SYNTHETIC_CLASSES, CLASS_NAME);
|
433 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.SYNTHETIC_CLASSES, CLASS_NAME);
|
434 |
1
| ignoring (mockClassfile).isDeprecated();
|
435 |
1
| ignoring (mockClassfile).isGeneric();
|
436 |
| }}); |
437 |
| |
438 |
1
| final MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
439 |
| |
440 |
1
| checking(new Expectations() {{
|
441 |
1
| allowing (mockClassfile).getAttributes();
|
442 |
1
| will(returnValue(Collections.singleton(mockSynthetic_attribute)));
|
443 |
1
| allowing (mockSynthetic_attribute).accept(sut);
|
444 |
| }}); |
445 |
| |
446 |
1
| sut.visitClassfile(mockClassfile);
|
447 |
| } |
448 |
| |
449 |
1
| public void testVisitClassfile_synthetic_withoutSyntheticAttribute() throws Exception {
|
450 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
451 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
452 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
453 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
454 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "class");
|
455 |
| |
456 |
1
| checking(new Expectations() {{
|
457 |
1
| one (mockFactory).createProjectMetrics();
|
458 |
1
| will(returnValue(mockProjectMetrics));
|
459 |
1
| one (mockClassfile).getClassName();
|
460 |
1
| will(returnValue(CLASS_NAME));
|
461 |
1
| one (mockFactory).createClassMetrics(CLASS_NAME);
|
462 |
1
| will(returnValue(mockClassMetrics));
|
463 |
1
| one (mockFactory).includeClassMetrics(mockClassMetrics);
|
464 |
1
| one (mockClassMetrics).getParent();
|
465 |
1
| will(returnValue(mockGroupMetrics));
|
466 |
1
| one (mockGroupMetrics).getParent();
|
467 |
1
| will(returnValue(mockProjectMetrics));
|
468 |
1
| atLeast(1).of (mockGroupMetrics).getName();
|
469 |
1
| will(returnValue(PACKAGE_NAME));
|
470 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGES, PACKAGE_NAME);
|
471 |
| |
472 |
1
| ignoring (mockClassfile).isPublic();
|
473 |
1
| ignoring (mockClassfile).isPackage();
|
474 |
1
| ignoring (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
475 |
1
| ignoring (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_CLASSES, CLASS_NAME);
|
476 |
1
| ignoring (mockClassfile).isFinal();
|
477 |
1
| ignoring (mockClassfile).isSuper();
|
478 |
1
| ignoring (mockClassfile).isInterface();
|
479 |
1
| ignoring (mockClassfile).isAbstract();
|
480 |
| |
481 |
1
| ignoring (mockClassfile).getSuperclassIndex();
|
482 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
483 |
1
| ignoring (mockClassfile).getAllInterfaces();
|
484 |
1
| ignoring (mockClassfile).getAllFields();
|
485 |
1
| ignoring (mockClassfile).getAllMethods();
|
486 |
| |
487 |
1
| ignoring (mockClassfile).isAnnotation();
|
488 |
1
| ignoring (mockClassfile).isEnum();
|
489 |
1
| allowing (mockClassfile).isSynthetic();
|
490 |
1
| will(returnValue(true));
|
491 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.SYNTHETIC_CLASSES, CLASS_NAME);
|
492 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.SYNTHETIC_CLASSES, CLASS_NAME);
|
493 |
1
| ignoring (mockClassfile).isDeprecated();
|
494 |
1
| ignoring (mockClassfile).isGeneric();
|
495 |
| |
496 |
1
| ignoring (mockClassfile).getAttributes();
|
497 |
| }}); |
498 |
| |
499 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
500 |
1
| sut.visitClassfile(mockClassfile);
|
501 |
| } |
502 |
| |
503 |
1
| public void testVisitField_info_public() throws Exception {
|
504 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
505 |
1
| final Field_info mockField = mock(Field_info.class);
|
506 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
507 |
| |
508 |
1
| checking(new Expectations() {{
|
509 |
1
| allowing (mockFactory).createProjectMetrics();
|
510 |
1
| one (mockField).getFullName();
|
511 |
1
| will(returnValue(FIELD_NAME));
|
512 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
513 |
1
| allowing (mockField).getFullSignature();
|
514 |
1
| allowing (mockMetrics).getName();
|
515 |
1
| allowing (mockField).getAccessFlag();
|
516 |
1
| allowing (mockField).isPublic();
|
517 |
1
| will(returnValue(true));
|
518 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PUBLIC_ATTRIBUTES, FIELD_NAME);
|
519 |
1
| ignoring (mockField).isPrivate();
|
520 |
1
| ignoring (mockField).isProtected();
|
521 |
1
| ignoring (mockField).isPackage();
|
522 |
1
| ignoring (mockField).isStatic();
|
523 |
1
| ignoring (mockField).isFinal();
|
524 |
1
| ignoring (mockField).isVolatile();
|
525 |
1
| ignoring (mockField).isTransient();
|
526 |
1
| ignoring (mockField).isSynthetic();
|
527 |
1
| ignoring (mockField).getAttributes();
|
528 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
529 |
1
| ignoring (mockField).getDescriptor();
|
530 |
| }}); |
531 |
| |
532 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
533 |
1
| sut.setCurrentClass(mockMetrics);
|
534 |
1
| sut.visitField_info(mockField);
|
535 |
| } |
536 |
| |
537 |
1
| public void testVisitField_info_private() throws Exception {
|
538 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
539 |
1
| final Field_info mockField = mock(Field_info.class);
|
540 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
541 |
| |
542 |
1
| checking(new Expectations() {{
|
543 |
1
| allowing (mockFactory).createProjectMetrics();
|
544 |
1
| one (mockField).getFullName();
|
545 |
1
| will(returnValue(FIELD_NAME));
|
546 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
547 |
1
| allowing (mockField).getFullSignature();
|
548 |
1
| allowing (mockMetrics).getName();
|
549 |
1
| allowing (mockField).getAccessFlag();
|
550 |
1
| ignoring (mockField).isPublic();
|
551 |
1
| allowing (mockField).isPrivate();
|
552 |
1
| will(returnValue(true));
|
553 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PRIVATE_ATTRIBUTES, FIELD_NAME);
|
554 |
1
| ignoring (mockField).isProtected();
|
555 |
1
| ignoring (mockField).isPackage();
|
556 |
1
| ignoring (mockField).isStatic();
|
557 |
1
| ignoring (mockField).isFinal();
|
558 |
1
| ignoring (mockField).isVolatile();
|
559 |
1
| ignoring (mockField).isTransient();
|
560 |
1
| ignoring (mockField).isSynthetic();
|
561 |
1
| ignoring (mockField).getAttributes();
|
562 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
563 |
1
| ignoring (mockField).getDescriptor();
|
564 |
| }}); |
565 |
| |
566 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
567 |
1
| sut.setCurrentClass(mockMetrics);
|
568 |
1
| sut.visitField_info(mockField);
|
569 |
| } |
570 |
| |
571 |
1
| public void testVisitField_info_protected() throws Exception {
|
572 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
573 |
1
| final Field_info mockField = mock(Field_info.class);
|
574 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
575 |
| |
576 |
1
| checking(new Expectations() {{
|
577 |
1
| allowing (mockFactory).createProjectMetrics();
|
578 |
1
| one (mockField).getFullName();
|
579 |
1
| will(returnValue(FIELD_NAME));
|
580 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
581 |
1
| allowing (mockField).getFullSignature();
|
582 |
1
| allowing (mockMetrics).getName();
|
583 |
1
| allowing (mockField).getAccessFlag();
|
584 |
1
| ignoring (mockField).isPublic();
|
585 |
1
| ignoring (mockField).isPrivate();
|
586 |
1
| allowing (mockField).isProtected();
|
587 |
1
| will(returnValue(true));
|
588 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PROTECTED_ATTRIBUTES, FIELD_NAME);
|
589 |
1
| ignoring (mockField).isPackage();
|
590 |
1
| ignoring (mockField).isStatic();
|
591 |
1
| ignoring (mockField).isFinal();
|
592 |
1
| ignoring (mockField).isVolatile();
|
593 |
1
| ignoring (mockField).isTransient();
|
594 |
1
| ignoring (mockField).isSynthetic();
|
595 |
1
| ignoring (mockField).getAttributes();
|
596 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
597 |
1
| ignoring (mockField).getDescriptor();
|
598 |
| }}); |
599 |
| |
600 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
601 |
1
| sut.setCurrentClass(mockMetrics);
|
602 |
1
| sut.visitField_info(mockField);
|
603 |
| } |
604 |
| |
605 |
1
| public void testVisitField_info_package() throws Exception {
|
606 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
607 |
1
| final Field_info mockField = mock(Field_info.class);
|
608 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
609 |
| |
610 |
1
| checking(new Expectations() {{
|
611 |
1
| allowing (mockFactory).createProjectMetrics();
|
612 |
1
| one (mockField).getFullName();
|
613 |
1
| will(returnValue(FIELD_NAME));
|
614 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
615 |
1
| allowing (mockField).getFullSignature();
|
616 |
1
| allowing (mockMetrics).getName();
|
617 |
1
| allowing (mockField).getAccessFlag();
|
618 |
1
| ignoring (mockField).isPublic();
|
619 |
1
| ignoring (mockField).isPrivate();
|
620 |
1
| ignoring (mockField).isProtected();
|
621 |
1
| allowing (mockField).isPackage();
|
622 |
1
| will(returnValue(true));
|
623 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_ATTRIBUTES, FIELD_NAME);
|
624 |
1
| ignoring (mockField).isStatic();
|
625 |
1
| ignoring (mockField).isFinal();
|
626 |
1
| ignoring (mockField).isVolatile();
|
627 |
1
| ignoring (mockField).isTransient();
|
628 |
1
| ignoring (mockField).isSynthetic();
|
629 |
1
| ignoring (mockField).getAttributes();
|
630 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
631 |
1
| ignoring (mockField).getDescriptor();
|
632 |
| }}); |
633 |
| |
634 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
635 |
1
| sut.setCurrentClass(mockMetrics);
|
636 |
1
| sut.visitField_info(mockField);
|
637 |
| } |
638 |
| |
639 |
1
| public void testVisitField_info_static() throws Exception {
|
640 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
641 |
1
| final Field_info mockField = mock(Field_info.class);
|
642 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
643 |
| |
644 |
1
| checking(new Expectations() {{
|
645 |
1
| allowing (mockFactory).createProjectMetrics();
|
646 |
1
| one (mockField).getFullName();
|
647 |
1
| will(returnValue(FIELD_NAME));
|
648 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
649 |
1
| allowing (mockField).getFullSignature();
|
650 |
1
| allowing (mockMetrics).getName();
|
651 |
1
| allowing (mockField).getAccessFlag();
|
652 |
1
| ignoring (mockField).isPublic();
|
653 |
1
| ignoring (mockField).isPrivate();
|
654 |
1
| ignoring (mockField).isProtected();
|
655 |
1
| ignoring (mockField).isPackage();
|
656 |
1
| ignoring (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_ATTRIBUTES, FIELD_NAME);
|
657 |
1
| allowing (mockField).isStatic();
|
658 |
1
| will(returnValue(true));
|
659 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.STATIC_ATTRIBUTES, FIELD_NAME);
|
660 |
1
| ignoring (mockField).isFinal();
|
661 |
1
| ignoring (mockField).isVolatile();
|
662 |
1
| ignoring (mockField).isTransient();
|
663 |
1
| ignoring (mockField).isSynthetic();
|
664 |
1
| ignoring (mockField).getAttributes();
|
665 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
666 |
1
| ignoring (mockField).getDescriptor();
|
667 |
| }}); |
668 |
| |
669 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
670 |
1
| sut.setCurrentClass(mockMetrics);
|
671 |
1
| sut.visitField_info(mockField);
|
672 |
| } |
673 |
| |
674 |
1
| public void testVisitField_info_final() throws Exception {
|
675 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
676 |
1
| final Field_info mockField = mock(Field_info.class);
|
677 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
678 |
| |
679 |
1
| checking(new Expectations() {{
|
680 |
1
| allowing (mockFactory).createProjectMetrics();
|
681 |
1
| one (mockField).getFullName();
|
682 |
1
| will(returnValue(FIELD_NAME));
|
683 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
684 |
1
| allowing (mockField).getFullSignature();
|
685 |
1
| allowing (mockMetrics).getName();
|
686 |
1
| allowing (mockField).getAccessFlag();
|
687 |
1
| ignoring (mockField).isPublic();
|
688 |
1
| ignoring (mockField).isPrivate();
|
689 |
1
| ignoring (mockField).isProtected();
|
690 |
1
| ignoring (mockField).isPackage();
|
691 |
1
| ignoring (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_ATTRIBUTES, FIELD_NAME);
|
692 |
1
| ignoring (mockField).isStatic();
|
693 |
1
| allowing (mockField).isFinal();
|
694 |
1
| will(returnValue(true));
|
695 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.FINAL_ATTRIBUTES, FIELD_NAME);
|
696 |
1
| ignoring (mockField).isVolatile();
|
697 |
1
| ignoring (mockField).isTransient();
|
698 |
1
| ignoring (mockField).isSynthetic();
|
699 |
1
| ignoring (mockField).getAttributes();
|
700 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
701 |
1
| ignoring (mockField).getDescriptor();
|
702 |
| }}); |
703 |
| |
704 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
705 |
1
| sut.setCurrentClass(mockMetrics);
|
706 |
1
| sut.visitField_info(mockField);
|
707 |
| } |
708 |
| |
709 |
1
| public void testVisitField_info_volatile() throws Exception {
|
710 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
711 |
1
| final Field_info mockField = mock(Field_info.class);
|
712 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
713 |
| |
714 |
1
| checking(new Expectations() {{
|
715 |
1
| allowing (mockFactory).createProjectMetrics();
|
716 |
1
| one (mockField).getFullName();
|
717 |
1
| will(returnValue(FIELD_NAME));
|
718 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
719 |
1
| allowing (mockField).getFullSignature();
|
720 |
1
| allowing (mockMetrics).getName();
|
721 |
1
| allowing (mockField).getAccessFlag();
|
722 |
1
| ignoring (mockField).isPublic();
|
723 |
1
| ignoring (mockField).isPrivate();
|
724 |
1
| ignoring (mockField).isProtected();
|
725 |
1
| ignoring (mockField).isPackage();
|
726 |
1
| ignoring (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_ATTRIBUTES, FIELD_NAME);
|
727 |
1
| ignoring (mockField).isStatic();
|
728 |
1
| ignoring (mockField).isFinal();
|
729 |
1
| allowing (mockField).isVolatile();
|
730 |
1
| will(returnValue(true));
|
731 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.VOLATILE_ATTRIBUTES, FIELD_NAME);
|
732 |
1
| ignoring (mockField).isTransient();
|
733 |
1
| ignoring (mockField).isSynthetic();
|
734 |
1
| ignoring (mockField).getAttributes();
|
735 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
736 |
1
| ignoring (mockField).getDescriptor();
|
737 |
| }}); |
738 |
| |
739 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
740 |
1
| sut.setCurrentClass(mockMetrics);
|
741 |
1
| sut.visitField_info(mockField);
|
742 |
| } |
743 |
| |
744 |
1
| public void testVisitField_info_transient() throws Exception {
|
745 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
746 |
1
| final Field_info mockField = mock(Field_info.class);
|
747 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
748 |
| |
749 |
1
| checking(new Expectations() {{
|
750 |
1
| allowing (mockFactory).createProjectMetrics();
|
751 |
1
| one (mockField).getFullName();
|
752 |
1
| will(returnValue(FIELD_NAME));
|
753 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
754 |
1
| allowing (mockField).getFullSignature();
|
755 |
1
| allowing (mockMetrics).getName();
|
756 |
1
| allowing (mockField).getAccessFlag();
|
757 |
1
| ignoring (mockField).isPublic();
|
758 |
1
| ignoring (mockField).isPrivate();
|
759 |
1
| ignoring (mockField).isProtected();
|
760 |
1
| ignoring (mockField).isPackage();
|
761 |
1
| ignoring (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_ATTRIBUTES, FIELD_NAME);
|
762 |
1
| ignoring (mockField).isStatic();
|
763 |
1
| ignoring (mockField).isFinal();
|
764 |
1
| ignoring (mockField).isVolatile();
|
765 |
1
| allowing (mockField).isTransient();
|
766 |
1
| will(returnValue(true));
|
767 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.TRANSIENT_ATTRIBUTES, FIELD_NAME);
|
768 |
1
| ignoring (mockField).isSynthetic();
|
769 |
1
| ignoring (mockField).getAttributes();
|
770 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.CLASS_SLOC, 1);
|
771 |
1
| ignoring (mockField).getDescriptor();
|
772 |
| }}); |
773 |
| |
774 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
775 |
1
| sut.setCurrentClass(mockMetrics);
|
776 |
1
| sut.visitField_info(mockField);
|
777 |
| } |
778 |
| |
779 |
1
| public void testVisitField_info_synthetic() throws Exception {
|
780 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
781 |
1
| final Field_info mockField = mock(Field_info.class);
|
782 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
783 |
1
| final Attribute_info mockSyntheticAttribute = mock(Synthetic_attribute.class);
|
784 |
1
| final Collection<? extends Attribute_info> attributes = Collections.singleton(mockSyntheticAttribute);
|
785 |
| |
786 |
1
| checking(new Expectations() {{
|
787 |
1
| allowing (mockFactory).createProjectMetrics();
|
788 |
| }}); |
789 |
| |
790 |
1
| final MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
791 |
| |
792 |
1
| checking(new Expectations() {{
|
793 |
1
| allowing (mockFactory).createProjectMetrics();
|
794 |
1
| one (mockField).getFullName();
|
795 |
1
| will(returnValue(FIELD_NAME));
|
796 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ATTRIBUTES, FIELD_NAME);
|
797 |
1
| allowing (mockField).getFullSignature();
|
798 |
1
| allowing (mockMetrics).getName();
|
799 |
1
| allowing (mockField).getAccessFlag();
|
800 |
1
| ignoring (mockField).isPublic();
|
801 |
1
| ignoring (mockField).isPrivate();
|
802 |
1
| ignoring (mockField).isProtected();
|
803 |
1
| ignoring (mockField).isPackage();
|
804 |
1
| ignoring (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_ATTRIBUTES, FIELD_NAME);
|
805 |
1
| ignoring (mockField).isStatic();
|
806 |
1
| ignoring (mockField).isFinal();
|
807 |
1
| ignoring (mockField).isVolatile();
|
808 |
1
| ignoring (mockField).isTransient();
|
809 |
1
| allowing (mockField).isSynthetic();
|
810 |
1
| will(returnValue(true));
|
811 |
1
| never (mockMetrics).addToMeasurement(with(equal(BasicMeasurements.SYNTHETIC_ATTRIBUTES)), with(any(String.class)));
|
812 |
1
| one (mockField).getAttributes();
|
813 |
1
| will(returnValue(attributes));
|
814 |
1
| one (mockSyntheticAttribute).accept(sut);
|
815 |
1
| never (mockMetrics).addToMeasurement(with(equal(BasicMeasurements.CLASS_SLOC)), with(any(Number.class)));
|
816 |
1
| ignoring (mockField).getDescriptor();
|
817 |
| }}); |
818 |
| |
819 |
1
| sut.setCurrentClass(mockMetrics);
|
820 |
1
| sut.visitField_info(mockField);
|
821 |
| } |
822 |
| |
823 |
1
| public void testVisitMethod_info_public() throws Exception {
|
824 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
825 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
826 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
827 |
| |
828 |
1
| checking(new Expectations() {{
|
829 |
1
| allowing (mockFactory).createProjectMetrics();
|
830 |
1
| allowing (mockMethod).getClassfile();
|
831 |
1
| allowing (mockMethod).getFullSignature();
|
832 |
1
| will(returnValue(METHOD_SIGNATURE));
|
833 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
834 |
1
| will(returnValue(mockMetrics));
|
835 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
836 |
1
| allowing (mockMetrics).getName();
|
837 |
1
| allowing (mockMethod).getAccessFlag();
|
838 |
1
| allowing (mockMethod).isPublic();
|
839 |
1
| will(returnValue(true));
|
840 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PUBLIC_METHODS, METHOD_SIGNATURE);
|
841 |
1
| ignoring (mockMethod).isPrivate();
|
842 |
1
| ignoring (mockMethod).isProtected();
|
843 |
1
| ignoring (mockMethod).isPackage();
|
844 |
1
| ignoring (mockMethod).isStatic();
|
845 |
1
| ignoring (mockMethod).isFinal();
|
846 |
1
| ignoring (mockMethod).isSynchronized();
|
847 |
1
| ignoring (mockMethod).isNative();
|
848 |
1
| ignoring (mockMethod).isAbstract();
|
849 |
1
| ignoring (mockMethod).isSynthetic();
|
850 |
1
| allowing (mockMethod).getDescriptor();
|
851 |
1
| will(returnValue("()V"));
|
852 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
853 |
1
| ignoring (mockMethod).getAttributes();
|
854 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
855 |
| }}); |
856 |
| |
857 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
858 |
1
| sut.setCurrentClass(mockMetrics);
|
859 |
1
| sut.visitMethod_info(mockMethod);
|
860 |
| } |
861 |
| |
862 |
1
| public void testVisitMethod_info_private() throws Exception {
|
863 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
864 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
865 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
866 |
| |
867 |
1
| checking(new Expectations() {{
|
868 |
1
| allowing (mockFactory).createProjectMetrics();
|
869 |
1
| allowing (mockMethod).getClassfile();
|
870 |
1
| allowing (mockMethod).getFullSignature();
|
871 |
1
| will(returnValue(METHOD_SIGNATURE));
|
872 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
873 |
1
| will(returnValue(mockMetrics));
|
874 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
875 |
1
| allowing (mockMetrics).getName();
|
876 |
1
| allowing (mockMethod).getAccessFlag();
|
877 |
1
| ignoring (mockMethod).isPublic();
|
878 |
1
| allowing (mockMethod).isPrivate();
|
879 |
1
| will(returnValue(true));
|
880 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PRIVATE_METHODS, METHOD_SIGNATURE);
|
881 |
1
| ignoring (mockMethod).isProtected();
|
882 |
1
| ignoring (mockMethod).isPackage();
|
883 |
1
| ignoring (mockMethod).isStatic();
|
884 |
1
| ignoring (mockMethod).isFinal();
|
885 |
1
| ignoring (mockMethod).isSynchronized();
|
886 |
1
| ignoring (mockMethod).isNative();
|
887 |
1
| ignoring (mockMethod).isAbstract();
|
888 |
1
| ignoring (mockMethod).isSynthetic();
|
889 |
1
| allowing (mockMethod).getDescriptor();
|
890 |
1
| will(returnValue("()V"));
|
891 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
892 |
1
| ignoring (mockMethod).getAttributes();
|
893 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
894 |
| }}); |
895 |
| |
896 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
897 |
1
| sut.setCurrentClass(mockMetrics);
|
898 |
1
| sut.visitMethod_info(mockMethod);
|
899 |
| } |
900 |
| |
901 |
1
| public void testVisitMethod_info_protected() throws Exception {
|
902 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
903 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
904 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
905 |
| |
906 |
1
| checking(new Expectations() {{
|
907 |
1
| allowing (mockFactory).createProjectMetrics();
|
908 |
1
| allowing (mockMethod).getClassfile();
|
909 |
1
| allowing (mockMethod).getFullSignature();
|
910 |
1
| will(returnValue(METHOD_SIGNATURE));
|
911 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
912 |
1
| will(returnValue(mockMetrics));
|
913 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
914 |
1
| allowing (mockMetrics).getName();
|
915 |
1
| allowing (mockMethod).getAccessFlag();
|
916 |
1
| ignoring (mockMethod).isPublic();
|
917 |
1
| ignoring (mockMethod).isPrivate();
|
918 |
1
| allowing (mockMethod).isProtected();
|
919 |
1
| will(returnValue(true));
|
920 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PROTECTED_METHODS, METHOD_SIGNATURE);
|
921 |
1
| ignoring (mockMethod).isPackage();
|
922 |
1
| ignoring (mockMethod).isStatic();
|
923 |
1
| ignoring (mockMethod).isFinal();
|
924 |
1
| ignoring (mockMethod).isSynchronized();
|
925 |
1
| ignoring (mockMethod).isNative();
|
926 |
1
| ignoring (mockMethod).isAbstract();
|
927 |
1
| ignoring (mockMethod).isSynthetic();
|
928 |
1
| allowing (mockMethod).getDescriptor();
|
929 |
1
| will(returnValue("()V"));
|
930 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
931 |
1
| ignoring (mockMethod).getAttributes();
|
932 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
933 |
| }}); |
934 |
| |
935 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
936 |
1
| sut.setCurrentClass(mockMetrics);
|
937 |
1
| sut.visitMethod_info(mockMethod);
|
938 |
| } |
939 |
| |
940 |
1
| public void testVisitMethod_info_package() throws Exception {
|
941 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
942 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
943 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
944 |
| |
945 |
1
| checking(new Expectations() {{
|
946 |
1
| allowing (mockFactory).createProjectMetrics();
|
947 |
1
| allowing (mockMethod).getClassfile();
|
948 |
1
| allowing (mockMethod).getFullSignature();
|
949 |
1
| will(returnValue(METHOD_SIGNATURE));
|
950 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
951 |
1
| will(returnValue(mockMetrics));
|
952 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
953 |
1
| allowing (mockMetrics).getName();
|
954 |
1
| allowing (mockMethod).getAccessFlag();
|
955 |
1
| ignoring (mockMethod).isPublic();
|
956 |
1
| ignoring (mockMethod).isPrivate();
|
957 |
1
| ignoring (mockMethod).isProtected();
|
958 |
1
| allowing (mockMethod).isPackage();
|
959 |
1
| will(returnValue(true));
|
960 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
961 |
1
| ignoring (mockMethod).isStatic();
|
962 |
1
| ignoring (mockMethod).isFinal();
|
963 |
1
| ignoring (mockMethod).isSynchronized();
|
964 |
1
| ignoring (mockMethod).isNative();
|
965 |
1
| ignoring (mockMethod).isAbstract();
|
966 |
1
| ignoring (mockMethod).isSynthetic();
|
967 |
1
| allowing (mockMethod).getDescriptor();
|
968 |
1
| will(returnValue("()V"));
|
969 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
970 |
1
| ignoring (mockMethod).getAttributes();
|
971 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
972 |
| }}); |
973 |
| |
974 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
975 |
1
| sut.setCurrentClass(mockMetrics);
|
976 |
1
| sut.visitMethod_info(mockMethod);
|
977 |
| } |
978 |
| |
979 |
1
| public void testVisitMethod_info_static() throws Exception {
|
980 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
981 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
982 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
983 |
| |
984 |
1
| checking(new Expectations() {{
|
985 |
1
| allowing (mockFactory).createProjectMetrics();
|
986 |
1
| allowing (mockMethod).getClassfile();
|
987 |
1
| allowing (mockMethod).getFullSignature();
|
988 |
1
| will(returnValue(METHOD_SIGNATURE));
|
989 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
990 |
1
| will(returnValue(mockMetrics));
|
991 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
992 |
1
| allowing (mockMetrics).getName();
|
993 |
1
| allowing (mockMethod).getAccessFlag();
|
994 |
1
| ignoring (mockMethod).isPublic();
|
995 |
1
| ignoring (mockMethod).isPrivate();
|
996 |
1
| ignoring (mockMethod).isProtected();
|
997 |
1
| ignoring (mockMethod).isPackage();
|
998 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
999 |
1
| allowing (mockMethod).isStatic();
|
1000 |
1
| will(returnValue(true));
|
1001 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.STATIC_METHODS, METHOD_SIGNATURE);
|
1002 |
1
| ignoring (mockMethod).isFinal();
|
1003 |
1
| ignoring (mockMethod).isSynchronized();
|
1004 |
1
| ignoring (mockMethod).isNative();
|
1005 |
1
| ignoring (mockMethod).isAbstract();
|
1006 |
1
| ignoring (mockMethod).isSynthetic();
|
1007 |
1
| allowing (mockMethod).getDescriptor();
|
1008 |
1
| will(returnValue("()V"));
|
1009 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
1010 |
1
| ignoring (mockMethod).getAttributes();
|
1011 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
1012 |
| }}); |
1013 |
| |
1014 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1015 |
1
| sut.setCurrentClass(mockMetrics);
|
1016 |
1
| sut.visitMethod_info(mockMethod);
|
1017 |
| } |
1018 |
| |
1019 |
1
| public void testVisitMethod_info_final() throws Exception {
|
1020 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1021 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1022 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1023 |
| |
1024 |
1
| checking(new Expectations() {{
|
1025 |
1
| allowing (mockFactory).createProjectMetrics();
|
1026 |
1
| allowing (mockMethod).getClassfile();
|
1027 |
1
| allowing (mockMethod).getFullSignature();
|
1028 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1029 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
1030 |
1
| will(returnValue(mockMetrics));
|
1031 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
1032 |
1
| allowing (mockMetrics).getName();
|
1033 |
1
| allowing (mockMethod).getAccessFlag();
|
1034 |
1
| ignoring (mockMethod).isPublic();
|
1035 |
1
| ignoring (mockMethod).isPrivate();
|
1036 |
1
| ignoring (mockMethod).isProtected();
|
1037 |
1
| ignoring (mockMethod).isPackage();
|
1038 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
1039 |
1
| ignoring (mockMethod).isStatic();
|
1040 |
1
| allowing (mockMethod).isFinal();
|
1041 |
1
| will(returnValue(true));
|
1042 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.FINAL_METHODS, METHOD_SIGNATURE);
|
1043 |
1
| ignoring (mockMethod).isSynchronized();
|
1044 |
1
| ignoring (mockMethod).isNative();
|
1045 |
1
| ignoring (mockMethod).isAbstract();
|
1046 |
1
| ignoring (mockMethod).isSynthetic();
|
1047 |
1
| allowing (mockMethod).getDescriptor();
|
1048 |
1
| will(returnValue("()V"));
|
1049 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
1050 |
1
| ignoring (mockMethod).getAttributes();
|
1051 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
1052 |
| }}); |
1053 |
| |
1054 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1055 |
1
| sut.setCurrentClass(mockMetrics);
|
1056 |
1
| sut.visitMethod_info(mockMethod);
|
1057 |
| } |
1058 |
| |
1059 |
1
| public void testVisitMethod_info_synchronized() throws Exception {
|
1060 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1061 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1062 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1063 |
| |
1064 |
1
| checking(new Expectations() {{
|
1065 |
1
| allowing (mockFactory).createProjectMetrics();
|
1066 |
1
| allowing (mockMethod).getClassfile();
|
1067 |
1
| allowing (mockMethod).getFullSignature();
|
1068 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1069 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
1070 |
1
| will(returnValue(mockMetrics));
|
1071 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
1072 |
1
| allowing (mockMetrics).getName();
|
1073 |
1
| allowing (mockMethod).getAccessFlag();
|
1074 |
1
| ignoring (mockMethod).isPublic();
|
1075 |
1
| ignoring (mockMethod).isPrivate();
|
1076 |
1
| ignoring (mockMethod).isProtected();
|
1077 |
1
| ignoring (mockMethod).isPackage();
|
1078 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
1079 |
1
| ignoring (mockMethod).isStatic();
|
1080 |
1
| ignoring (mockMethod).isFinal();
|
1081 |
1
| allowing (mockMethod).isSynchronized();
|
1082 |
1
| will(returnValue(true));
|
1083 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SYNCHRONIZED_METHODS, METHOD_SIGNATURE);
|
1084 |
1
| ignoring (mockMethod).isNative();
|
1085 |
1
| ignoring (mockMethod).isAbstract();
|
1086 |
1
| ignoring (mockMethod).isSynthetic();
|
1087 |
1
| allowing (mockMethod).getDescriptor();
|
1088 |
1
| will(returnValue("()V"));
|
1089 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
1090 |
1
| ignoring (mockMethod).getAttributes();
|
1091 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
1092 |
| }}); |
1093 |
| |
1094 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1095 |
1
| sut.setCurrentClass(mockMetrics);
|
1096 |
1
| sut.visitMethod_info(mockMethod);
|
1097 |
| } |
1098 |
| |
1099 |
1
| public void testVisitMethod_info_native() throws Exception {
|
1100 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1101 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1102 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1103 |
| |
1104 |
1
| checking(new Expectations() {{
|
1105 |
1
| allowing (mockFactory).createProjectMetrics();
|
1106 |
1
| allowing (mockMethod).getClassfile();
|
1107 |
1
| allowing (mockMethod).getFullSignature();
|
1108 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1109 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
1110 |
1
| will(returnValue(mockMetrics));
|
1111 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
1112 |
1
| allowing (mockMetrics).getName();
|
1113 |
1
| allowing (mockMethod).getAccessFlag();
|
1114 |
1
| ignoring (mockMethod).isPublic();
|
1115 |
1
| ignoring (mockMethod).isPrivate();
|
1116 |
1
| ignoring (mockMethod).isProtected();
|
1117 |
1
| ignoring (mockMethod).isPackage();
|
1118 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
1119 |
1
| ignoring (mockMethod).isStatic();
|
1120 |
1
| ignoring (mockMethod).isFinal();
|
1121 |
1
| ignoring (mockMethod).isSynchronized();
|
1122 |
1
| allowing (mockMethod).isNative();
|
1123 |
1
| will(returnValue(true));
|
1124 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.NATIVE_METHODS, METHOD_SIGNATURE);
|
1125 |
1
| ignoring (mockMethod).isAbstract();
|
1126 |
1
| ignoring (mockMethod).isSynthetic();
|
1127 |
1
| allowing (mockMethod).getDescriptor();
|
1128 |
1
| will(returnValue("()V"));
|
1129 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
1130 |
1
| ignoring (mockMethod).getAttributes();
|
1131 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
1132 |
| }}); |
1133 |
| |
1134 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1135 |
1
| sut.setCurrentClass(mockMetrics);
|
1136 |
1
| sut.visitMethod_info(mockMethod);
|
1137 |
| } |
1138 |
| |
1139 |
1
| public void testVisitMethod_info_abstract() throws Exception {
|
1140 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1141 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1142 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1143 |
| |
1144 |
1
| checking(new Expectations() {{
|
1145 |
1
| allowing (mockFactory).createProjectMetrics();
|
1146 |
1
| allowing (mockMethod).getClassfile();
|
1147 |
1
| allowing (mockMethod).getFullSignature();
|
1148 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1149 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
1150 |
1
| will(returnValue(mockMetrics));
|
1151 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
1152 |
1
| allowing (mockMetrics).getName();
|
1153 |
1
| allowing (mockMethod).getAccessFlag();
|
1154 |
1
| ignoring (mockMethod).isPublic();
|
1155 |
1
| ignoring (mockMethod).isPrivate();
|
1156 |
1
| ignoring (mockMethod).isProtected();
|
1157 |
1
| ignoring (mockMethod).isPackage();
|
1158 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
1159 |
1
| ignoring (mockMethod).isStatic();
|
1160 |
1
| ignoring (mockMethod).isFinal();
|
1161 |
1
| ignoring (mockMethod).isSynchronized();
|
1162 |
1
| ignoring (mockMethod).isNative();
|
1163 |
1
| allowing (mockMethod).isAbstract();
|
1164 |
1
| will(returnValue(true));
|
1165 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.ABSTRACT_METHODS, METHOD_SIGNATURE);
|
1166 |
1
| ignoring (mockMethod).isSynthetic();
|
1167 |
1
| allowing (mockMethod).getDescriptor();
|
1168 |
1
| will(returnValue("()V"));
|
1169 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
1170 |
1
| ignoring (mockMethod).getAttributes();
|
1171 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 1);
|
1172 |
| }}); |
1173 |
| |
1174 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1175 |
1
| sut.setCurrentClass(mockMetrics);
|
1176 |
1
| sut.visitMethod_info(mockMethod);
|
1177 |
| } |
1178 |
| |
1179 |
1
| public void testVisitMethod_info_synthetic() throws Exception {
|
1180 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1181 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1182 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1183 |
| |
1184 |
1
| checking(new Expectations() {{
|
1185 |
1
| allowing (mockFactory).createProjectMetrics();
|
1186 |
1
| allowing (mockMethod).getClassfile();
|
1187 |
1
| allowing (mockMethod).getFullSignature();
|
1188 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1189 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
1190 |
1
| will(returnValue(mockMetrics));
|
1191 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
1192 |
1
| allowing (mockMetrics).getName();
|
1193 |
1
| allowing (mockMethod).getAccessFlag();
|
1194 |
1
| ignoring (mockMethod).isPublic();
|
1195 |
1
| ignoring (mockMethod).isPrivate();
|
1196 |
1
| ignoring (mockMethod).isProtected();
|
1197 |
1
| ignoring (mockMethod).isPackage();
|
1198 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
1199 |
1
| ignoring (mockMethod).isStatic();
|
1200 |
1
| ignoring (mockMethod).isFinal();
|
1201 |
1
| ignoring (mockMethod).isSynchronized();
|
1202 |
1
| ignoring (mockMethod).isNative();
|
1203 |
1
| ignoring (mockMethod).isAbstract();
|
1204 |
1
| allowing (mockMethod).isSynthetic();
|
1205 |
1
| will(returnValue(true));
|
1206 |
1
| never (mockMetrics).addToMeasurement(with(equal(BasicMeasurements.SYNTHETIC_METHODS)), with(any(String.class)));
|
1207 |
1
| allowing (mockMethod).getDescriptor();
|
1208 |
1
| will(returnValue("()V"));
|
1209 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 0);
|
1210 |
1
| ignoring (mockMethod).getAttributes();
|
1211 |
1
| never (mockMetrics).addToMeasurement(with(equal(BasicMeasurements.SLOC)), with(any(Number.class)));
|
1212 |
| }}); |
1213 |
| |
1214 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1215 |
1
| sut.setCurrentClass(mockMetrics);
|
1216 |
1
| sut.visitMethod_info(mockMethod);
|
1217 |
| } |
1218 |
| |
1219 |
1
| public void testVisitMethod_info_parameters() throws Exception {
|
1220 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1221 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1222 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1223 |
| |
1224 |
1
| checking(new Expectations() {{
|
1225 |
1
| allowing (mockFactory).createProjectMetrics();
|
1226 |
1
| allowing (mockMethod).getClassfile();
|
1227 |
1
| allowing (mockMethod).getFullSignature();
|
1228 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1229 |
1
| one (mockFactory).createMethodMetrics(METHOD_SIGNATURE);
|
1230 |
1
| will(returnValue(mockMetrics));
|
1231 |
1
| one (mockFactory).includeMethodMetrics(mockMetrics);
|
1232 |
1
| allowing (mockMetrics).getName();
|
1233 |
1
| allowing (mockMethod).getAccessFlag();
|
1234 |
1
| ignoring (mockMethod).isPublic();
|
1235 |
1
| ignoring (mockMethod).isPrivate();
|
1236 |
1
| ignoring (mockMethod).isProtected();
|
1237 |
1
| ignoring (mockMethod).isPackage();
|
1238 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PACKAGE_METHODS, METHOD_SIGNATURE);
|
1239 |
1
| ignoring (mockMethod).isStatic();
|
1240 |
1
| ignoring (mockMethod).isFinal();
|
1241 |
1
| ignoring (mockMethod).isSynchronized();
|
1242 |
1
| ignoring (mockMethod).isNative();
|
1243 |
1
| ignoring (mockMethod).isAbstract();
|
1244 |
1
| ignoring (mockMethod).isSynthetic();
|
1245 |
1
| atLeast(1).of (mockMethod).getDescriptor();
|
1246 |
1
| will(returnValue("(iLjava/lang/Object;)V"));
|
1247 |
1
| ignoring (mockFactory).createClassMetrics("java.lang.Object");
|
1248 |
1
| ignoring (mockMetrics).getParent();
|
1249 |
1
| ignoring (mockMetrics).addToMeasurement(with(equal(BasicMeasurements.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES)), with(any(String.class)));
|
1250 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.PARAMETERS, 2);
|
1251 |
1
| ignoring (mockMethod).getAttributes();
|
1252 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SLOC, 0);
|
1253 |
| }}); |
1254 |
| |
1255 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1256 |
1
| sut.setCurrentClass(mockMetrics);
|
1257 |
1
| sut.visitMethod_info(mockMethod);
|
1258 |
| } |
1259 |
| |
1260 |
1
| public void testIsInnerClassOfCurrentClass_NamedInnerClass_OfCurrentClass() throws Exception {
|
1261 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1262 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1263 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1264 |
| |
1265 |
1
| checking(new Expectations() {{
|
1266 |
1
| allowing (mockFactory).createProjectMetrics();
|
1267 |
1
| one (mockMetrics).getName();
|
1268 |
1
| will(returnValue(CLASS_NAME));
|
1269 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1270 |
1
| will(returnValue(CLASS_NAME));
|
1271 |
| }}); |
1272 |
| |
1273 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1274 |
1
| sut.setCurrentClass(mockMetrics);
|
1275 |
1
| assertEquals("return value", true, sut.isInnerClassOfCurrentClass(mockInnerClass));
|
1276 |
| } |
1277 |
| |
1278 |
1
| public void testIsInnerClassOfCurrentClass_NamedInnerClass_OfOtherClass() throws Exception {
|
1279 |
1
| final String otherClassName = "otherpackage.OtherClass";
|
1280 |
| |
1281 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1282 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1283 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1284 |
| |
1285 |
1
| checking(new Expectations() {{
|
1286 |
1
| allowing (mockFactory).createProjectMetrics();
|
1287 |
1
| one (mockMetrics).getName();
|
1288 |
1
| will(returnValue(CLASS_NAME));
|
1289 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1290 |
1
| will(returnValue(otherClassName));
|
1291 |
| }}); |
1292 |
| |
1293 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1294 |
1
| sut.setCurrentClass(mockMetrics);
|
1295 |
1
| assertEquals("return value", false, sut.isInnerClassOfCurrentClass(mockInnerClass));
|
1296 |
| } |
1297 |
| |
1298 |
1
| public void testIsInnerClassOfCurrentClass_AnonymousInnerClass_OfCurrentClass() throws Exception {
|
1299 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1300 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1301 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1302 |
| |
1303 |
1
| checking(new Expectations() {{
|
1304 |
1
| allowing (mockFactory).createProjectMetrics();
|
1305 |
1
| one (mockMetrics).getName();
|
1306 |
1
| will(returnValue(CLASS_NAME));
|
1307 |
1
| one (mockInnerClass).getOuterClassInfo();
|
1308 |
1
| will(returnValue(""));
|
1309 |
1
| one (mockInnerClass).getInnerClassInfo();
|
1310 |
1
| will(returnValue(ANONYMOUS_INNER_CLASS_NAME));
|
1311 |
| }}); |
1312 |
| |
1313 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1314 |
1
| sut.setCurrentClass(mockMetrics);
|
1315 |
1
| assertEquals("return value", true, sut.isInnerClassOfCurrentClass(mockInnerClass));
|
1316 |
| } |
1317 |
| |
1318 |
1
| public void testIsInnerClassOfCurrentClass_AnonymousInnerClass_OfOtherClass() throws Exception {
|
1319 |
1
| final String otherInnerClassName = "otherpackage.OtherClass$1";
|
1320 |
| |
1321 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1322 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1323 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1324 |
| |
1325 |
1
| checking(new Expectations() {{
|
1326 |
1
| allowing (mockFactory).createProjectMetrics();
|
1327 |
1
| one (mockMetrics).getName();
|
1328 |
1
| will(returnValue(CLASS_NAME));
|
1329 |
1
| one (mockInnerClass).getOuterClassInfo();
|
1330 |
1
| will(returnValue(""));
|
1331 |
1
| one (mockInnerClass).getInnerClassInfo();
|
1332 |
1
| will(returnValue(otherInnerClassName));
|
1333 |
| }}); |
1334 |
| |
1335 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1336 |
1
| sut.setCurrentClass(mockMetrics);
|
1337 |
1
| assertEquals("return value", false, sut.isInnerClassOfCurrentClass(mockInnerClass));
|
1338 |
| } |
1339 |
| |
1340 |
1
| public void testVisitInnerClass_public() throws Exception {
|
1341 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1342 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1343 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1344 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1345 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1346 |
| |
1347 |
1
| checking(new Expectations() {{
|
1348 |
1
| allowing (mockFactory).createProjectMetrics();
|
1349 |
1
| will(returnValue(mockProjectMetrics));
|
1350 |
1
| one (mockClassMetrics).getName();
|
1351 |
1
| will(returnValue(CLASS_NAME));
|
1352 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1353 |
1
| will(returnValue(CLASS_NAME));
|
1354 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1355 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1356 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1357 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1358 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1359 |
1
| allowing (mockInnerClass).isPublic();
|
1360 |
1
| will(returnValue(true));
|
1361 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PUBLIC_INNER_CLASSES, INNER_CLASS_NAME);
|
1362 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PUBLIC_INNER_CLASSES, INNER_CLASS_NAME);
|
1363 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PUBLIC_INNER_CLASSES, INNER_CLASS_NAME);
|
1364 |
1
| ignoring (mockInnerClass).isPrivate();
|
1365 |
1
| ignoring (mockInnerClass).isProtected();
|
1366 |
1
| ignoring (mockInnerClass).isPackage();
|
1367 |
1
| ignoring (mockInnerClass).isStatic();
|
1368 |
1
| ignoring (mockInnerClass).isFinal();
|
1369 |
1
| ignoring (mockInnerClass).isAbstract();
|
1370 |
| }}); |
1371 |
| |
1372 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1373 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1374 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1375 |
1
| sut.visitInnerClass(mockInnerClass);
|
1376 |
| } |
1377 |
| |
1378 |
1
| public void testVisitInnerClass_private() throws Exception {
|
1379 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1380 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1381 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1382 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1383 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1384 |
| |
1385 |
1
| checking(new Expectations() {{
|
1386 |
1
| allowing (mockFactory).createProjectMetrics();
|
1387 |
1
| will(returnValue(mockProjectMetrics));
|
1388 |
1
| one (mockClassMetrics).getName();
|
1389 |
1
| will(returnValue(CLASS_NAME));
|
1390 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1391 |
1
| will(returnValue(CLASS_NAME));
|
1392 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1393 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1394 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1395 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1396 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1397 |
1
| ignoring (mockInnerClass).isPublic();
|
1398 |
1
| allowing (mockInnerClass).isPrivate();
|
1399 |
1
| will(returnValue(true));
|
1400 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PRIVATE_INNER_CLASSES, INNER_CLASS_NAME);
|
1401 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PRIVATE_INNER_CLASSES, INNER_CLASS_NAME);
|
1402 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PRIVATE_INNER_CLASSES, INNER_CLASS_NAME);
|
1403 |
1
| ignoring (mockInnerClass).isProtected();
|
1404 |
1
| ignoring (mockInnerClass).isPackage();
|
1405 |
1
| ignoring (mockInnerClass).isStatic();
|
1406 |
1
| ignoring (mockInnerClass).isFinal();
|
1407 |
1
| ignoring (mockInnerClass).isAbstract();
|
1408 |
| }}); |
1409 |
| |
1410 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1411 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1412 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1413 |
1
| sut.visitInnerClass(mockInnerClass);
|
1414 |
| } |
1415 |
| |
1416 |
1
| public void testVisitInnerClass_protected() throws Exception {
|
1417 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1418 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1419 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1420 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1421 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1422 |
| |
1423 |
1
| checking(new Expectations() {{
|
1424 |
1
| allowing (mockFactory).createProjectMetrics();
|
1425 |
1
| will(returnValue(mockProjectMetrics));
|
1426 |
1
| one (mockClassMetrics).getName();
|
1427 |
1
| will(returnValue(CLASS_NAME));
|
1428 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1429 |
1
| will(returnValue(CLASS_NAME));
|
1430 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1431 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1432 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1433 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1434 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1435 |
1
| ignoring (mockInnerClass).isPublic();
|
1436 |
1
| ignoring (mockInnerClass).isPrivate();
|
1437 |
1
| allowing (mockInnerClass).isProtected();
|
1438 |
1
| will(returnValue(true));
|
1439 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PROTECTED_INNER_CLASSES, INNER_CLASS_NAME);
|
1440 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PROTECTED_INNER_CLASSES, INNER_CLASS_NAME);
|
1441 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PROTECTED_INNER_CLASSES, INNER_CLASS_NAME);
|
1442 |
1
| ignoring (mockInnerClass).isPackage();
|
1443 |
1
| ignoring (mockInnerClass).isStatic();
|
1444 |
1
| ignoring (mockInnerClass).isFinal();
|
1445 |
1
| ignoring (mockInnerClass).isAbstract();
|
1446 |
| }}); |
1447 |
| |
1448 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1449 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1450 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1451 |
1
| sut.visitInnerClass(mockInnerClass);
|
1452 |
| } |
1453 |
| |
1454 |
1
| public void testVisitInnerClass_package() throws Exception {
|
1455 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1456 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1457 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1458 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1459 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1460 |
| |
1461 |
1
| checking(new Expectations() {{
|
1462 |
1
| allowing (mockFactory).createProjectMetrics();
|
1463 |
1
| will(returnValue(mockProjectMetrics));
|
1464 |
1
| one (mockClassMetrics).getName();
|
1465 |
1
| will(returnValue(CLASS_NAME));
|
1466 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1467 |
1
| will(returnValue(CLASS_NAME));
|
1468 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1469 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1470 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1471 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1472 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1473 |
1
| ignoring (mockInnerClass).isPublic();
|
1474 |
1
| ignoring (mockInnerClass).isPrivate();
|
1475 |
1
| ignoring (mockInnerClass).isProtected();
|
1476 |
1
| allowing (mockInnerClass).isPackage();
|
1477 |
1
| will(returnValue(true));
|
1478 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1479 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1480 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1481 |
1
| ignoring (mockInnerClass).isStatic();
|
1482 |
1
| ignoring (mockInnerClass).isFinal();
|
1483 |
1
| ignoring (mockInnerClass).isAbstract();
|
1484 |
| }}); |
1485 |
| |
1486 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1487 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1488 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1489 |
1
| sut.visitInnerClass(mockInnerClass);
|
1490 |
| } |
1491 |
| |
1492 |
1
| public void testVisitInnerClass_static() throws Exception {
|
1493 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1494 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1495 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1496 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1497 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1498 |
| |
1499 |
1
| checking(new Expectations() {{
|
1500 |
1
| allowing (mockFactory).createProjectMetrics();
|
1501 |
1
| will(returnValue(mockProjectMetrics));
|
1502 |
1
| one (mockClassMetrics).getName();
|
1503 |
1
| will(returnValue(CLASS_NAME));
|
1504 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1505 |
1
| will(returnValue(CLASS_NAME));
|
1506 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1507 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1508 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1509 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1510 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1511 |
1
| ignoring (mockInnerClass).isPublic();
|
1512 |
1
| ignoring (mockInnerClass).isPrivate();
|
1513 |
1
| ignoring (mockInnerClass).isProtected();
|
1514 |
1
| ignoring (mockInnerClass).isPackage();
|
1515 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1516 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1517 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1518 |
1
| allowing (mockInnerClass).isStatic();
|
1519 |
1
| will(returnValue(true));
|
1520 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.STATIC_INNER_CLASSES, INNER_CLASS_NAME);
|
1521 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.STATIC_INNER_CLASSES, INNER_CLASS_NAME);
|
1522 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.STATIC_INNER_CLASSES, INNER_CLASS_NAME);
|
1523 |
1
| ignoring (mockInnerClass).isFinal();
|
1524 |
1
| ignoring (mockInnerClass).isAbstract();
|
1525 |
| }}); |
1526 |
| |
1527 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1528 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1529 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1530 |
1
| sut.visitInnerClass(mockInnerClass);
|
1531 |
| } |
1532 |
| |
1533 |
1
| public void testVisitInnerClass_final() throws Exception {
|
1534 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1535 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1536 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1537 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1538 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1539 |
| |
1540 |
1
| checking(new Expectations() {{
|
1541 |
1
| allowing (mockFactory).createProjectMetrics();
|
1542 |
1
| will(returnValue(mockProjectMetrics));
|
1543 |
1
| one (mockClassMetrics).getName();
|
1544 |
1
| will(returnValue(CLASS_NAME));
|
1545 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1546 |
1
| will(returnValue(CLASS_NAME));
|
1547 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1548 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1549 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1550 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1551 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1552 |
1
| ignoring (mockInnerClass).isPublic();
|
1553 |
1
| ignoring (mockInnerClass).isPrivate();
|
1554 |
1
| ignoring (mockInnerClass).isProtected();
|
1555 |
1
| ignoring (mockInnerClass).isPackage();
|
1556 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1557 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1558 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1559 |
1
| ignoring (mockInnerClass).isStatic();
|
1560 |
1
| allowing (mockInnerClass).isFinal();
|
1561 |
1
| will(returnValue(true));
|
1562 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.FINAL_INNER_CLASSES, INNER_CLASS_NAME);
|
1563 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.FINAL_INNER_CLASSES, INNER_CLASS_NAME);
|
1564 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.FINAL_INNER_CLASSES, INNER_CLASS_NAME);
|
1565 |
1
| ignoring (mockInnerClass).isAbstract();
|
1566 |
| }}); |
1567 |
| |
1568 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1569 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1570 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1571 |
1
| sut.visitInnerClass(mockInnerClass);
|
1572 |
| } |
1573 |
| |
1574 |
1
| public void testVisitInnerClass_abstract() throws Exception {
|
1575 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1576 |
1
| final InnerClass mockInnerClass = mock(InnerClass.class);
|
1577 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "currentProject");
|
1578 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "currentGroup");
|
1579 |
1
| final Metrics mockClassMetrics = mock(Metrics.class, "currentClass");
|
1580 |
| |
1581 |
1
| checking(new Expectations() {{
|
1582 |
1
| allowing (mockFactory).createProjectMetrics();
|
1583 |
1
| will(returnValue(mockProjectMetrics));
|
1584 |
1
| one (mockClassMetrics).getName();
|
1585 |
1
| will(returnValue(CLASS_NAME));
|
1586 |
1
| exactly(2).of (mockInnerClass).getOuterClassInfo();
|
1587 |
1
| will(returnValue(CLASS_NAME));
|
1588 |
1
| allowing (mockInnerClass).getInnerClassInfo();
|
1589 |
1
| will(returnValue(INNER_CLASS_NAME));
|
1590 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1591 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1592 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.INNER_CLASSES, INNER_CLASS_NAME);
|
1593 |
1
| ignoring (mockInnerClass).isPublic();
|
1594 |
1
| ignoring (mockInnerClass).isPrivate();
|
1595 |
1
| ignoring (mockInnerClass).isProtected();
|
1596 |
1
| ignoring (mockInnerClass).isPackage();
|
1597 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1598 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1599 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.PACKAGE_INNER_CLASSES, INNER_CLASS_NAME);
|
1600 |
1
| ignoring (mockInnerClass).isStatic();
|
1601 |
1
| ignoring (mockInnerClass).isFinal();
|
1602 |
1
| allowing (mockInnerClass).isAbstract();
|
1603 |
1
| will(returnValue(true));
|
1604 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.ABSTRACT_INNER_CLASSES, INNER_CLASS_NAME);
|
1605 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.ABSTRACT_INNER_CLASSES, INNER_CLASS_NAME);
|
1606 |
1
| one (mockClassMetrics).addToMeasurement(BasicMeasurements.ABSTRACT_INNER_CLASSES, INNER_CLASS_NAME);
|
1607 |
| }}); |
1608 |
| |
1609 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1610 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1611 |
1
| sut.setCurrentClass(mockClassMetrics);
|
1612 |
1
| sut.visitInnerClass(mockInnerClass);
|
1613 |
| } |
1614 |
| |
1615 |
1
| public void testVisitSynthetic_attribute_class() throws Exception {
|
1616 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1617 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
1618 |
1
| final Synthetic_attribute mockSyntheticAttribute = mock(Synthetic_attribute.class);
|
1619 |
| |
1620 |
1
| checking(new Expectations() {{
|
1621 |
1
| allowing (mockFactory).createProjectMetrics();
|
1622 |
1
| one (mockSyntheticAttribute).getOwner();
|
1623 |
1
| will(returnValue(mockClassfile));
|
1624 |
| }}); |
1625 |
| |
1626 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1627 |
1
| sut.visitSynthetic_attribute(mockSyntheticAttribute);
|
1628 |
| } |
1629 |
| |
1630 |
1
| public void testVisitSynthetic_attribute_field() throws Exception {
|
1631 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1632 |
1
| final Field_info mockField = mock(Field_info.class);
|
1633 |
1
| final Synthetic_attribute mockSyntheticAttribute = mock(Synthetic_attribute.class);
|
1634 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1635 |
| |
1636 |
1
| checking(new Expectations() {{
|
1637 |
1
| allowing (mockFactory).createProjectMetrics();
|
1638 |
1
| one (mockSyntheticAttribute).getOwner();
|
1639 |
1
| will(returnValue(mockField));
|
1640 |
1
| one (mockField).getFullName();
|
1641 |
1
| will(returnValue(FIELD_NAME));
|
1642 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SYNTHETIC_ATTRIBUTES, FIELD_NAME);
|
1643 |
| }}); |
1644 |
| |
1645 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1646 |
1
| sut.setCurrentClass(mockMetrics);
|
1647 |
1
| sut.visitSynthetic_attribute(mockSyntheticAttribute);
|
1648 |
| } |
1649 |
| |
1650 |
1
| public void testVisitSynthetic_attribute_method() throws Exception {
|
1651 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1652 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1653 |
1
| final Synthetic_attribute mockSyntheticAttribute = mock(Synthetic_attribute.class);
|
1654 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1655 |
| |
1656 |
1
| checking(new Expectations() {{
|
1657 |
1
| allowing (mockFactory).createProjectMetrics();
|
1658 |
1
| one (mockSyntheticAttribute).getOwner();
|
1659 |
1
| will(returnValue(mockMethod));
|
1660 |
1
| one (mockMethod).getFullSignature();
|
1661 |
1
| will(returnValue(METHOD_SIGNATURE));
|
1662 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.SYNTHETIC_METHODS, METHOD_SIGNATURE);
|
1663 |
| }}); |
1664 |
| |
1665 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1666 |
1
| sut.setCurrentClass(mockMetrics);
|
1667 |
1
| sut.visitSynthetic_attribute(mockSyntheticAttribute);
|
1668 |
| } |
1669 |
| |
1670 |
1
| public void testVisitSynthetic_attribute_other() throws Exception {
|
1671 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1672 |
1
| final Synthetic_attribute mockSyntheticAttribute = mock(Synthetic_attribute.class);
|
1673 |
1
| final Visitable mockOwner = mock(Visitable.class);
|
1674 |
| |
1675 |
1
| checking(new Expectations() {{
|
1676 |
1
| allowing (mockFactory).createProjectMetrics();
|
1677 |
1
| one (mockSyntheticAttribute).getOwner();
|
1678 |
1
| will(returnValue(mockOwner));
|
1679 |
| }}); |
1680 |
| |
1681 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1682 |
1
| sut.visitSynthetic_attribute(mockSyntheticAttribute);
|
1683 |
| } |
1684 |
| |
1685 |
1
| public void testVisitDeprecated_attribute_class() throws Exception {
|
1686 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1687 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
1688 |
1
| final Deprecated_attribute mockDeprecatedAttribute = mock(Deprecated_attribute.class);
|
1689 |
1
| final Metrics mockGroupMetrics = mock(Metrics.class, "group");
|
1690 |
1
| final Metrics mockProjectMetrics = mock(Metrics.class, "project");
|
1691 |
| |
1692 |
1
| checking(new Expectations() {{
|
1693 |
1
| allowing (mockFactory).createProjectMetrics();
|
1694 |
1
| one (mockDeprecatedAttribute).getOwner();
|
1695 |
1
| will(returnValue(mockClassfile));
|
1696 |
1
| one (mockClassfile).getClassName();
|
1697 |
1
| will(returnValue(CLASS_NAME));
|
1698 |
1
| one (mockProjectMetrics).addToMeasurement(BasicMeasurements.DEPRECATED_CLASSES, CLASS_NAME);
|
1699 |
1
| one (mockGroupMetrics).addToMeasurement(BasicMeasurements.DEPRECATED_CLASSES, CLASS_NAME);
|
1700 |
| }}); |
1701 |
| |
1702 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1703 |
1
| sut.setCurrentProject(mockProjectMetrics);
|
1704 |
1
| sut.setCurrentGroup(mockGroupMetrics);
|
1705 |
1
| sut.visitDeprecated_attribute(mockDeprecatedAttribute);
|
1706 |
| } |
1707 |
| |
1708 |
1
| public void testVisitDeprecated_attribute_field() throws Exception {
|
1709 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1710 |
1
| final Field_info mockField = mock(Field_info.class);
|
1711 |
1
| final Deprecated_attribute mockDeprecatedAttribute = mock(Deprecated_attribute.class);
|
1712 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1713 |
| |
1714 |
1
| checking(new Expectations() {{
|
1715 |
1
| allowing (mockFactory).createProjectMetrics();
|
1716 |
1
| one (mockDeprecatedAttribute).getOwner();
|
1717 |
1
| will(returnValue(mockField));
|
1718 |
1
| one (mockField).getFullName();
|
1719 |
1
| will(returnValue(FIELD_NAME));
|
1720 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.DEPRECATED_ATTRIBUTES, FIELD_NAME);
|
1721 |
| }}); |
1722 |
| |
1723 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1724 |
1
| sut.setCurrentClass(mockMetrics);
|
1725 |
1
| sut.visitDeprecated_attribute(mockDeprecatedAttribute);
|
1726 |
| } |
1727 |
| |
1728 |
1
| public void testVisitDeprecated_attribute_method() throws Exception {
|
1729 |
1
| final String methodSignature = METHOD_SIGNATURE;
|
1730 |
| |
1731 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1732 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
1733 |
1
| final Deprecated_attribute mockDeprecatedAttribute = mock(Deprecated_attribute.class);
|
1734 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1735 |
| |
1736 |
1
| checking(new Expectations() {{
|
1737 |
1
| allowing (mockFactory).createProjectMetrics();
|
1738 |
1
| one (mockDeprecatedAttribute).getOwner();
|
1739 |
1
| will(returnValue(mockMethod));
|
1740 |
1
| one (mockMethod).getFullSignature();
|
1741 |
1
| will(returnValue(methodSignature));
|
1742 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.DEPRECATED_METHODS, methodSignature);
|
1743 |
| }}); |
1744 |
| |
1745 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1746 |
1
| sut.setCurrentClass(mockMetrics);
|
1747 |
1
| sut.visitDeprecated_attribute(mockDeprecatedAttribute);
|
1748 |
| } |
1749 |
| |
1750 |
1
| public void testVisitDeprecated_attribute_other() throws Exception {
|
1751 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1752 |
1
| final Deprecated_attribute mockDeprecatedAttribute = mock(Deprecated_attribute.class);
|
1753 |
1
| final Visitable mockOwner = mock(Visitable.class);
|
1754 |
| |
1755 |
1
| checking(new Expectations() {{
|
1756 |
1
| allowing (mockFactory).createProjectMetrics();
|
1757 |
1
| one (mockDeprecatedAttribute).getOwner();
|
1758 |
1
| will(returnValue(mockOwner));
|
1759 |
| }}); |
1760 |
| |
1761 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1762 |
1
| sut.visitDeprecated_attribute(mockDeprecatedAttribute);
|
1763 |
| } |
1764 |
| |
1765 |
1
| public void testVisitLocalVariable() throws Exception {
|
1766 |
1
| final String localVariableName = "localVariableName";
|
1767 |
| |
1768 |
1
| final MetricsFactory mockFactory = mock(MetricsFactory.class);
|
1769 |
1
| final LocalVariable mockLocalVariable = mock(LocalVariable.class);
|
1770 |
1
| final Metrics mockMetrics = mock(Metrics.class);
|
1771 |
| |
1772 |
1
| checking(new Expectations() {{
|
1773 |
1
| allowing (mockFactory).createProjectMetrics();
|
1774 |
1
| one (mockLocalVariable).getName();
|
1775 |
1
| will(returnValue(localVariableName));
|
1776 |
1
| one (mockMetrics).addToMeasurement(BasicMeasurements.LOCAL_VARIABLES, localVariableName);
|
1777 |
1
| one (mockLocalVariable).getDescriptor();
|
1778 |
| }}); |
1779 |
| |
1780 |
1
| MetricsGatherer sut = new MetricsGatherer(mockFactory);
|
1781 |
1
| sut.setCurrentMethod(mockMetrics);
|
1782 |
1
| sut.visitLocalVariable(mockLocalVariable);
|
1783 |
| } |
1784 |
| } |