KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > TestLinkMinimizer


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 import java.util.*;
37
38 import junit.framework.*;
39
40 import org.apache.oro.text.perl.*;
41
42 public class TestLinkMinimizer extends TestCase {
43     NodeFactory factory;
44     
45     Node _package;
46     Node test_class;
47     Node test_main_method;
48     Node test_test_method;
49         
50     Node java_lang_package;
51     Node java_lang_Object_class;
52     Node java_lang_Object_Object_method;
53     Node java_lang_String_class;
54         
55     Node java_util_package;
56     Node java_util_Collections_class;
57     Node java_util_Collections_singleton_method;
58     Node java_util_Set_class;
59     
60     LinkMinimizer visitor;
61
62     protected void setUp() throws Exception JavaDoc {
63         factory = new NodeFactory();
64
65         _package = factory.createPackage("");
66         test_class = factory.createClass("test");
67         test_main_method = factory.createFeature("test.main(String[])");
68         test_test_method = factory.createFeature("test.test()");
69         
70         java_lang_package = factory.createPackage("java.lang");
71         java_lang_Object_class = factory.createClass("java.lang.Object");
72         java_lang_Object_Object_method = factory.createFeature("java.lang.Object.Object()");
73         java_lang_String_class = factory.createClass("java.lang.String");
74         
75         java_util_package = factory.createPackage("java.util");
76         java_util_Collections_class = factory.createClass("java.util.Collections");
77         java_util_Collections_singleton_method = factory.createFeature("java.util.Collections.singleton(java.lang.Object)");
78         java_util_Set_class = factory.createClass("java.util.Set");
79     
80         test_class.addDependency(java_lang_Object_class);
81         test_main_method.addDependency(java_lang_Object_class);
82         test_main_method.addDependency(java_lang_Object_Object_method);
83         test_main_method.addDependency(java_lang_String_class);
84         test_main_method.addDependency(java_util_Collections_singleton_method);
85         test_main_method.addDependency(java_util_Set_class);
86         test_test_method.addDependency(java_lang_Object_Object_method);
87
88         visitor = new LinkMinimizer();
89         visitor.traverseNodes(factory.getPackages().values());
90     }
91
92     public void test_package() {
93         assertEquals("_package.Outbound()",
94                      0,
95                      _package.getOutboundDependencies().size());
96         assertEquals("_package.Inbound()",
97                      0,
98                      _package.getInboundDependencies().size());
99     }
100
101     public void testtest_class() {
102         assertEquals("test_class.Outbound()",
103                      0,
104                      test_class.getOutboundDependencies().size());
105         assertEquals("test_class.Inbound()",
106                      0,
107                      test_class.getInboundDependencies().size());
108     }
109
110     public void testtest_main_method() {
111         assertEquals("test_main_method.Outbound()",
112                      4,
113                      test_main_method.getOutboundDependencies().size());
114         assertTrue("test.main(java.lang.String[]) missing " + java_lang_Object_Object_method,
115                    test_main_method.getOutboundDependencies().contains(java_lang_Object_Object_method));
116         assertTrue("test.main(java.lang.String[]) missing " + java_lang_String_class,
117                    test_main_method.getOutboundDependencies().contains(java_lang_String_class));
118         assertTrue("test.main(java.lang.String[]) missing " + java_util_Collections_singleton_method,
119                    test_main_method.getOutboundDependencies().contains(java_util_Collections_singleton_method));
120         assertTrue("test.main(java.lang.String[]) missing " + java_util_Set_class,
121                    test_main_method.getOutboundDependencies().contains(java_util_Set_class));
122         assertEquals("test_main_method.Inbound()",
123                      0,
124                      test_main_method.getInboundDependencies().size());
125     }
126
127     public void testtest_test_method() {
128         assertEquals("test_test_method.Outbound()",
129                      1,
130                      test_test_method.getOutboundDependencies().size());
131         assertTrue("test.test() missing " + java_lang_Object_Object_method,
132                    test_test_method.getOutboundDependencies().contains(java_lang_Object_Object_method));
133         assertEquals("_package.Inbound()",
134                      0,
135                      test_test_method.getInboundDependencies().size());
136     }
137
138     public void testjava_lang_package() {
139         assertEquals("java_lang_package.Outbound()",
140                      0,
141                      java_lang_package.getOutboundDependencies().size());
142         assertEquals("java_lang_package.Inbound()",
143                      0,
144                      java_lang_package.getInboundDependencies().size());
145     }
146
147     public void testjava_lang_Object_class() {
148         assertEquals("java_lang_Object_class.Outbound()",
149                      0,
150                      java_lang_Object_class.getOutboundDependencies().size());
151         assertEquals("java_lang_Object_class.Inbound()",
152                      0,
153                      java_lang_Object_class.getInboundDependencies().size());
154     }
155
156     public void testjava_lang_Object_Object_method() {
157         assertEquals("java_lang_Object_Object_method.Outbound()",
158                      0,
159                      java_lang_Object_Object_method.getOutboundDependencies().size());
160         assertEquals("java_lang_Object_Object_method.Inbound()",
161                      2,
162                      java_lang_Object_Object_method.getInboundDependencies().size());
163         assertTrue("java.lang.Object.Object() missing " + test_main_method,
164                    java_lang_Object_Object_method.getInboundDependencies().contains(test_main_method));
165         assertTrue("java.lang.Object.Object() missing " + test_test_method,
166                    java_lang_Object_Object_method.getInboundDependencies().contains(test_test_method));
167     }
168
169     public void testjava_lang_String_class() {
170         assertEquals("java_lang_String_class.Outbound()",
171                      0,
172                      java_lang_String_class.getOutboundDependencies().size());
173         assertEquals("java_lang_String_class.Inbound()",
174                      1,
175                      java_lang_String_class.getInboundDependencies().size());
176         assertTrue("java.lang.String missing " + test_main_method,
177                    java_lang_String_class.getInboundDependencies().contains(test_main_method));
178     }
179
180     public void testjava_util_package() {
181         assertEquals("java_util_package.Outbound()",
182                      0,
183                      java_util_package.getOutboundDependencies().size());
184         assertEquals("java_util_package.Inbound()",
185                      0,
186                      java_util_package.getInboundDependencies().size());
187     }
188
189     public void testjava_util_Collections_class() {
190         assertEquals("java_util_Collections_class.Outbound()",
191                      0,
192                      java_util_Collections_class.getOutboundDependencies().size());
193         assertEquals("java_util_Collections_class.Inbound()",
194                      0,
195                      java_util_Collections_class.getInboundDependencies().size());
196     }
197
198     public void testjava_util_Collections_singleton_method() {
199         assertEquals("java_util_Collections_singleton_method.Outbound()",
200                      0,
201                      java_util_Collections_singleton_method.getOutboundDependencies().size());
202         assertEquals("java_util_Collections_singleton_method.Inbound()",
203                      1,
204                      java_util_Collections_singleton_method.getInboundDependencies().size());
205         assertTrue("java.util.Collections.singleton(java.lang.Object) missing " + test_main_method,
206                    java_util_Collections_singleton_method.getInboundDependencies().contains(test_main_method));
207     }
208
209     public void testjava_util_Set_class() {
210         assertEquals("java_util_Set_class.Outbound()",
211                      0,
212                      java_util_Set_class.getOutboundDependencies().size());
213         assertEquals("java_util_Set_class.Inbound()",
214                      1,
215                      java_util_Set_class.getInboundDependencies().size());
216         assertTrue("java.util.Set missing " + test_main_method,
217                    java_util_Set_class.getInboundDependencies().contains(test_main_method));
218     }
219 }
220
Popular Tags