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 com.jeantessier.classreader.*;
041:
042: public class TestCodeDependencyCollector extends TestCase {
043: public static final String TEST_CLASS = "test";
044: public static final String TEST_FILENAME = "classes"
045: + File.separator + "test.class";
046:
047: private NodeFactory factory;
048:
049: protected void setUp() throws Exception {
050: factory = new NodeFactory();
051:
052: ClassfileLoader loader = new AggregatingClassfileLoader();
053: loader.addLoadListener(new LoadListenerVisitorAdapter(
054: new CodeDependencyCollector(factory)));
055: loader.load(Collections.singleton(TEST_FILENAME));
056: }
057:
058: public void testPackages() {
059: assertEquals("nb packages", 4, factory.getPackages().size());
060:
061: Node node;
062:
063: node = (Node) factory.getPackages().get("");
064: assertNotNull("default package missing", node);
065: assertTrue("default package not concrete", node.isConfirmed());
066:
067: node = (Node) factory.getPackages().get("java.io");
068: assertNotNull("package java.io missing", node);
069: assertFalse("package java.io is concrete", node.isConfirmed());
070:
071: node = (Node) factory.getPackages().get("java.lang");
072: assertNotNull("package java.lang missing", node);
073: assertFalse("package java.lang is concrete", node.isConfirmed());
074:
075: node = (Node) factory.getPackages().get("java.util");
076: assertNotNull("package java.util missing", node);
077: assertFalse("package java.util is concrete", node.isConfirmed());
078: }
079:
080: public void testClasses() {
081: assertEquals("nb classes", 8, factory.getClasses().size());
082:
083: Node node;
084:
085: node = (Node) factory.getClasses().get("test");
086: assertNotNull("class test missing", node);
087: assertTrue("class test not concrete", node.isConfirmed());
088:
089: node = (Node) factory.getClasses().get("java.io.PrintStream");
090: assertNotNull("class java.io.PrintStream missing", node);
091: assertFalse("class java.io.PrintStream is concrete", node
092: .isConfirmed());
093:
094: node = (Node) factory.getClasses().get(
095: "java.lang.NullPointerException");
096: assertNotNull("class java.lang.NullPointerException missing",
097: node);
098: assertFalse("class java.lang.NullPointerException is concrete",
099: node.isConfirmed());
100:
101: node = (Node) factory.getClasses().get("java.lang.Object");
102: assertNotNull("class java.lang.Object missing", node);
103: assertFalse("class java.lang.Object is concrete", node
104: .isConfirmed());
105:
106: node = (Node) factory.getClasses().get("java.lang.String");
107: assertNotNull("class java.lang.String missing", node);
108: assertFalse("class java.lang.String is concrete", node
109: .isConfirmed());
110:
111: node = (Node) factory.getClasses().get("java.lang.System");
112: assertNotNull("class java.lang.System missing", node);
113: assertFalse("class java.lang.System is concrete", node
114: .isConfirmed());
115:
116: node = (Node) factory.getClasses().get("java.util.Collections");
117: assertNotNull("class java.util.Collections missing", node);
118: assertFalse("class java.util.Collections is concrete", node
119: .isConfirmed());
120:
121: node = (Node) factory.getClasses().get("java.util.Set");
122: assertNotNull("class java.util.Set missing", node);
123: assertFalse("class java.util.Set is concrete", node
124: .isConfirmed());
125: }
126:
127: public void testFeatures() {
128: assertEquals("nb features", 6, factory.getFeatures().size());
129:
130: Node node;
131:
132: node = (Node) factory.getFeatures().get(
133: "test.main(java.lang.String[])");
134: assertNotNull("feature test.main(java.lang.String[]) missing",
135: node);
136: assertTrue(
137: "feature test.main(java.lang.String[]) not concrete",
138: node.isConfirmed());
139:
140: node = (Node) factory.getFeatures().get("test.test()");
141: assertNotNull("feature test.test() missing", node);
142: assertTrue("feature test.test() not concrete", node
143: .isConfirmed());
144:
145: node = (Node) factory.getFeatures().get(
146: "java.io.PrintStream.println(java.lang.Object)");
147: assertNotNull(
148: "feature java.io.PrintStream.println(java.lang.Object) missing",
149: node);
150: assertFalse(
151: "feature java.io.PrintStream.println(java.lang.Object) is concrete",
152: node.isConfirmed());
153:
154: node = (Node) factory.getFeatures().get(
155: "java.lang.Object.Object()");
156: assertNotNull("feature java.lang.Object.Object() missing", node);
157: assertFalse("feature java.lang.Object.Object() is concrete",
158: node.isConfirmed());
159:
160: node = (Node) factory.getFeatures().get("java.lang.System.out");
161: assertNotNull("feature java.lang.System.out missing", node);
162: assertFalse("feature java.lang.System.out is concrete", node
163: .isConfirmed());
164:
165: node = (Node) factory.getFeatures().get(
166: "java.util.Collections.singleton(java.lang.Object)");
167: assertNotNull(
168: "feature java.util.Collections.singleton(java.lang.Object) missing",
169: node);
170: assertFalse(
171: "feature java.util.Collections.singleton(java.lang.Object) is concrete",
172: node.isConfirmed());
173: }
174: }
|