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 TestCodeDependencyCollectorWithFiltering 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: RegularExpressionSelectionCriteria filterCriteria = new RegularExpressionSelectionCriteria(
053: "//");
054: filterCriteria.setGlobalExcludes("/java.lang/");
055:
056: ClassfileLoader loader = new AggregatingClassfileLoader();
057: loader.addLoadListener(new LoadListenerVisitorAdapter(
058: new CodeDependencyCollector(factory, filterCriteria)));
059: loader.load(Collections.singleton(TEST_FILENAME));
060: }
061:
062: public void testPackages() {
063: assertEquals("nb packages", 3, factory.getPackages().size());
064:
065: Node node;
066:
067: node = (Node) factory.getPackages().get("");
068: assertNotNull("default package missing", node);
069: assertTrue("default package not concrete", node.isConfirmed());
070:
071: node = (Node) factory.getPackages().get("java.io");
072: assertNotNull("package java.io missing", node);
073: assertFalse("package java.io 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", 3, 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("java.util.Set");
095: assertNotNull("class java.util.Set missing", node);
096: assertFalse("class java.util.Set is concrete", node
097: .isConfirmed());
098: }
099:
100: public void testFeatures() {
101: assertEquals("nb features", 2, factory.getFeatures().size());
102:
103: Node node;
104:
105: node = (Node) factory.getFeatures().get(
106: "test.main(java.lang.String[])");
107: assertNotNull("feature test.main(java.lang.String[]) missing",
108: node);
109: assertTrue(
110: "feature test.main(java.lang.String[]) not concrete",
111: node.isConfirmed());
112:
113: node = (Node) factory.getFeatures().get("test.test()");
114: assertNotNull("feature test.test() missing", node);
115: assertTrue("feature test.test() not concrete", node
116: .isConfirmed());
117: }
118: }
|