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.dependency;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: import org.apache.oro.text.perl.*;
041:
042: public class TestLinkMaximizer extends TestCase {
043: NodeFactory factory;
044:
045: Node _package;
046: Node test_class;
047: Node test_main_method;
048: Node test_test_method;
049:
050: Node java_lang_package;
051: Node java_lang_Object_class;
052: Node java_lang_Object_Object_method;
053: Node java_lang_String_class;
054:
055: Node java_util_package;
056: Node java_util_Collections_class;
057: Node java_util_Collections_singleton_method;
058: Node java_util_Set_class;
059:
060: LinkMaximizer visitor;
061:
062: protected void setUp() throws Exception {
063: factory = new NodeFactory();
064:
065: _package = factory.createPackage("");
066: test_class = factory.createClass("test");
067: test_main_method = factory.createFeature("test.main(String[])");
068: test_test_method = factory.createFeature("test.test()");
069:
070: java_lang_package = factory.createPackage("java.lang");
071: java_lang_Object_class = factory
072: .createClass("java.lang.Object");
073: java_lang_Object_Object_method = factory
074: .createFeature("java.lang.Object.Object()");
075: java_lang_String_class = factory
076: .createClass("java.lang.String");
077:
078: java_util_package = factory.createPackage("java.util");
079: java_util_Collections_class = factory
080: .createClass("java.util.Collections");
081: java_util_Collections_singleton_method = factory
082: .createFeature("java.util.Collections.singleton(java.lang.Object)");
083: java_util_Set_class = factory.createClass("java.util.Set");
084:
085: test_class.addDependency(java_lang_Object_class);
086: test_main_method.addDependency(java_lang_Object_class);
087: test_main_method.addDependency(java_lang_Object_Object_method);
088: test_main_method.addDependency(java_lang_String_class);
089: test_main_method
090: .addDependency(java_util_Collections_singleton_method);
091: test_main_method.addDependency(java_util_Set_class);
092: test_test_method.addDependency(java_lang_Object_Object_method);
093:
094: visitor = new LinkMaximizer();
095: visitor.traverseNodes(factory.getPackages().values());
096: }
097:
098: public void test_package() {
099: assertEquals("_package.Outbound()", 8, _package
100: .getOutboundDependencies().size());
101: assertTrue("default missing " + java_lang_package, _package
102: .getOutboundDependencies().contains(java_lang_package));
103: assertTrue("default missing " + java_lang_Object_class,
104: _package.getOutboundDependencies().contains(
105: java_lang_Object_class));
106: assertTrue("default missing " + java_lang_Object_Object_method,
107: _package.getOutboundDependencies().contains(
108: java_lang_Object_Object_method));
109: assertTrue("default missing " + java_lang_String_class,
110: _package.getOutboundDependencies().contains(
111: java_lang_String_class));
112: assertTrue("default missing " + java_util_package, _package
113: .getOutboundDependencies().contains(java_util_package));
114: assertTrue("default missing " + java_util_Collections_class,
115: _package.getOutboundDependencies().contains(
116: java_util_Collections_class));
117: assertTrue("default missing "
118: + java_util_Collections_singleton_method, _package
119: .getOutboundDependencies().contains(
120: java_util_Collections_singleton_method));
121: assertTrue("default missing " + java_util_Set_class, _package
122: .getOutboundDependencies()
123: .contains(java_util_Set_class));
124: assertEquals("_package.Inbound()", 0, _package
125: .getInboundDependencies().size());
126: }
127:
128: public void testtest_class() {
129: assertEquals("test_class.Outbound()", 8, test_class
130: .getOutboundDependencies().size());
131: assertTrue("test missing " + java_lang_package, test_class
132: .getOutboundDependencies().contains(java_lang_package));
133: assertTrue("test missing " + java_lang_Object_class, test_class
134: .getOutboundDependencies().contains(
135: java_lang_Object_class));
136: assertTrue("test missing " + java_lang_Object_Object_method,
137: test_class.getOutboundDependencies().contains(
138: java_lang_Object_Object_method));
139: assertTrue("test missing " + java_lang_String_class, test_class
140: .getOutboundDependencies().contains(
141: java_lang_String_class));
142: assertTrue("test missing " + java_util_package, test_class
143: .getOutboundDependencies().contains(java_util_package));
144: assertTrue("test missing " + java_util_Collections_class,
145: test_class.getOutboundDependencies().contains(
146: java_util_Collections_class));
147: assertTrue("test missing "
148: + java_util_Collections_singleton_method, test_class
149: .getOutboundDependencies().contains(
150: java_util_Collections_singleton_method));
151: assertTrue("test missing " + java_util_Set_class, test_class
152: .getOutboundDependencies()
153: .contains(java_util_Set_class));
154: assertEquals("test_class.Inbound()", 0, test_class
155: .getInboundDependencies().size());
156: }
157:
158: public void testtest_main_method() {
159: assertEquals("test_main_method.Outbound()", 8, test_main_method
160: .getOutboundDependencies().size());
161: assertTrue("test.main(java.lang.String[]) missing "
162: + java_lang_package, test_main_method
163: .getOutboundDependencies().contains(java_lang_package));
164: assertTrue("test.main(java.lang.String[]) missing "
165: + java_lang_Object_class, test_main_method
166: .getOutboundDependencies().contains(
167: java_lang_Object_class));
168: assertTrue("test.main(java.lang.String[]) missing "
169: + java_lang_Object_Object_method, test_main_method
170: .getOutboundDependencies().contains(
171: java_lang_Object_Object_method));
172: assertTrue("test.main(java.lang.String[]) missing "
173: + java_lang_String_class, test_main_method
174: .getOutboundDependencies().contains(
175: java_lang_String_class));
176: assertTrue("test.main(java.lang.String[]) missing "
177: + java_util_package, test_main_method
178: .getOutboundDependencies().contains(java_util_package));
179: assertTrue("test.main(java.lang.String[]) missing "
180: + java_util_Collections_class, test_main_method
181: .getOutboundDependencies().contains(
182: java_util_Collections_class));
183: assertTrue("test.main(java.lang.String[]) missing "
184: + java_util_Collections_singleton_method,
185: test_main_method.getOutboundDependencies().contains(
186: java_util_Collections_singleton_method));
187: assertTrue("test.main(java.lang.String[]) missing "
188: + java_util_Set_class, test_main_method
189: .getOutboundDependencies()
190: .contains(java_util_Set_class));
191: assertEquals("test_main_method.Inbound()", 0, test_main_method
192: .getInboundDependencies().size());
193: }
194:
195: public void testtest_test_method() {
196: assertEquals("test_test_method.Outbound()", 3, test_test_method
197: .getOutboundDependencies().size());
198: assertTrue("test.test() missing " + java_lang_package,
199: test_test_method.getOutboundDependencies().contains(
200: java_lang_package));
201: assertTrue("test.test() missing " + java_lang_Object_class,
202: test_test_method.getOutboundDependencies().contains(
203: java_lang_Object_class));
204: assertTrue("test.test() missing "
205: + java_lang_Object_Object_method, test_test_method
206: .getOutboundDependencies().contains(
207: java_lang_Object_Object_method));
208: assertEquals("_package.Inbound()", 0, test_test_method
209: .getInboundDependencies().size());
210: }
211:
212: public void testjava_lang_package() {
213: assertEquals("java_lang_package.Outbound()", 0,
214: java_lang_package.getOutboundDependencies().size());
215: assertEquals("java_lang_package.Inbound()", 4,
216: java_lang_package.getInboundDependencies().size());
217: assertTrue("java.lang missing " + _package, java_lang_package
218: .getInboundDependencies().contains(_package));
219: assertTrue("java.lang missing " + test_class, java_lang_package
220: .getInboundDependencies().contains(test_class));
221: assertTrue("java.lang missing " + test_main_method,
222: java_lang_package.getInboundDependencies().contains(
223: test_main_method));
224: assertTrue("java.lang missing " + test_test_method,
225: java_lang_package.getInboundDependencies().contains(
226: test_test_method));
227: }
228:
229: public void testjava_lang_Object_class() {
230: assertEquals("java_lang_Object_class.Outbound()", 0,
231: java_lang_Object_class.getOutboundDependencies().size());
232: assertEquals("java_lang_Object_class.Inbound()", 4,
233: java_lang_Object_class.getInboundDependencies().size());
234: assertTrue("java.lang.Object missing " + _package,
235: java_lang_Object_class.getInboundDependencies()
236: .contains(_package));
237: assertTrue("java.lang.Object missing " + test_class,
238: java_lang_Object_class.getInboundDependencies()
239: .contains(test_class));
240: assertTrue("java.lang.Object missing " + test_main_method,
241: java_lang_Object_class.getInboundDependencies()
242: .contains(test_main_method));
243: assertTrue("java.lang.Object missing " + test_test_method,
244: java_lang_Object_class.getInboundDependencies()
245: .contains(test_test_method));
246: }
247:
248: public void testjava_lang_Object_Object_method() {
249: assertEquals("java_lang_Object_Object_method.Outbound()", 0,
250: java_lang_Object_Object_method
251: .getOutboundDependencies().size());
252: assertEquals("java_lang_Object_Object_method.Inbound()", 4,
253: java_lang_Object_Object_method.getInboundDependencies()
254: .size());
255: assertTrue("java.lang.Object.Object() missing " + _package,
256: java_lang_Object_Object_method.getInboundDependencies()
257: .contains(_package));
258: assertTrue("java.lang.Object.Object() missing " + test_class,
259: java_lang_Object_Object_method.getInboundDependencies()
260: .contains(test_class));
261: assertTrue("java.lang.Object.Object() missing "
262: + test_main_method, java_lang_Object_Object_method
263: .getInboundDependencies().contains(test_main_method));
264: assertTrue("java.lang.Object.Object() missing "
265: + test_test_method, java_lang_Object_Object_method
266: .getInboundDependencies().contains(test_test_method));
267: }
268:
269: public void testjava_lang_String_class() {
270: assertEquals("java_lang_String_class.Outbound()", 0,
271: java_lang_String_class.getOutboundDependencies().size());
272: assertEquals("java_lang_String_class.Inbound()", 3,
273: java_lang_String_class.getInboundDependencies().size());
274: assertTrue("java.lang.String missing " + _package,
275: java_lang_String_class.getInboundDependencies()
276: .contains(_package));
277: assertTrue("java.lang.String missing " + test_class,
278: java_lang_String_class.getInboundDependencies()
279: .contains(test_class));
280: assertTrue("java.lang.String missing " + test_main_method,
281: java_lang_String_class.getInboundDependencies()
282: .contains(test_main_method));
283: }
284:
285: public void testjava_util_package() {
286: assertEquals("java_util_package.Outbound()", 0,
287: java_util_package.getOutboundDependencies().size());
288: assertEquals("java_util_package.Inbound()", 3,
289: java_util_package.getInboundDependencies().size());
290: assertTrue("java.util missing " + _package, java_util_package
291: .getInboundDependencies().contains(_package));
292: assertTrue("java.util missing " + test_class, java_util_package
293: .getInboundDependencies().contains(test_class));
294: assertTrue("java.util missing " + test_main_method,
295: java_util_package.getInboundDependencies().contains(
296: test_main_method));
297: }
298:
299: public void testjava_util_Collections_class() {
300: assertEquals("java_util_Collections_class.Outbound()", 0,
301: java_util_Collections_class.getOutboundDependencies()
302: .size());
303: assertEquals("java_util_Collections_class.Inbound()", 3,
304: java_util_Collections_class.getInboundDependencies()
305: .size());
306: assertTrue("java.util.Collections missing " + _package,
307: java_util_Collections_class.getInboundDependencies()
308: .contains(_package));
309: assertTrue("java.util.Collections missing " + test_class,
310: java_util_Collections_class.getInboundDependencies()
311: .contains(test_class));
312: assertTrue("java.util.Collections missing " + test_main_method,
313: java_util_Collections_class.getInboundDependencies()
314: .contains(test_main_method));
315: }
316:
317: public void testjava_util_Collections_singleton_method() {
318: assertEquals(
319: "java_util_Collections_singleton_method.Outbound()", 0,
320: java_util_Collections_singleton_method
321: .getOutboundDependencies().size());
322: assertEquals(
323: "java_util_Collections_singleton_method.Inbound()", 3,
324: java_util_Collections_singleton_method
325: .getInboundDependencies().size());
326: assertTrue(
327: "java.util.Collections.singleton(java.lang.Object) missing "
328: + _package,
329: java_util_Collections_singleton_method
330: .getInboundDependencies().contains(_package));
331: assertTrue(
332: "java.util.Collections.singleton(java.lang.Object) missing "
333: + test_class,
334: java_util_Collections_singleton_method
335: .getInboundDependencies().contains(test_class));
336: assertTrue(
337: "java.util.Collections.singleton(java.lang.Object) missing "
338: + test_main_method,
339: java_util_Collections_singleton_method
340: .getInboundDependencies().contains(
341: test_main_method));
342: }
343:
344: public void testjava_util_Set_class() {
345: assertEquals("java_util_Set_class.Outbound()", 0,
346: java_util_Set_class.getOutboundDependencies().size());
347: assertEquals("java_util_Set_class.Inbound()", 3,
348: java_util_Set_class.getInboundDependencies().size());
349: assertTrue("java.util.Set missing " + _package,
350: java_util_Set_class.getInboundDependencies().contains(
351: _package));
352: assertTrue("java.util.Set missing " + test_class,
353: java_util_Set_class.getInboundDependencies().contains(
354: test_class));
355: assertTrue("java.util.Set missing " + test_main_method,
356: java_util_Set_class.getInboundDependencies().contains(
357: test_main_method));
358: }
359: }
|