001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.metrics;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: import com.jeantessier.classreader.*;
041:
042: public class TestMetricsGatherer extends TestCase {
043: public static final String TEST_CLASS = "test";
044: public static final String TEST_FILENAME = "classes"
045: + File.separator + "test.class";
046:
047: private MetricsFactory factory;
048: private ClassfileLoader loader;
049:
050: protected void setUp() throws Exception {
051: factory = new MetricsFactory("test",
052: new MetricsConfigurationLoader(Boolean
053: .getBoolean("DEPENDENCYFINDER_TESTS_VALIDATE"))
054: .load("etc" + File.separator
055: + "MetricsConfig.xml"));
056:
057: loader = new AggregatingClassfileLoader();
058: loader.load(Collections.singleton(TEST_FILENAME));
059:
060: loader.getClassfile(TEST_CLASS).accept(
061: new MetricsGatherer("test", factory));
062: }
063:
064: public void testNbElements() {
065: assertEquals("factory.ProjectNames().size()", 1, factory
066: .getProjectNames().size());
067: assertTrue(factory.getProjectNames().toString()
068: + " does not contain project \"test\"", factory
069: .getProjectNames().contains("test"));
070:
071: assertTrue(factory.getGroupNames().toString()
072: + " does not contain package \"\"", factory
073: .getGroupNames().contains(""));
074: assertEquals(factory.getGroupNames().toString(), 1, factory
075: .getGroupNames().size());
076:
077: assertTrue(factory.getClassNames().toString()
078: + " does not contain class \"test\"", factory
079: .getClassNames().contains("test"));
080: assertEquals(factory.getClassNames().toString(), 1, factory
081: .getClassNames().size());
082:
083: assertTrue(
084: factory.getMethodNames().toString()
085: + " does not contain method \"test.main(java.lang.String[])\"",
086: factory.getMethodNames().contains(
087: "test.main(java.lang.String[])"));
088: assertTrue(factory.getMethodNames().toString()
089: + " does not contain method \"test.test()\"", factory
090: .getMethodNames().contains("test.test()"));
091: assertEquals(factory.getMethodNames().toString(), 2, factory
092: .getMethodNames().size());
093: }
094:
095: public void testNbAllElements() {
096: assertEquals("factory.AllProjectNames().size()", 1, factory
097: .getAllProjectNames().size());
098: assertTrue(factory.getAllProjectNames().toString()
099: + " does not contain project \"test\"", factory
100: .getAllProjectNames().contains("test"));
101:
102: assertTrue(factory.getAllGroupNames().toString()
103: + " does not contain package \"\"", factory
104: .getAllGroupNames().contains(""));
105: assertTrue(factory.getAllGroupNames().toString()
106: + " does not contain package \"java.lang\"", factory
107: .getAllGroupNames().contains("java.lang"));
108: assertTrue(factory.getAllGroupNames().toString()
109: + " does not contain package \"java.util\"", factory
110: .getAllGroupNames().contains("java.util"));
111: assertTrue(factory.getAllGroupNames().toString()
112: + " does not contain package \"java.io\"", factory
113: .getAllGroupNames().contains("java.util"));
114: assertEquals(factory.getAllGroupNames().toString(), 4, factory
115: .getAllGroupNames().size());
116:
117: assertTrue(factory.getAllClassNames().toString()
118: + " does not contain class \"java.io.PrintStream\"",
119: factory.getAllClassNames().contains(
120: "java.io.PrintStream"));
121: assertTrue(
122: factory.getAllClassNames().toString()
123: + " does not contain class \"java.lang.NullPointerException\"",
124: factory.getAllClassNames().contains(
125: "java.lang.NullPointerException"));
126: assertTrue(factory.getAllClassNames().toString()
127: + " does not contain class \"java.lang.Object\"",
128: factory.getAllClassNames().contains("java.lang.Object"));
129: assertTrue(factory.getAllClassNames().toString()
130: + " does not contain class \"java.lang.String\"",
131: factory.getAllClassNames().contains("java.lang.String"));
132: assertTrue(factory.getAllClassNames().toString()
133: + " does not contain class \"java.lang.System\"",
134: factory.getAllClassNames().contains("java.lang.System"));
135: assertTrue(factory.getAllClassNames().toString()
136: + " does not contain class \"java.util.Collections\"",
137: factory.getAllClassNames().contains(
138: "java.util.Collections"));
139: assertTrue(factory.getAllClassNames().toString()
140: + " does not contain class \"java.util.Collection\"",
141: factory.getAllClassNames().contains(
142: "java.util.Collection"));
143: assertTrue(factory.getAllClassNames().toString()
144: + " does not contain class \"java.util.Set\"", factory
145: .getAllClassNames().contains("java.util.Set"));
146: assertTrue(factory.getAllClassNames().toString()
147: + " does not contain class \"test\"", factory
148: .getAllClassNames().contains("test"));
149: assertEquals(factory.getAllClassNames().toString(), 9, factory
150: .getAllClassNames().size());
151:
152: assertTrue(
153: factory.getAllMethodNames().toString()
154: + " does not contain method \"java.io.PrintStream.println(java.lang.Object)\"",
155: factory
156: .getAllMethodNames()
157: .contains(
158: "java.io.PrintStream.println(java.lang.Object)"));
159: assertTrue(
160: factory.getAllMethodNames().toString()
161: + " does not contain method \"java.lang.Object.Object()\"",
162: factory.getAllMethodNames().contains(
163: "java.lang.Object.Object()"));
164: assertTrue(
165: factory.getAllMethodNames().toString()
166: + " does not contain method \"java.util.Collections.singleton(java.lang.Object)\"",
167: factory
168: .getAllMethodNames()
169: .contains(
170: "java.util.Collections.singleton(java.lang.Object)"));
171: assertTrue(
172: factory.getAllMethodNames().toString()
173: + " does not contain method \"test.main(java.lang.String[])\"",
174: factory.getAllMethodNames().contains(
175: "test.main(java.lang.String[])"));
176: assertTrue(factory.getAllMethodNames().toString()
177: + " does not contain method \"test.test()\"", factory
178: .getAllMethodNames().contains("test.test()"));
179: assertEquals(factory.getAllMethodNames().toString(), 5, factory
180: .getAllMethodNames().size());
181: }
182:
183: public void test_test_test() {
184: assertEquals(Metrics.SLOC, 1, factory.createMethodMetrics(
185: "test.test()").getMeasurement(Metrics.SLOC).intValue());
186: assertEquals(Metrics.PARAMETERS, 0, factory
187: .createMethodMetrics("test.test()").getMeasurement(
188: Metrics.PARAMETERS).intValue());
189: assertEquals(Metrics.LOCAL_VARIABLES, 1, factory
190: .createMethodMetrics("test.test()").getMeasurement(
191: Metrics.LOCAL_VARIABLES).intValue());
192:
193: //
194: // Dependencies
195: //
196:
197: Collection dependencies;
198:
199: dependencies = ((CollectionMeasurement) factory
200: .createMethodMetrics("test.test()")
201: .getMeasurement(
202: Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES))
203: .getValues();
204: assertEquals(Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES
205: + " " + dependencies, 0, dependencies.size());
206:
207: dependencies = ((CollectionMeasurement) factory
208: .createMethodMetrics("test.test()")
209: .getMeasurement(
210: Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES))
211: .getValues();
212: assertEquals(Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES
213: + " " + dependencies, 0, dependencies.size());
214:
215: dependencies = ((CollectionMeasurement) factory
216: .createMethodMetrics("test.test()")
217: .getMeasurement(
218: Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES))
219: .getValues();
220: assertEquals(Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES
221: + " " + dependencies, 0, dependencies.size());
222:
223: dependencies = ((CollectionMeasurement) factory
224: .createMethodMetrics("test.test()")
225: .getMeasurement(
226: Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES))
227: .getValues();
228: assertEquals(Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES
229: + " " + dependencies, 0, dependencies.size());
230:
231: dependencies = ((CollectionMeasurement) factory
232: .createMethodMetrics("test.test()")
233: .getMeasurement(
234: Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES))
235: .getValues();
236: assertEquals(
237: Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES
238: + " " + dependencies, 0, dependencies.size());
239:
240: dependencies = ((CollectionMeasurement) factory
241: .createMethodMetrics("test.test()")
242: .getMeasurement(
243: Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES))
244: .getValues();
245: assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES
246: + " " + dependencies, 0, dependencies.size());
247:
248: dependencies = ((CollectionMeasurement) factory
249: .createMethodMetrics("test.test()")
250: .getMeasurement(
251: Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES))
252: .getValues();
253: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES
254: + " " + dependencies
255: + "missing java.lang.Object.Object()", dependencies
256: .contains("java.lang.Object.Object()"));
257: assertEquals(
258: Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES
259: + " " + dependencies, 1, dependencies.size());
260:
261: dependencies = ((CollectionMeasurement) factory
262: .createMethodMetrics("test.test()")
263: .getMeasurement(
264: Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES))
265: .getValues();
266: assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
267: + " " + dependencies, 0, dependencies.size());
268: }
269:
270: public void test_test_main() {
271: assertEquals(Metrics.SLOC, 5, factory.createMethodMetrics(
272: "test.main(java.lang.String[])").getMeasurement(
273: Metrics.SLOC).intValue());
274: assertEquals(Metrics.PARAMETERS, 1, factory
275: .createMethodMetrics("test.main(java.lang.String[])")
276: .getMeasurement(Metrics.PARAMETERS).intValue());
277: assertEquals(Metrics.LOCAL_VARIABLES, 3, factory
278: .createMethodMetrics("test.main(java.lang.String[])")
279: .getMeasurement(Metrics.LOCAL_VARIABLES).intValue());
280:
281: //
282: // Dependencies
283: //
284:
285: Collection dependencies;
286:
287: dependencies = ((CollectionMeasurement) factory
288: .createMethodMetrics("test.main(java.lang.String[])")
289: .getMeasurement(
290: Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES))
291: .getValues();
292: assertEquals(Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES
293: + " " + dependencies, 0, dependencies.size());
294:
295: dependencies = ((CollectionMeasurement) factory
296: .createMethodMetrics("test.main(java.lang.String[])")
297: .getMeasurement(
298: Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES))
299: .getValues();
300: assertEquals(Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES
301: + " " + dependencies, 0, dependencies.size());
302:
303: dependencies = ((CollectionMeasurement) factory
304: .createMethodMetrics("test.main(java.lang.String[])")
305: .getMeasurement(
306: Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES))
307: .getValues();
308: assertEquals(Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES
309: + " " + dependencies, 0, dependencies.size());
310:
311: dependencies = ((CollectionMeasurement) factory
312: .createMethodMetrics("test.main(java.lang.String[])")
313: .getMeasurement(
314: Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES))
315: .getValues();
316: assertEquals(Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES
317: + " " + dependencies, 0, dependencies.size());
318:
319: dependencies = ((CollectionMeasurement) factory
320: .createMethodMetrics("test.main(java.lang.String[])")
321: .getMeasurement(
322: Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES))
323: .getValues();
324: assertEquals(
325: Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES
326: + " " + dependencies, 0, dependencies.size());
327:
328: dependencies = ((CollectionMeasurement) factory
329: .createMethodMetrics("test.main(java.lang.String[])")
330: .getMeasurement(
331: Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES))
332: .getValues();
333: assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES
334: + " " + dependencies, 0, dependencies.size());
335:
336: dependencies = ((CollectionMeasurement) factory
337: .createMethodMetrics("test.main(java.lang.String[])")
338: .getMeasurement(
339: Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES))
340: .getValues();
341: assertTrue(
342: Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES
343: + " "
344: + dependencies
345: + "missing java.util.Collections.singleton(java.lang.Object)",
346: dependencies
347: .contains("java.util.Collections.singleton(java.lang.Object)"));
348: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES
349: + " " + dependencies
350: + "missing java.lang.Object.Object()", dependencies
351: .contains("java.lang.Object.Object()"));
352: assertTrue(
353: Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES
354: + " "
355: + dependencies
356: + "missing java.io.PrintStream.println(java.lang.Object)",
357: dependencies
358: .contains("java.io.PrintStream.println(java.lang.Object)"));
359: assertEquals(
360: Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES
361: + " " + dependencies, 3, dependencies.size());
362:
363: dependencies = ((CollectionMeasurement) factory
364: .createMethodMetrics("test.main(java.lang.String[])")
365: .getMeasurement(
366: Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES))
367: .getValues();
368: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
369: + " " + dependencies + "missing java.io.PrintStream",
370: dependencies.contains("java.io.PrintStream"));
371: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
372: + " " + dependencies
373: + "missing java.lang.NullPointerException",
374: dependencies.contains("java.lang.NullPointerException"));
375: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
376: + " " + dependencies + "missing java.lang.Object",
377: dependencies.contains("java.lang.Object"));
378: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
379: + " " + dependencies + "missing java.lang.String",
380: dependencies.contains("java.lang.String"));
381: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
382: + " " + dependencies + "missing java.lang.System",
383: dependencies.contains("java.lang.System"));
384: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
385: + " " + dependencies + "missing java.util.Collection",
386: dependencies.contains("java.util.Collection"));
387: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
388: + " " + dependencies + "missing java.util.Set",
389: dependencies.contains("java.util.Set"));
390: assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES
391: + " " + dependencies, 7, dependencies.size());
392: }
393:
394: public void test_test() {
395: assertEquals(Metrics.SLOC, 7, factory
396: .createClassMetrics("test")
397: .getMeasurement(Metrics.SLOC).intValue());
398: assertEquals("M", 2, factory.createClassMetrics("test")
399: .getMeasurement("M").intValue());
400: assertEquals(Metrics.PUBLIC_METHODS, 2, factory
401: .createClassMetrics("test").getMeasurement(
402: Metrics.PUBLIC_METHODS).intValue());
403: assertEquals(Metrics.PROTECTED_METHODS, 0, factory
404: .createClassMetrics("test").getMeasurement(
405: Metrics.PROTECTED_METHODS).intValue());
406: assertEquals(Metrics.PRIVATE_METHODS, 0, factory
407: .createClassMetrics("test").getMeasurement(
408: Metrics.PRIVATE_METHODS).intValue());
409: assertEquals(Metrics.PACKAGE_METHODS, 0, factory
410: .createClassMetrics("test").getMeasurement(
411: Metrics.PACKAGE_METHODS).intValue());
412: assertEquals(Metrics.FINAL_METHODS, 0, factory
413: .createClassMetrics("test").getMeasurement(
414: Metrics.FINAL_METHODS).intValue());
415: assertEquals(Metrics.ABSTRACT_METHODS, 0, factory
416: .createClassMetrics("test").getMeasurement(
417: Metrics.ABSTRACT_METHODS).intValue());
418: assertEquals(Metrics.DEPRECATED_METHODS, 0, factory
419: .createClassMetrics("test").getMeasurement(
420: Metrics.DEPRECATED_METHODS).intValue());
421: assertEquals(Metrics.SYNTHETIC_METHODS, 0, factory
422: .createClassMetrics("test").getMeasurement(
423: Metrics.SYNTHETIC_METHODS).intValue());
424: assertEquals(Metrics.STATIC_METHODS, 1, factory
425: .createClassMetrics("test").getMeasurement(
426: Metrics.STATIC_METHODS).intValue());
427: assertEquals(Metrics.SYNCHRONIZED_METHODS, 0, factory
428: .createClassMetrics("test").getMeasurement(
429: Metrics.SYNCHRONIZED_METHODS).intValue());
430: assertEquals(Metrics.NATIVE_METHODS, 0, factory
431: .createClassMetrics("test").getMeasurement(
432: Metrics.NATIVE_METHODS).intValue());
433: assertEquals(Metrics.TRIVIAL_METHODS, 0, factory
434: .createClassMetrics("test").getMeasurement(
435: Metrics.TRIVIAL_METHODS).intValue());
436: assertEquals("PuMR", 1, factory.createClassMetrics("test")
437: .getMeasurement("PuMR").doubleValue(), 0.01);
438: assertEquals("ProMR", 0, factory.createClassMetrics("test")
439: .getMeasurement("ProMR").doubleValue(), 0.01);
440: assertEquals("PriMR", 0, factory.createClassMetrics("test")
441: .getMeasurement("PriMR").doubleValue(), 0.01);
442: assertEquals("PaMR", 0, factory.createClassMetrics("test")
443: .getMeasurement("PaMR").doubleValue(), 0.01);
444: assertEquals("FMR", 0, factory.createClassMetrics("test")
445: .getMeasurement("FMR").doubleValue(), 0.01);
446: assertEquals("AMR", 0, factory.createClassMetrics("test")
447: .getMeasurement("AMR").doubleValue(), 0.01);
448: assertEquals("DMR", 0, factory.createClassMetrics("test")
449: .getMeasurement("DMR").doubleValue(), 0.01);
450: assertEquals("SynthMR", 0, factory.createClassMetrics("test")
451: .getMeasurement("SynthMR").doubleValue(), 0.01);
452: assertEquals("SMR", 0.5, factory.createClassMetrics("test")
453: .getMeasurement("SMR").doubleValue(), 0.01);
454: assertEquals("SynchMR", 0, factory.createClassMetrics("test")
455: .getMeasurement("SynchMR").doubleValue(), 0.01);
456: assertEquals("NMR", 0, factory.createClassMetrics("test")
457: .getMeasurement("NMR").doubleValue(), 0.01);
458: assertEquals("TMR", 0, factory.createClassMetrics("test")
459: .getMeasurement("TMR").doubleValue(), 0.01);
460: assertEquals("A", 0, factory.createClassMetrics("test")
461: .getMeasurement("A").intValue());
462: assertEquals(Metrics.PUBLIC_ATTRIBUTES, 0, factory
463: .createClassMetrics("test").getMeasurement(
464: Metrics.PUBLIC_ATTRIBUTES).intValue());
465: assertEquals(Metrics.PROTECTED_ATTRIBUTES, 0, factory
466: .createClassMetrics("test").getMeasurement(
467: Metrics.PROTECTED_ATTRIBUTES).intValue());
468: assertEquals(Metrics.PRIVATE_ATTRIBUTES, 0, factory
469: .createClassMetrics("test").getMeasurement(
470: Metrics.PRIVATE_ATTRIBUTES).intValue());
471: assertEquals(Metrics.PACKAGE_ATTRIBUTES, 0, factory
472: .createClassMetrics("test").getMeasurement(
473: Metrics.PACKAGE_ATTRIBUTES).intValue());
474: assertEquals(Metrics.FINAL_ATTRIBUTES, 0, factory
475: .createClassMetrics("test").getMeasurement(
476: Metrics.FINAL_ATTRIBUTES).intValue());
477: assertEquals(Metrics.DEPRECATED_ATTRIBUTES, 0, factory
478: .createClassMetrics("test").getMeasurement(
479: Metrics.DEPRECATED_ATTRIBUTES).intValue());
480: assertEquals(Metrics.SYNTHETIC_ATTRIBUTES, 0, factory
481: .createClassMetrics("test").getMeasurement(
482: Metrics.SYNTHETIC_ATTRIBUTES).intValue());
483: assertEquals(Metrics.STATIC_ATTRIBUTES, 0, factory
484: .createClassMetrics("test").getMeasurement(
485: Metrics.STATIC_ATTRIBUTES).intValue());
486: assertEquals(Metrics.TRANSIENT_ATTRIBUTES, 0, factory
487: .createClassMetrics("test").getMeasurement(
488: Metrics.TRANSIENT_ATTRIBUTES).intValue());
489: assertEquals(Metrics.VOLATILE_ATTRIBUTES, 0, factory
490: .createClassMetrics("test").getMeasurement(
491: Metrics.VOLATILE_ATTRIBUTES).intValue());
492: assertTrue("PuAR", Double.isNaN(factory.createClassMetrics(
493: "test").getMeasurement("PuAR").doubleValue()));
494: assertTrue("ProAR", Double.isNaN(factory.createClassMetrics(
495: "test").getMeasurement("ProAR").doubleValue()));
496: assertTrue("PriAR", Double.isNaN(factory.createClassMetrics(
497: "test").getMeasurement("PriAR").doubleValue()));
498: assertTrue("PaAR", Double.isNaN(factory.createClassMetrics(
499: "test").getMeasurement("PaAR").doubleValue()));
500: assertTrue("FAR", Double.isNaN(factory.createClassMetrics(
501: "test").getMeasurement("FAR").doubleValue()));
502: assertTrue("DAR", Double.isNaN(factory.createClassMetrics(
503: "test").getMeasurement("DAR").doubleValue()));
504: assertTrue("SynthAR", Double.isNaN(factory.createClassMetrics(
505: "test").getMeasurement("SynthAR").doubleValue()));
506: assertTrue("SAR", Double.isNaN(factory.createClassMetrics(
507: "test").getMeasurement("SAR").doubleValue()));
508: assertTrue("TAR", Double.isNaN(factory.createClassMetrics(
509: "test").getMeasurement("TAR").doubleValue()));
510: assertTrue("VAR", Double.isNaN(factory.createClassMetrics(
511: "test").getMeasurement("VAR").doubleValue()));
512: assertEquals(Metrics.SUBCLASSES, 0, factory.createClassMetrics(
513: "test").getMeasurement(Metrics.SUBCLASSES).intValue());
514: assertEquals(Metrics.DEPTH_OF_INHERITANCE, 1, factory
515: .createClassMetrics("test").getMeasurement(
516: Metrics.DEPTH_OF_INHERITANCE).intValue());
517:
518: //
519: // Dependencies
520: //
521:
522: Collection dependencies;
523:
524: dependencies = ((CollectionMeasurement) factory
525: .createClassMetrics("test").getMeasurement(
526: Metrics.INBOUND_INTRA_PACKAGE_DEPENDENCIES))
527: .getValues();
528: assertEquals(Metrics.INBOUND_INTRA_PACKAGE_DEPENDENCIES + " "
529: + dependencies, 0, dependencies.size());
530:
531: dependencies = ((CollectionMeasurement) factory
532: .createClassMetrics("test").getMeasurement(
533: Metrics.INBOUND_EXTRA_PACKAGE_DEPENDENCIES))
534: .getValues();
535: assertEquals(Metrics.INBOUND_EXTRA_PACKAGE_DEPENDENCIES + " "
536: + dependencies, 0, dependencies.size());
537:
538: dependencies = ((CollectionMeasurement) factory
539: .createClassMetrics("test").getMeasurement(
540: Metrics.OUTBOUND_INTRA_PACKAGE_DEPENDENCIES))
541: .getValues();
542: assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_DEPENDENCIES + " "
543: + dependencies, 0, dependencies.size());
544:
545: dependencies = ((CollectionMeasurement) factory
546: .createClassMetrics("test").getMeasurement(
547: Metrics.OUTBOUND_EXTRA_PACKAGE_DEPENDENCIES))
548: .getValues();
549: assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_DEPENDENCIES, 1,
550: dependencies.size());
551: assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_DEPENDENCIES + " "
552: + dependencies + "missing java.lang.Object",
553: dependencies.contains("java.lang.Object"));
554: }
555:
556: public void test_() {
557: assertEquals(Metrics.SLOC, 7, factory.createGroupMetrics("")
558: .getMeasurement(Metrics.SLOC).intValue());
559: }
560:
561: public void testProject() {
562: assertEquals(Metrics.SLOC, 7, factory.createProjectMetrics(
563: "test").getMeasurement(Metrics.SLOC).intValue());
564: }
565: }
|