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 TestLinkMinimizer 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: LinkMinimizer 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 LinkMinimizer();
095: visitor.traverseNodes(factory.getPackages().values());
096: }
097:
098: public void test_package() {
099: assertEquals("_package.Outbound()", 0, _package
100: .getOutboundDependencies().size());
101: assertEquals("_package.Inbound()", 0, _package
102: .getInboundDependencies().size());
103: }
104:
105: public void testtest_class() {
106: assertEquals("test_class.Outbound()", 0, test_class
107: .getOutboundDependencies().size());
108: assertEquals("test_class.Inbound()", 0, test_class
109: .getInboundDependencies().size());
110: }
111:
112: public void testtest_main_method() {
113: assertEquals("test_main_method.Outbound()", 4, test_main_method
114: .getOutboundDependencies().size());
115: assertTrue("test.main(java.lang.String[]) missing "
116: + java_lang_Object_Object_method, test_main_method
117: .getOutboundDependencies().contains(
118: java_lang_Object_Object_method));
119: assertTrue("test.main(java.lang.String[]) missing "
120: + java_lang_String_class, test_main_method
121: .getOutboundDependencies().contains(
122: java_lang_String_class));
123: assertTrue("test.main(java.lang.String[]) missing "
124: + java_util_Collections_singleton_method,
125: test_main_method.getOutboundDependencies().contains(
126: java_util_Collections_singleton_method));
127: assertTrue("test.main(java.lang.String[]) missing "
128: + java_util_Set_class, test_main_method
129: .getOutboundDependencies()
130: .contains(java_util_Set_class));
131: assertEquals("test_main_method.Inbound()", 0, test_main_method
132: .getInboundDependencies().size());
133: }
134:
135: public void testtest_test_method() {
136: assertEquals("test_test_method.Outbound()", 1, test_test_method
137: .getOutboundDependencies().size());
138: assertTrue("test.test() missing "
139: + java_lang_Object_Object_method, test_test_method
140: .getOutboundDependencies().contains(
141: java_lang_Object_Object_method));
142: assertEquals("_package.Inbound()", 0, test_test_method
143: .getInboundDependencies().size());
144: }
145:
146: public void testjava_lang_package() {
147: assertEquals("java_lang_package.Outbound()", 0,
148: java_lang_package.getOutboundDependencies().size());
149: assertEquals("java_lang_package.Inbound()", 0,
150: java_lang_package.getInboundDependencies().size());
151: }
152:
153: public void testjava_lang_Object_class() {
154: assertEquals("java_lang_Object_class.Outbound()", 0,
155: java_lang_Object_class.getOutboundDependencies().size());
156: assertEquals("java_lang_Object_class.Inbound()", 0,
157: java_lang_Object_class.getInboundDependencies().size());
158: }
159:
160: public void testjava_lang_Object_Object_method() {
161: assertEquals("java_lang_Object_Object_method.Outbound()", 0,
162: java_lang_Object_Object_method
163: .getOutboundDependencies().size());
164: assertEquals("java_lang_Object_Object_method.Inbound()", 2,
165: java_lang_Object_Object_method.getInboundDependencies()
166: .size());
167: assertTrue("java.lang.Object.Object() missing "
168: + test_main_method, java_lang_Object_Object_method
169: .getInboundDependencies().contains(test_main_method));
170: assertTrue("java.lang.Object.Object() missing "
171: + test_test_method, java_lang_Object_Object_method
172: .getInboundDependencies().contains(test_test_method));
173: }
174:
175: public void testjava_lang_String_class() {
176: assertEquals("java_lang_String_class.Outbound()", 0,
177: java_lang_String_class.getOutboundDependencies().size());
178: assertEquals("java_lang_String_class.Inbound()", 1,
179: java_lang_String_class.getInboundDependencies().size());
180: assertTrue("java.lang.String missing " + test_main_method,
181: java_lang_String_class.getInboundDependencies()
182: .contains(test_main_method));
183: }
184:
185: public void testjava_util_package() {
186: assertEquals("java_util_package.Outbound()", 0,
187: java_util_package.getOutboundDependencies().size());
188: assertEquals("java_util_package.Inbound()", 0,
189: java_util_package.getInboundDependencies().size());
190: }
191:
192: public void testjava_util_Collections_class() {
193: assertEquals("java_util_Collections_class.Outbound()", 0,
194: java_util_Collections_class.getOutboundDependencies()
195: .size());
196: assertEquals("java_util_Collections_class.Inbound()", 0,
197: java_util_Collections_class.getInboundDependencies()
198: .size());
199: }
200:
201: public void testjava_util_Collections_singleton_method() {
202: assertEquals(
203: "java_util_Collections_singleton_method.Outbound()", 0,
204: java_util_Collections_singleton_method
205: .getOutboundDependencies().size());
206: assertEquals(
207: "java_util_Collections_singleton_method.Inbound()", 1,
208: java_util_Collections_singleton_method
209: .getInboundDependencies().size());
210: assertTrue(
211: "java.util.Collections.singleton(java.lang.Object) missing "
212: + test_main_method,
213: java_util_Collections_singleton_method
214: .getInboundDependencies().contains(
215: test_main_method));
216: }
217:
218: public void testjava_util_Set_class() {
219: assertEquals("java_util_Set_class.Outbound()", 0,
220: java_util_Set_class.getOutboundDependencies().size());
221: assertEquals("java_util_Set_class.Inbound()", 1,
222: java_util_Set_class.getInboundDependencies().size());
223: assertTrue("java.util.Set missing " + test_main_method,
224: java_util_Set_class.getInboundDependencies().contains(
225: test_main_method));
226: }
227: }
|