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 TestClosureStopSelector extends TestCase {
043: private NodeFactory factory;
044:
045: private PackageNode a;
046: private ClassNode a_A;
047: private FeatureNode a_A_a;
048:
049: private PackageNode b;
050: private ClassNode b_B;
051: private FeatureNode b_B_b;
052:
053: private PackageNode c;
054: private ClassNode c_C;
055: private FeatureNode c_C_c;
056:
057: protected void setUp() throws Exception {
058: factory = new NodeFactory();
059:
060: a = factory.createPackage("a");
061: a_A = factory.createClass("a.A");
062: a_A_a = factory.createFeature("a.A.a");
063:
064: b = factory.createPackage("b");
065: b_B = factory.createClass("b.B");
066: b_B_b = factory.createFeature("b.B.b");
067:
068: c = factory.createPackage("c");
069: c_C = factory.createClass("c.C");
070: c_C_c = factory.createFeature("c.C.c");
071:
072: a_A_a.addDependency(b_B_b);
073: b_B_b.addDependency(c_C_c);
074: }
075:
076: public void testEmpty() {
077: RegularExpressionSelectionCriteria localCriteria = new RegularExpressionSelectionCriteria();
078: localCriteria.setGlobalIncludes("/b.B.b/");
079:
080: ClosureStopSelector selector = new ClosureStopSelector(
081: localCriteria);
082: selector.traverseNodes(Collections.EMPTY_SET);
083:
084: assertTrue("Failed to recognize empty collection", selector
085: .isDone());
086: }
087:
088: public void testPositive() {
089: RegularExpressionSelectionCriteria localCriteria = new RegularExpressionSelectionCriteria();
090: localCriteria.setGlobalIncludes("/b.B.b/");
091:
092: ClosureStopSelector selector = new ClosureStopSelector(
093: localCriteria);
094: selector.traverseNodes(Collections.singleton(b_B_b));
095:
096: assertTrue("Failed to recognize target", selector.isDone());
097: }
098:
099: public void testNegative() {
100: RegularExpressionSelectionCriteria localCriteria = new RegularExpressionSelectionCriteria();
101: localCriteria.setGlobalIncludes("/b.B.b/");
102:
103: ClosureStopSelector selector = new ClosureStopSelector(
104: localCriteria);
105: selector.traverseNodes(Collections.singleton(a_A_a));
106:
107: assertFalse("Failed to ignore non-target", selector.isDone());
108: }
109:
110: public void testMultiple() {
111: RegularExpressionSelectionCriteria localCriteria = new RegularExpressionSelectionCriteria();
112: localCriteria.setGlobalIncludes("/b.B.b/");
113:
114: Collection targets = new ArrayList();
115: targets.add(a_A_a);
116: targets.add(b_B_b);
117:
118: ClosureStopSelector selector = new ClosureStopSelector(
119: localCriteria);
120: selector.traverseNodes(targets);
121:
122: assertTrue("Failed to recognize target", selector.isDone());
123: }
124: }
|