KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > metrics > TestMetricsGatherer


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.metrics;
34
35 import junit.framework.*;
36
37 import java.io.*;
38 import java.util.*;
39
40 import org.xml.sax.*;
41
42 import com.jeantessier.classreader.*;
43
44 public class TestMetricsGatherer extends TestCase {
45     public static final String JavaDoc TEST_CLASS = "test";
46     public static final String JavaDoc TEST_FILENAME = "classes" + File.separator + "test.class";
47
48     private MetricsFactory factory;
49     private ClassfileLoader loader;
50     
51     protected void setUp() throws Exception JavaDoc {
52         factory = new MetricsFactory("test", new MetricsConfigurationLoader(Boolean.getBoolean("DEPENDENCYFINDER_TESTS_VALIDATE")).load("etc" + File.separator + "MetricsConfig.xml"));
53
54         loader = new AggregatingClassfileLoader();
55         loader.load(Collections.singleton(TEST_FILENAME));
56
57         loader.getClassfile(TEST_CLASS).accept(new MetricsGatherer("test", factory));
58     }
59     
60     public void testNbElements() {
61         assertEquals("factory.ProjectNames().size()", 1, factory.getProjectNames().size());
62         assertTrue(factory.getProjectNames().toString() + " does not contain project \"test\"", factory.getProjectNames().contains("test"));
63
64         assertTrue(factory.getGroupNames().toString() + " does not contain package \"\"", factory.getGroupNames().contains(""));
65         assertEquals(factory.getGroupNames().toString(), 1, factory.getGroupNames().size());
66
67         assertTrue(factory.getClassNames().toString() + " does not contain class \"test\"", factory.getClassNames().contains("test"));
68         assertEquals(factory.getClassNames().toString(), 1, factory.getClassNames().size());
69
70         assertTrue(factory.getMethodNames().toString() + " does not contain method \"test.main(java.lang.String[])\"", factory.getMethodNames().contains("test.main(java.lang.String[])"));
71         assertTrue(factory.getMethodNames().toString() + " does not contain method \"test.test()\"", factory.getMethodNames().contains("test.test()"));
72         assertEquals(factory.getMethodNames().toString(), 2, factory.getMethodNames().size());
73     }
74     
75     public void testNbAllElements() throws IOException, SAXException {
76         assertEquals("factory.AllProjectNames().size()", 1, factory.getAllProjectNames().size());
77         assertTrue(factory.getAllProjectNames().toString() + " does not contain project \"test\"", factory.getAllProjectNames().contains("test"));
78
79         assertTrue(factory.getAllGroupNames().toString() + " does not contain package \"\"", factory.getAllGroupNames().contains(""));
80         assertTrue(factory.getAllGroupNames().toString() + " does not contain package \"java.lang\"", factory.getAllGroupNames().contains("java.lang"));
81         assertTrue(factory.getAllGroupNames().toString() + " does not contain package \"java.util\"", factory.getAllGroupNames().contains("java.util"));
82         assertTrue(factory.getAllGroupNames().toString() + " does not contain package \"java.io\"", factory.getAllGroupNames().contains("java.util"));
83         assertEquals(factory.getAllGroupNames().toString(), 4, factory.getAllGroupNames().size());
84
85         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.io.PrintStream\"", factory.getAllClassNames().contains("java.io.PrintStream"));
86         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.lang.NullPointerException\"", factory.getAllClassNames().contains("java.lang.NullPointerException"));
87         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.lang.Object\"", factory.getAllClassNames().contains("java.lang.Object"));
88         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.lang.String\"", factory.getAllClassNames().contains("java.lang.String"));
89         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.lang.System\"", factory.getAllClassNames().contains("java.lang.System"));
90         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.util.Collections\"", factory.getAllClassNames().contains("java.util.Collections"));
91         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.util.Collection\"", factory.getAllClassNames().contains("java.util.Collection"));
92         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"java.util.Set\"", factory.getAllClassNames().contains("java.util.Set"));
93         assertTrue(factory.getAllClassNames().toString() + " does not contain class \"test\"", factory.getAllClassNames().contains("test"));
94         assertEquals(factory.getAllClassNames().toString(), 9, factory.getAllClassNames().size());
95
96         assertTrue(factory.getAllMethodNames().toString() + " does not contain method \"java.io.PrintStream.println(java.lang.Object)\"", factory.getAllMethodNames().contains("java.io.PrintStream.println(java.lang.Object)"));
97         assertTrue(factory.getAllMethodNames().toString() + " does not contain method \"java.lang.Object.Object()\"", factory.getAllMethodNames().contains("java.lang.Object.Object()"));
98         assertTrue(factory.getAllMethodNames().toString() + " does not contain method \"java.util.Collections.singleton(java.lang.Object)\"", factory.getAllMethodNames().contains("java.util.Collections.singleton(java.lang.Object)"));
99         assertTrue(factory.getAllMethodNames().toString() + " does not contain method \"test.main(java.lang.String[])\"", factory.getAllMethodNames().contains("test.main(java.lang.String[])"));
100         assertTrue(factory.getAllMethodNames().toString() + " does not contain method \"test.test()\"", factory.getAllMethodNames().contains("test.test()"));
101         assertEquals(factory.getAllMethodNames().toString(), 5, factory.getAllMethodNames().size());
102     }
103     
104     public void test_test_test() {
105         assertEquals(Metrics.SLOC, 1, factory.createMethodMetrics("test.test()").getMeasurement(Metrics.SLOC).intValue());
106         assertEquals(Metrics.PARAMETERS, 0, factory.createMethodMetrics("test.test()").getMeasurement(Metrics.PARAMETERS).intValue());
107         assertEquals(Metrics.LOCAL_VARIABLES, 1, factory.createMethodMetrics("test.test()").getMeasurement(Metrics.LOCAL_VARIABLES).intValue());
108
109         //
110
// Dependencies
111
//
112

113         Collection dependencies;
114
115         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES)).getValues();
116         assertEquals(Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
117
118         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES)).getValues();
119         assertEquals(Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
120
121         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES)).getValues();
122         assertEquals(Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
123
124         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES)).getValues();
125         assertEquals(Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
126
127         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES)).getValues();
128         assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
129
130         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES)).getValues();
131         assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
132
133         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES)).getValues();
134         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies + "missing java.lang.Object.Object()", dependencies.contains("java.lang.Object.Object()"));
135         assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies, 1, dependencies.size());
136
137         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.test()").getMeasurement(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES)).getValues();
138         assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
139     }
140     
141     public void test_test_main() {
142         assertEquals(Metrics.SLOC, 5, factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.SLOC).intValue());
143         assertEquals(Metrics.PARAMETERS, 1, factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.PARAMETERS).intValue());
144         assertEquals(Metrics.LOCAL_VARIABLES, 3, factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.LOCAL_VARIABLES).intValue());
145
146         //
147
// Dependencies
148
//
149

150         Collection dependencies;
151
152         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES)).getValues();
153         assertEquals(Metrics.INBOUND_INTRA_CLASS_METHOD_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
154
155         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES)).getValues();
156         assertEquals(Metrics.INBOUND_INTRA_PACKAGE_METHOD_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
157
158         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES)).getValues();
159         assertEquals(Metrics.INBOUND_EXTRA_PACKAGE_METHOD_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
160
161         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES)).getValues();
162         assertEquals(Metrics.OUTBOUND_INTRA_CLASS_FEATURE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
163
164         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES)).getValues();
165         assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
166
167         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES)).getValues();
168         assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
169
170         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES)).getValues();
171         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies + "missing java.util.Collections.singleton(java.lang.Object)", dependencies.contains("java.util.Collections.singleton(java.lang.Object)"));
172         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies + "missing java.lang.Object.Object()", dependencies.contains("java.lang.Object.Object()"));
173         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies + "missing java.io.PrintStream.println(java.lang.Object)", dependencies.contains("java.io.PrintStream.println(java.lang.Object)"));
174         assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_FEATURE_DEPENDENCIES + " " + dependencies, 3, dependencies.size());
175
176         dependencies = ((CollectionMeasurement) factory.createMethodMetrics("test.main(java.lang.String[])").getMeasurement(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES)).getValues();
177         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.io.PrintStream", dependencies.contains("java.io.PrintStream"));
178         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.lang.NullPointerException", dependencies.contains("java.lang.NullPointerException"));
179         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.lang.Object", dependencies.contains("java.lang.Object"));
180         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.lang.String", dependencies.contains("java.lang.String"));
181         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.lang.System", dependencies.contains("java.lang.System"));
182         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.util.Collection", dependencies.contains("java.util.Collection"));
183         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies + "missing java.util.Set", dependencies.contains("java.util.Set"));
184         assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_CLASS_DEPENDENCIES + " " + dependencies, 7, dependencies.size());
185     }
186     
187     public void test_test() {
188         assertEquals(Metrics.SLOC, 7, factory.createClassMetrics("test").getMeasurement(Metrics.SLOC).intValue());
189         assertEquals("M", 2, factory.createClassMetrics("test").getMeasurement("M").intValue());
190         assertEquals(Metrics.PUBLIC_METHODS, 2, factory.createClassMetrics("test").getMeasurement(Metrics.PUBLIC_METHODS).intValue());
191         assertEquals(Metrics.PROTECTED_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PROTECTED_METHODS).intValue());
192         assertEquals(Metrics.PRIVATE_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PRIVATE_METHODS).intValue());
193         assertEquals(Metrics.PACKAGE_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PACKAGE_METHODS).intValue());
194         assertEquals(Metrics.FINAL_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.FINAL_METHODS).intValue());
195         assertEquals(Metrics.ABSTRACT_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.ABSTRACT_METHODS).intValue());
196         assertEquals(Metrics.DEPRECATED_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.DEPRECATED_METHODS).intValue());
197         assertEquals(Metrics.SYNTHETIC_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.SYNTHETIC_METHODS).intValue());
198         assertEquals(Metrics.STATIC_METHODS, 1, factory.createClassMetrics("test").getMeasurement(Metrics.STATIC_METHODS).intValue());
199         assertEquals(Metrics.SYNCHRONIZED_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.SYNCHRONIZED_METHODS).intValue());
200         assertEquals(Metrics.NATIVE_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.NATIVE_METHODS).intValue());
201         assertEquals(Metrics.TRIVIAL_METHODS, 0, factory.createClassMetrics("test").getMeasurement(Metrics.TRIVIAL_METHODS).intValue());
202         assertEquals("PuMR", 1, factory.createClassMetrics("test").getMeasurement("PuMR").doubleValue(), 0.01);
203         assertEquals("ProMR", 0, factory.createClassMetrics("test").getMeasurement("ProMR").doubleValue(), 0.01);
204         assertEquals("PriMR", 0, factory.createClassMetrics("test").getMeasurement("PriMR").doubleValue(), 0.01);
205         assertEquals("PaMR", 0, factory.createClassMetrics("test").getMeasurement("PaMR").doubleValue(), 0.01);
206         assertEquals("FMR", 0, factory.createClassMetrics("test").getMeasurement("FMR").doubleValue(), 0.01);
207         assertEquals("AMR", 0, factory.createClassMetrics("test").getMeasurement("AMR").doubleValue(), 0.01);
208         assertEquals("DMR", 0, factory.createClassMetrics("test").getMeasurement("DMR").doubleValue(), 0.01);
209         assertEquals("SynthMR", 0, factory.createClassMetrics("test").getMeasurement("SynthMR").doubleValue(), 0.01);
210         assertEquals("SMR", 0.5, factory.createClassMetrics("test").getMeasurement("SMR").doubleValue(), 0.01);
211         assertEquals("SynchMR", 0, factory.createClassMetrics("test").getMeasurement("SynchMR").doubleValue(), 0.01);
212         assertEquals("NMR", 0, factory.createClassMetrics("test").getMeasurement("NMR").doubleValue(), 0.01);
213         assertEquals("TMR", 0, factory.createClassMetrics("test").getMeasurement("TMR").doubleValue(), 0.01);
214         assertEquals("A", 0, factory.createClassMetrics("test").getMeasurement("A").intValue());
215         assertEquals(Metrics.PUBLIC_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PUBLIC_ATTRIBUTES).intValue());
216         assertEquals(Metrics.PROTECTED_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PROTECTED_ATTRIBUTES).intValue());
217         assertEquals(Metrics.PRIVATE_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PRIVATE_ATTRIBUTES).intValue());
218         assertEquals(Metrics.PACKAGE_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.PACKAGE_ATTRIBUTES).intValue());
219         assertEquals(Metrics.FINAL_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.FINAL_ATTRIBUTES).intValue());
220         assertEquals(Metrics.DEPRECATED_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.DEPRECATED_ATTRIBUTES).intValue());
221         assertEquals(Metrics.SYNTHETIC_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.SYNTHETIC_ATTRIBUTES).intValue());
222         assertEquals(Metrics.STATIC_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.STATIC_ATTRIBUTES).intValue());
223         assertEquals(Metrics.TRANSIENT_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.TRANSIENT_ATTRIBUTES).intValue());
224         assertEquals(Metrics.VOLATILE_ATTRIBUTES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.VOLATILE_ATTRIBUTES).intValue());
225         assertTrue("PuAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("PuAR").doubleValue()));
226         assertTrue("ProAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("ProAR").doubleValue()));
227         assertTrue("PriAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("PriAR").doubleValue()));
228         assertTrue("PaAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("PaAR").doubleValue()));
229         assertTrue("FAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("FAR").doubleValue()));
230         assertTrue("DAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("DAR").doubleValue()));
231         assertTrue("SynthAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("SynthAR").doubleValue()));
232         assertTrue("SAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("SAR").doubleValue()));
233         assertTrue("TAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("TAR").doubleValue()));
234         assertTrue("VAR", Double.isNaN(factory.createClassMetrics("test").getMeasurement("VAR").doubleValue()));
235         assertEquals(Metrics.SUBCLASSES, 0, factory.createClassMetrics("test").getMeasurement(Metrics.SUBCLASSES).intValue());
236         assertEquals(Metrics.DEPTH_OF_INHERITANCE, 1, factory.createClassMetrics("test").getMeasurement(Metrics.DEPTH_OF_INHERITANCE).intValue());
237
238         //
239
// Dependencies
240
//
241

242         Collection dependencies;
243
244         dependencies = ((CollectionMeasurement) factory.createClassMetrics("test").getMeasurement(Metrics.INBOUND_INTRA_PACKAGE_DEPENDENCIES)).getValues();
245         assertEquals(Metrics.INBOUND_INTRA_PACKAGE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
246         
247         dependencies = ((CollectionMeasurement) factory.createClassMetrics("test").getMeasurement(Metrics.INBOUND_EXTRA_PACKAGE_DEPENDENCIES)).getValues();
248         assertEquals(Metrics.INBOUND_EXTRA_PACKAGE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
249         
250         dependencies = ((CollectionMeasurement) factory.createClassMetrics("test").getMeasurement(Metrics.OUTBOUND_INTRA_PACKAGE_DEPENDENCIES)).getValues();
251         assertEquals(Metrics.OUTBOUND_INTRA_PACKAGE_DEPENDENCIES + " " + dependencies, 0, dependencies.size());
252         
253         dependencies = ((CollectionMeasurement) factory.createClassMetrics("test").getMeasurement(Metrics.OUTBOUND_EXTRA_PACKAGE_DEPENDENCIES)).getValues();
254         assertEquals(Metrics.OUTBOUND_EXTRA_PACKAGE_DEPENDENCIES, 1, dependencies.size());
255         assertTrue(Metrics.OUTBOUND_EXTRA_PACKAGE_DEPENDENCIES + " " + dependencies + "missing java.lang.Object", dependencies.contains("java.lang.Object"));
256     }
257
258     public void test_() {
259         assertEquals(Metrics.SLOC, 7, factory.createGroupMetrics("").getMeasurement(Metrics.SLOC).intValue());
260     }
261
262     public void testProject() {
263         assertEquals(Metrics.SLOC, 7, factory.createProjectMetrics("test").getMeasurement(Metrics.SLOC).intValue());
264     }
265 }
266
Popular Tags