KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
36
37 import org.apache.log4j.*;
38
39 public class TestNodeFactory extends TestCase {
40     private NodeFactory factory;
41
42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44
45         Logger.getLogger(getClass()).debug("Begin " + getName());
46         
47         factory = new NodeFactory();
48     }
49
50     protected void tearDown() throws Exception JavaDoc {
51         Logger.getLogger(getClass()).debug("End " + getName());
52
53         super.tearDown();
54     }
55
56     public void testCreatePackage() {
57         PackageNode node = factory.createPackage("a");
58
59         assertEquals("name", "a", node.getName());
60         assertEquals("classes", 0, node.getClasses().size());
61         assertEquals("inbounds", 0, node.getInboundDependencies().size());
62         assertEquals("outbounds", 0, node.getOutboundDependencies().size());
63     }
64
65     public void testLookupPackage() {
66         Node node1 = factory.createPackage("a");
67         Node node2 = factory.createPackage("a");
68
69         assertSame("factory returned different object for same key", node1, node2);
70     }
71
72     public void testCreateClass() {
73         ClassNode node = factory.createClass("a.A");
74
75         assertEquals("name", "a.A", node.getName());
76         assertEquals("package name", "a", node.getPackageNode().getName());
77         assertEquals("features", 0, node.getFeatures().size());
78         assertEquals("inbounds", 0, node.getInboundDependencies().size());
79         assertEquals("outbounds", 0, node.getOutboundDependencies().size());
80     }
81
82     public void testCreateClassInDefaultPackage() {
83         ClassNode node = factory.createClass("A");
84
85         assertEquals("name", "A", node.getName());
86         assertEquals("package name", "", node.getPackageNode().getName());
87     }
88
89     public void testCreateIllegalClass() {
90         ClassNode node = factory.createClass("");
91
92         assertEquals("name", "", node.getName());
93         assertEquals("package name", "", node.getPackageNode().getName());
94     }
95
96     public void testLookupClass() {
97         Node node1 = factory.createClass("a.A");
98         Node node2 = factory.createClass("a.A");
99
100         assertSame("factory returned different object for same key", node1, node2);
101     }
102
103     public void testCreateFeature() {
104         FeatureNode node = factory.createFeature("a.A.a");
105
106         assertEquals("name", "a.A.a", node.getName());
107         assertEquals("class name", "a.A", node.getClassNode().getName());
108         assertEquals("pacakge name", "a", node.getClassNode().getPackageNode().getName());
109         assertEquals("inbounds", 0, node.getInboundDependencies().size());
110         assertEquals("outbounds", 0, node.getOutboundDependencies().size());
111     }
112
113     public void testLookupFeature() {
114         Node node1 = factory.createFeature("a.A.a");
115         Node node2 = factory.createFeature("a.A.a");
116
117         assertSame("factory returned different object for same key", node1, node2);
118     }
119
120     public void testCreateFeatureInDefaultPackage() {
121         FeatureNode node = factory.createFeature("A.a");
122
123         assertEquals("name", "A.a", node.getName());
124         assertEquals("class name", "A", node.getClassNode().getName());
125         assertEquals("package name", "", node.getClassNode().getPackageNode().getName());
126     }
127
128     public void testCreateIllegalFeature() {
129         FeatureNode node = factory.createFeature("");
130
131         assertEquals("name", "", node.getName());
132         assertEquals("class name", "", node.getClassNode().getName());
133         assertEquals("package name", "", node.getClassNode().getPackageNode().getName());
134     }
135
136     public void testCreateReferencedPackageNode() {
137         PackageNode node = factory.createPackage("a", false);
138
139         assertFalse("Not referenced", node.isConfirmed());
140     }
141
142     public void testCreateConcretePackageNode() {
143         PackageNode node = factory.createPackage("a", true);
144
145         assertTrue("Not concrete", node.isConfirmed());
146     }
147
148     public void testCreatePackageNodeDefaultsToReferenced() {
149         PackageNode node = factory.createPackage("a");
150
151         assertFalse("Not referenced", node.isConfirmed());
152     }
153
154     public void testCreateReferencedClassNode() {
155         ClassNode node = factory.createClass("a.A", false);
156
157         assertFalse("Not referenced", node.isConfirmed());
158         assertFalse("Not referenced", node.getPackageNode().isConfirmed());
159     }
160
161     public void testCreateConcreteClassNode() {
162         ClassNode node = factory.createClass("a.A", true);
163
164         assertTrue("Not concrete", node.isConfirmed());
165         assertTrue("Not concrete", node.getPackageNode().isConfirmed());
166     }
167
168     public void testCreateClassNodeDefaultsToReferenced() {
169         ClassNode node = factory.createClass("a.A");
170
171         assertFalse("Not referenced", node.isConfirmed());
172         assertFalse("Not referenced", node.getPackageNode().isConfirmed());
173     }
174
175     public void testCreateReferencedFeatureNode() {
176         FeatureNode node = factory.createFeature("a.A.a", false);
177
178         assertFalse("Not referenced", node.isConfirmed());
179         assertFalse("Not referenced", node.getClassNode().isConfirmed());
180         assertFalse("Not referenced", node.getClassNode().getPackageNode().isConfirmed());
181     }
182
183     public void testCreateConcreteFeatureNode() {
184         FeatureNode node = factory.createFeature("a.A.a", true);
185
186         assertTrue("Not concrete", node.isConfirmed());
187         assertTrue("Not concrete", node.getClassNode().isConfirmed());
188         assertTrue("Not concrete", node.getClassNode().getPackageNode().isConfirmed());
189     }
190
191     public void testCreateFeatureNodeDefaultsToReferenced() {
192         FeatureNode node = factory.createFeature("a.A.a");
193
194         assertFalse("Not referenced", node.isConfirmed());
195         assertFalse("Not referenced", node.getClassNode().isConfirmed());
196         assertFalse("Not referenced", node.getClassNode().getPackageNode().isConfirmed());
197     }
198
199     public void testSwitchPackageNodeFromReferencedToConcrete() {
200         PackageNode node;
201
202         node = factory.createPackage("a", false);
203         assertFalse("Not referenced", node.isConfirmed());
204
205         node = factory.createPackage("a", true);
206         assertTrue("Not concrete", node.isConfirmed());
207     }
208
209     public void testSwitchPackageNodeFromConcreteToReferenced() {
210         PackageNode node;
211
212         node = factory.createPackage("a", true);
213         assertTrue("Not concrete", node.isConfirmed());
214
215         node = factory.createPackage("a", false);
216         assertTrue("Not concrete", node.isConfirmed());
217     }
218
219     public void testMakingPackageNodeConcreteDoesNotChangeItsClasses() {
220         PackageNode node;
221
222         node = factory.createPackage("a", false);
223         factory.createClass("a.A", false);
224         assertFalse("Not referenced", node.isConfirmed());
225         assertFalse("Not referenced", ((Node) node.getClasses().iterator().next()).isConfirmed());
226
227         node = factory.createPackage("a", true);
228         assertTrue("Not concrete", node.isConfirmed());
229         assertFalse("Not referenced", ((Node) node.getClasses().iterator().next()).isConfirmed());
230     }
231
232     public void testSwitchClassNodeFromReferencedToConcrete() {
233         ClassNode node;
234
235         node = factory.createClass("a.A", false);
236         assertFalse("Not referenced", node.isConfirmed());
237         assertFalse("Not referenced", node.getPackageNode().isConfirmed());
238
239         node = factory.createClass("a.A", true);
240         assertTrue("Not concrete", node.isConfirmed());
241         assertTrue("Not concrete", node.getPackageNode().isConfirmed());
242     }
243
244     public void testSwitchClassNodeFromConcreteToReferenced() {
245         ClassNode node;
246
247         node = factory.createClass("a.A", true);
248         assertTrue("Not concrete", node.isConfirmed());
249         assertTrue("Not concrete", node.getPackageNode().isConfirmed());
250
251         node = factory.createClass("a.A", false);
252         assertTrue("Not concrete", node.isConfirmed());
253         assertTrue("Not concrete", node.getPackageNode().isConfirmed());
254     }
255
256     public void testMakingClassNodeConcreteDoesNotChangeItsFeatures() {
257         ClassNode node;
258
259         node = factory.createClass("a.A", false);
260         factory.createFeature("a.A.a", false);
261         assertFalse("Not referenced", node.isConfirmed());
262         assertFalse("Not referenced", ((Node) node.getFeatures().iterator().next()).isConfirmed());
263
264         node = factory.createClass("a.A", true);
265         assertTrue("Not concrete", node.isConfirmed());
266         assertFalse("Not referenced", ((Node) node.getFeatures().iterator().next()).isConfirmed());
267     }
268
269     public void testSwitchFeatureNodeFromReferencedToConcrete() {
270         FeatureNode node;
271
272         node = factory.createFeature("a.A.a", false);
273         assertFalse("Not referenced", node.isConfirmed());
274         assertFalse("Not referenced", node.getClassNode().isConfirmed());
275         assertFalse("Not referenced", node.getClassNode().getPackageNode().isConfirmed());
276
277         node = factory.createFeature("a.A.a", true);
278         assertTrue("Not concrete", node.isConfirmed());
279         assertTrue("Not concrete", node.getClassNode().isConfirmed());
280         assertTrue("Not concrete", node.getClassNode().getPackageNode().isConfirmed());
281     }
282
283     public void testSwitchFeatureNodeFromConcreteToReferenced() {
284         FeatureNode node;
285
286         node = factory.createFeature("a.A.a", true);
287         assertTrue("Not concrete", node.isConfirmed());
288         assertTrue("Not concrete", node.getClassNode().isConfirmed());
289         assertTrue("Not concrete", node.getClassNode().getPackageNode().isConfirmed());
290
291         node = factory.createFeature("a.A.a", false);
292         assertTrue("Not concrete", node.isConfirmed());
293         assertTrue("Not concrete", node.getClassNode().isConfirmed());
294         assertTrue("Not concrete", node.getClassNode().getPackageNode().isConfirmed());
295     }
296 }
297
Popular Tags