KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > 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.dependency;
34
35 import java.io.*;
36
37 import junit.framework.*;
38
39 public class TestMetricsGatherer extends TestCase {
40     private NodeFactory factory;
41     
42     private Node _package;
43     private Node test_class;
44     private Node test_main_method;
45     private Node test_test_method;
46         
47     private Node java_lang_package;
48     private Node java_lang_Object_class;
49     private Node java_lang_Object_Object_method;
50     private Node java_lang_String_class;
51         
52     private Node java_io_package;
53     private Node java_io_Writer_class;
54     private Node java_io_Writer_write_method;
55         
56     private Node java_util_package;
57     private Node java_util_Collections_class;
58     private Node java_util_Collections_singleton_method;
59     private Node java_util_Set_class;
60
61     private MetricsGatherer metrics;
62
63     protected void setUp() throws Exception JavaDoc {
64         factory = new NodeFactory();
65
66         _package = factory.createPackage("");
67         test_class = factory.createClass("test");
68         test_main_method = factory.createFeature("test.main(java.lang.String[])");
69         test_test_method = factory.createFeature("test.test()");
70         
71         java_lang_package = factory.createPackage("java.lang");
72         java_lang_Object_class = factory.createClass("java.lang.Object");
73         java_lang_Object_Object_method = factory.createFeature("java.lang.Object.Object()");
74         java_lang_String_class = factory.createClass("java.lang.String");
75
76         java_io_package = factory.createPackage("java.io");
77         java_io_Writer_class = factory.createClass("java.io.Writer");
78         java_io_Writer_write_method = factory.createFeature("java.io.Writer.write(int)");
79         
80         java_util_package = factory.createPackage("java.util");
81         java_util_Collections_class = factory.createClass("java.util.Collections");
82         java_util_Collections_singleton_method = factory.createFeature("java.util.Collections.singleton(java.lang.Object)");
83         java_util_Set_class = factory.createClass("java.util.Set");
84
85         test_class.addDependency(java_lang_Object_class);
86         test_main_method.addDependency(java_lang_Object_class);
87         test_main_method.addDependency(java_lang_Object_Object_method);
88         test_main_method.addDependency(java_lang_String_class);
89         test_main_method.addDependency(java_util_Collections_singleton_method);
90         test_main_method.addDependency(java_util_Set_class);
91         test_test_method.addDependency(java_lang_Object_Object_method);
92
93         metrics = new MetricsGatherer();
94     }
95
96     public void testEverything() throws IOException {
97         metrics.traverseNodes(factory.getPackages().values());
98
99         assertEquals("Number of packages", 4, metrics.getPackages().size());
100         assertEquals("Number of classes", 6, metrics.getClasses().size());
101         assertEquals("Number of features", 5, metrics.getFeatures().size());
102
103         assertEquals("Number of inbounds", 7, metrics.getNbInbound());
104         assertEquals("Number of inbounds to packages", 0, metrics.getNbInboundPackages());
105         assertEquals("Number of inbounds to classes", 4, metrics.getNbInboundClasses());
106         assertEquals("Number of inbounds to features", 3, metrics.getNbInboundFeatures());
107
108         assertEquals("Number of outbounds", 7, metrics.getNbOutbound());
109         assertEquals("Number of outbounds from packages", 0, metrics.getNbOutboundPackages());
110         assertEquals("Number of outbounds from classes", 1, metrics.getNbOutboundClasses());
111         assertEquals("Number of outbounds from features", 6, metrics.getNbOutboundFeatures());
112     }
113 }
114
Popular Tags