KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.jeantessier.classreader.*;
41
42 public class TestCodeDependencyCollector extends TestCase {
43     public static final String JavaDoc TEST_CLASS = "test";
44     public static final String JavaDoc TEST_FILENAME = "classes" + File.separator + "test.class";
45     
46     private NodeFactory factory;
47
48     protected void setUp() throws Exception JavaDoc {
49         factory = new NodeFactory();
50
51         ClassfileLoader loader = new AggregatingClassfileLoader();
52         loader.addLoadListener(new LoadListenerVisitorAdapter(new CodeDependencyCollector(factory)));
53         loader.load(Collections.singleton(TEST_FILENAME));
54     }
55     
56     public void testPackages() {
57         assertEquals("nb packages", 4, factory.getPackages().size());
58
59         Node node;
60
61         node = (Node) factory.getPackages().get("");
62         assertNotNull("default package missing", node);
63         assertTrue("default package not concrete", node.isConfirmed());
64
65         node = (Node) factory.getPackages().get("java.io");
66         assertNotNull("package java.io missing", node);
67         assertFalse("package java.io is concrete", node.isConfirmed());
68
69         node = (Node) factory.getPackages().get("java.lang");
70         assertNotNull("package java.lang missing", node);
71         assertFalse("package java.lang is concrete", node.isConfirmed());
72
73         node = (Node) factory.getPackages().get("java.util");
74         assertNotNull("package java.util missing", node);
75         assertFalse("package java.util is concrete", node.isConfirmed());
76     }
77     
78     public void testClasses() {
79         assertEquals("nb classes", 8, factory.getClasses().size());
80
81         Node node;
82
83         node = (Node) factory.getClasses().get("test");
84         assertNotNull("class test missing", node);
85         assertTrue("class test not concrete", node.isConfirmed());
86
87         node = (Node) factory.getClasses().get("java.io.PrintStream");
88         assertNotNull("class java.io.PrintStream missing", node);
89         assertFalse("class java.io.PrintStream is concrete", node.isConfirmed());
90
91         node = (Node) factory.getClasses().get("java.lang.NullPointerException");
92         assertNotNull("class java.lang.NullPointerException missing", node);
93         assertFalse("class java.lang.NullPointerException is concrete", node.isConfirmed());
94
95         node = (Node) factory.getClasses().get("java.lang.Object");
96         assertNotNull("class java.lang.Object missing", node);
97         assertFalse("class java.lang.Object is concrete", node.isConfirmed());
98
99         node = (Node) factory.getClasses().get("java.lang.String");
100         assertNotNull("class java.lang.String missing", node);
101         assertFalse("class java.lang.String is concrete", node.isConfirmed());
102
103         node = (Node) factory.getClasses().get("java.lang.System");
104         assertNotNull("class java.lang.System missing", node);
105         assertFalse("class java.lang.System is concrete", node.isConfirmed());
106
107         node = (Node) factory.getClasses().get("java.util.Collections");
108         assertNotNull("class java.util.Collections missing", node);
109         assertFalse("class java.util.Collections is concrete", node.isConfirmed());
110
111         node = (Node) factory.getClasses().get("java.util.Set");
112         assertNotNull("class java.util.Set missing", node);
113         assertFalse("class java.util.Set is concrete", node.isConfirmed());
114     }
115     
116     public void testFeatures() {
117         assertEquals("nb features", 6, factory.getFeatures().size());
118
119         Node node;
120
121         node = (Node) factory.getFeatures().get("test.main(java.lang.String[])");
122         assertNotNull("feature test.main(java.lang.String[]) missing", node);
123         assertTrue("feature test.main(java.lang.String[]) not concrete", node.isConfirmed());
124
125         node = (Node) factory.getFeatures().get("test.test()");
126         assertNotNull("feature test.test() missing", node);
127         assertTrue("feature test.test() not concrete", node.isConfirmed());
128
129         node = (Node) factory.getFeatures().get("java.io.PrintStream.println(java.lang.Object)");
130         assertNotNull("feature java.io.PrintStream.println(java.lang.Object) missing", node);
131         assertFalse("feature java.io.PrintStream.println(java.lang.Object) is concrete", node.isConfirmed());
132
133         node = (Node) factory.getFeatures().get("java.lang.Object.Object()");
134         assertNotNull("feature java.lang.Object.Object() missing", node);
135         assertFalse("feature java.lang.Object.Object() is concrete", node.isConfirmed());
136
137         node = (Node) factory.getFeatures().get("java.lang.System.out");
138         assertNotNull("feature java.lang.System.out missing", node);
139         assertFalse("feature java.lang.System.out is concrete", node.isConfirmed());
140
141         node = (Node) factory.getFeatures().get("java.util.Collections.singleton(java.lang.Object)");
142         assertNotNull("feature java.util.Collections.singleton(java.lang.Object) missing", node);
143         assertFalse("feature java.util.Collections.singleton(java.lang.Object) is concrete", node.isConfirmed());
144     }
145 }
146
Popular Tags