KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestLinkMaximizer 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     LinkMaximizer 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 LinkMaximizer();
89         visitor.traverseNodes(factory.getPackages().values());
90     }
91
92     public void test_package() {
93         assertEquals("_package.Outbound()",
94                      8,
95                      _package.getOutboundDependencies().size());
96         assertTrue("default missing " + java_lang_package,
97                    _package.getOutboundDependencies().contains(java_lang_package));
98         assertTrue("default missing " + java_lang_Object_class,
99                    _package.getOutboundDependencies().contains(java_lang_Object_class));
100         assertTrue("default missing " + java_lang_Object_Object_method,
101                    _package.getOutboundDependencies().contains(java_lang_Object_Object_method));
102         assertTrue("default missing " + java_lang_String_class,
103                    _package.getOutboundDependencies().contains(java_lang_String_class));
104         assertTrue("default missing " + java_util_package,
105                    _package.getOutboundDependencies().contains(java_util_package));
106         assertTrue("default missing " + java_util_Collections_class,
107                    _package.getOutboundDependencies().contains(java_util_Collections_class));
108         assertTrue("default missing " + java_util_Collections_singleton_method,
109                    _package.getOutboundDependencies().contains(java_util_Collections_singleton_method));
110         assertTrue("default missing " + java_util_Set_class,
111                    _package.getOutboundDependencies().contains(java_util_Set_class));
112         assertEquals("_package.Inbound()",
113                      0,
114                      _package.getInboundDependencies().size());
115     }
116
117     public void testtest_class() {
118         assertEquals("test_class.Outbound()",
119                      8,
120                      test_class.getOutboundDependencies().size());
121         assertTrue("test missing " + java_lang_package,
122                    test_class.getOutboundDependencies().contains(java_lang_package));
123         assertTrue("test missing " + java_lang_Object_class,
124                    test_class.getOutboundDependencies().contains(java_lang_Object_class));
125         assertTrue("test missing " + java_lang_Object_Object_method,
126                    test_class.getOutboundDependencies().contains(java_lang_Object_Object_method));
127         assertTrue("test missing " + java_lang_String_class,
128                    test_class.getOutboundDependencies().contains(java_lang_String_class));
129         assertTrue("test missing " + java_util_package,
130                    test_class.getOutboundDependencies().contains(java_util_package));
131         assertTrue("test missing " + java_util_Collections_class,
132                    test_class.getOutboundDependencies().contains(java_util_Collections_class));
133         assertTrue("test missing " + java_util_Collections_singleton_method,
134                    test_class.getOutboundDependencies().contains(java_util_Collections_singleton_method));
135         assertTrue("test missing " + java_util_Set_class,
136                    test_class.getOutboundDependencies().contains(java_util_Set_class));
137         assertEquals("test_class.Inbound()",
138                      0,
139                      test_class.getInboundDependencies().size());
140     }
141
142     public void testtest_main_method() {
143         assertEquals("test_main_method.Outbound()",
144                      8,
145                      test_main_method.getOutboundDependencies().size());
146         assertTrue("test.main(java.lang.String[]) missing " + java_lang_package,
147                    test_main_method.getOutboundDependencies().contains(java_lang_package));
148         assertTrue("test.main(java.lang.String[]) missing " + java_lang_Object_class,
149                    test_main_method.getOutboundDependencies().contains(java_lang_Object_class));
150         assertTrue("test.main(java.lang.String[]) missing " + java_lang_Object_Object_method,
151                    test_main_method.getOutboundDependencies().contains(java_lang_Object_Object_method));
152         assertTrue("test.main(java.lang.String[]) missing " + java_lang_String_class,
153                    test_main_method.getOutboundDependencies().contains(java_lang_String_class));
154         assertTrue("test.main(java.lang.String[]) missing " + java_util_package,
155                    test_main_method.getOutboundDependencies().contains(java_util_package));
156         assertTrue("test.main(java.lang.String[]) missing " + java_util_Collections_class,
157                    test_main_method.getOutboundDependencies().contains(java_util_Collections_class));
158         assertTrue("test.main(java.lang.String[]) missing " + java_util_Collections_singleton_method,
159                    test_main_method.getOutboundDependencies().contains(java_util_Collections_singleton_method));
160         assertTrue("test.main(java.lang.String[]) missing " + java_util_Set_class,
161                    test_main_method.getOutboundDependencies().contains(java_util_Set_class));
162         assertEquals("test_main_method.Inbound()",
163                      0,
164                      test_main_method.getInboundDependencies().size());
165     }
166
167     public void testtest_test_method() {
168         assertEquals("test_test_method.Outbound()",
169                      3,
170                      test_test_method.getOutboundDependencies().size());
171         assertTrue("test.test() missing " + java_lang_package,
172                    test_test_method.getOutboundDependencies().contains(java_lang_package));
173         assertTrue("test.test() missing " + java_lang_Object_class,
174                    test_test_method.getOutboundDependencies().contains(java_lang_Object_class));
175         assertTrue("test.test() missing " + java_lang_Object_Object_method,
176                    test_test_method.getOutboundDependencies().contains(java_lang_Object_Object_method));
177         assertEquals("_package.Inbound()",
178                      0,
179                      test_test_method.getInboundDependencies().size());
180     }
181
182     public void testjava_lang_package() {
183         assertEquals("java_lang_package.Outbound()",
184                      0,
185                      java_lang_package.getOutboundDependencies().size());
186         assertEquals("java_lang_package.Inbound()",
187                      4,
188                      java_lang_package.getInboundDependencies().size());
189         assertTrue("java.lang missing " + _package,
190                    java_lang_package.getInboundDependencies().contains(_package));
191         assertTrue("java.lang missing " + test_class,
192                    java_lang_package.getInboundDependencies().contains(test_class));
193         assertTrue("java.lang missing " + test_main_method,
194                    java_lang_package.getInboundDependencies().contains(test_main_method));
195         assertTrue("java.lang missing " + test_test_method,
196                    java_lang_package.getInboundDependencies().contains(test_test_method));
197     }
198
199     public void testjava_lang_Object_class() {
200         assertEquals("java_lang_Object_class.Outbound()",
201                      0,
202                      java_lang_Object_class.getOutboundDependencies().size());
203         assertEquals("java_lang_Object_class.Inbound()",
204                      4,
205                      java_lang_Object_class.getInboundDependencies().size());
206         assertTrue("java.lang.Object missing " + _package,
207                    java_lang_Object_class.getInboundDependencies().contains(_package));
208         assertTrue("java.lang.Object missing " + test_class,
209                    java_lang_Object_class.getInboundDependencies().contains(test_class));
210         assertTrue("java.lang.Object missing " + test_main_method,
211                    java_lang_Object_class.getInboundDependencies().contains(test_main_method));
212         assertTrue("java.lang.Object missing " + test_test_method,
213                    java_lang_Object_class.getInboundDependencies().contains(test_test_method));
214     }
215
216     public void testjava_lang_Object_Object_method() {
217         assertEquals("java_lang_Object_Object_method.Outbound()",
218                      0,
219                      java_lang_Object_Object_method.getOutboundDependencies().size());
220         assertEquals("java_lang_Object_Object_method.Inbound()",
221                      4,
222                      java_lang_Object_Object_method.getInboundDependencies().size());
223         assertTrue("java.lang.Object.Object() missing " + _package,
224                    java_lang_Object_Object_method.getInboundDependencies().contains(_package));
225         assertTrue("java.lang.Object.Object() missing " + test_class,
226                    java_lang_Object_Object_method.getInboundDependencies().contains(test_class));
227         assertTrue("java.lang.Object.Object() missing " + test_main_method,
228                    java_lang_Object_Object_method.getInboundDependencies().contains(test_main_method));
229         assertTrue("java.lang.Object.Object() missing " + test_test_method,
230                    java_lang_Object_Object_method.getInboundDependencies().contains(test_test_method));
231     }
232
233     public void testjava_lang_String_class() {
234         assertEquals("java_lang_String_class.Outbound()",
235                      0,
236                      java_lang_String_class.getOutboundDependencies().size());
237         assertEquals("java_lang_String_class.Inbound()",
238                      3,
239                      java_lang_String_class.getInboundDependencies().size());
240         assertTrue("java.lang.String missing " + _package,
241                    java_lang_String_class.getInboundDependencies().contains(_package));
242         assertTrue("java.lang.String missing " + test_class,
243                    java_lang_String_class.getInboundDependencies().contains(test_class));
244         assertTrue("java.lang.String missing " + test_main_method,
245                    java_lang_String_class.getInboundDependencies().contains(test_main_method));
246     }
247
248     public void testjava_util_package() {
249         assertEquals("java_util_package.Outbound()",
250                      0,
251                      java_util_package.getOutboundDependencies().size());
252         assertEquals("java_util_package.Inbound()",
253                      3,
254                      java_util_package.getInboundDependencies().size());
255         assertTrue("java.util missing " + _package,
256                    java_util_package.getInboundDependencies().contains(_package));
257         assertTrue("java.util missing " + test_class,
258                    java_util_package.getInboundDependencies().contains(test_class));
259         assertTrue("java.util missing " + test_main_method,
260                    java_util_package.getInboundDependencies().contains(test_main_method));
261     }
262
263     public void testjava_util_Collections_class() {
264         assertEquals("java_util_Collections_class.Outbound()",
265                      0,
266                      java_util_Collections_class.getOutboundDependencies().size());
267         assertEquals("java_util_Collections_class.Inbound()",
268                      3,
269                      java_util_Collections_class.getInboundDependencies().size());
270         assertTrue("java.util.Collections missing " + _package,
271                    java_util_Collections_class.getInboundDependencies().contains(_package));
272         assertTrue("java.util.Collections missing " + test_class,
273                    java_util_Collections_class.getInboundDependencies().contains(test_class));
274         assertTrue("java.util.Collections missing " + test_main_method,
275                    java_util_Collections_class.getInboundDependencies().contains(test_main_method));
276     }
277
278     public void testjava_util_Collections_singleton_method() {
279         assertEquals("java_util_Collections_singleton_method.Outbound()",
280                      0,
281                      java_util_Collections_singleton_method.getOutboundDependencies().size());
282         assertEquals("java_util_Collections_singleton_method.Inbound()",
283                      3,
284                      java_util_Collections_singleton_method.getInboundDependencies().size());
285         assertTrue("java.util.Collections.singleton(java.lang.Object) missing " + _package,
286                    java_util_Collections_singleton_method.getInboundDependencies().contains(_package));
287         assertTrue("java.util.Collections.singleton(java.lang.Object) missing " + test_class,
288                    java_util_Collections_singleton_method.getInboundDependencies().contains(test_class));
289         assertTrue("java.util.Collections.singleton(java.lang.Object) missing " + test_main_method,
290                    java_util_Collections_singleton_method.getInboundDependencies().contains(test_main_method));
291     }
292
293     public void testjava_util_Set_class() {
294         assertEquals("java_util_Set_class.Outbound()",
295                      0,
296                      java_util_Set_class.getOutboundDependencies().size());
297         assertEquals("java_util_Set_class.Inbound()",
298                      3,
299                      java_util_Set_class.getInboundDependencies().size());
300         assertTrue("java.util.Set missing " + _package,
301                    java_util_Set_class.getInboundDependencies().contains(_package));
302         assertTrue("java.util.Set missing " + test_class,
303                    java_util_Set_class.getInboundDependencies().contains(test_class));
304         assertTrue("java.util.Set missing " + test_main_method,
305                    java_util_Set_class.getInboundDependencies().contains(test_main_method));
306     }
307 }
308
Popular Tags