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.util.*;
036:
037: import junit.framework.*;
038:
039: public class TestCollectionSelectionCriteria extends TestCase {
040: private Collection include;
041: private Collection exclude;
042: private CollectionSelectionCriteria criteria;
043:
044: private PackageNode a;
045: private ClassNode a_A;
046: private FeatureNode a_A_a;
047:
048: private PackageNode b;
049: private ClassNode b_B;
050: private FeatureNode b_B_b;
051:
052: protected void setUp() throws Exception {
053: include = new HashSet();
054: exclude = new HashSet();
055: criteria = new CollectionSelectionCriteria(include, exclude);
056:
057: NodeFactory factory = new NodeFactory();
058:
059: a = factory.createPackage("a");
060: a_A = factory.createClass("a.A");
061: a_A_a = factory.createFeature("a.A.a");
062:
063: b = factory.createPackage("b");
064: b_B = factory.createClass("b.B");
065: b_B_b = factory.createFeature("b.B.b");
066: }
067:
068: public void testEmptyInclude() {
069: assertFalse("a", criteria.matches(a));
070: assertFalse("a.A", criteria.matches(a_A));
071: assertFalse("a.A.a", criteria.matches(a_A_a));
072:
073: assertFalse("b", criteria.matches(b));
074: assertFalse("b.B", criteria.matches(b_B));
075: assertFalse("b.B.b", criteria.matches(b_B_b));
076: }
077:
078: public void testNullInclude() {
079: criteria = new CollectionSelectionCriteria(null, exclude);
080:
081: assertTrue("a", criteria.matches(a));
082: assertTrue("a.A", criteria.matches(a_A));
083: assertTrue("a.A.a", criteria.matches(a_A_a));
084:
085: assertTrue("b", criteria.matches(b));
086: assertTrue("b.B", criteria.matches(b_B));
087: assertTrue("b.B.b", criteria.matches(b_B_b));
088: }
089:
090: public void testMatchPackageNode() {
091: include.add("a");
092:
093: assertTrue("a", criteria.matches(a));
094: assertFalse("a.A", criteria.matches(a_A));
095: assertFalse("a.A.a", criteria.matches(a_A_a));
096:
097: assertFalse("b", criteria.matches(b));
098: assertFalse("b.B", criteria.matches(b_B));
099: assertFalse("b.B.b", criteria.matches(b_B_b));
100: }
101:
102: public void testMatchClassNode() {
103: include.add("a.A");
104:
105: assertFalse("a", criteria.matches(a));
106: assertTrue("a.A", criteria.matches(a_A));
107: assertFalse("a.A.a", criteria.matches(a_A_a));
108:
109: assertFalse("b", criteria.matches(b));
110: assertFalse("b.B", criteria.matches(b_B));
111: assertFalse("b.B.b", criteria.matches(b_B_b));
112: }
113:
114: public void testMatchFeatureNode() {
115: include.add("a.A.a");
116:
117: assertFalse("a", criteria.matches(a));
118: assertFalse("a.A", criteria.matches(a_A));
119: assertTrue("a.A.a", criteria.matches(a_A_a));
120:
121: assertFalse("b", criteria.matches(b));
122: assertFalse("b.B", criteria.matches(b_B));
123: assertFalse("b.B.b", criteria.matches(b_B_b));
124: }
125:
126: public void testMatchPackageName() {
127: include.add("a");
128:
129: assertTrue("a", criteria.matchesPackageName("a"));
130: assertFalse("a.A", criteria.matchesClassName("a.A"));
131: assertFalse("a.A.a", criteria.matchesFeatureName("a.A.a"));
132:
133: assertFalse("b", criteria.matchesPackageName("b"));
134: assertFalse("b.B", criteria.matchesClassName("b.B"));
135: assertFalse("b.B.b", criteria.matchesFeatureName("b.B.b"));
136: }
137:
138: public void testMatchClassName() {
139: include.add("a.A");
140:
141: assertFalse("a", criteria.matchesPackageName("a"));
142: assertTrue("a.A", criteria.matchesClassName("a.A"));
143: assertFalse("a.A.a", criteria.matchesFeatureName("a.A.a"));
144:
145: assertFalse("b", criteria.matchesPackageName("b"));
146: assertFalse("b.B", criteria.matchesClassName("b.B"));
147: assertFalse("b.B.b", criteria.matchesFeatureName("b.B.b"));
148: }
149:
150: public void testMatchFeatureName() {
151: include.add("a.A.a");
152:
153: assertFalse("a", criteria.matchesPackageName("a"));
154: assertFalse("a.A", criteria.matchesClassName("a.A"));
155: assertTrue("a.A.a", criteria.matchesFeatureName("a.A.a"));
156:
157: assertFalse("b", criteria.matchesPackageName("b"));
158: assertFalse("b.B", criteria.matchesClassName("b.B"));
159: assertFalse("b.B.b", criteria.matchesFeatureName("b.B.b"));
160: }
161:
162: public void testExclude() {
163: include.add("a");
164: include.add("a.A");
165: include.add("a.A.a");
166: exclude.add("a.A.a");
167:
168: assertTrue("a", criteria.matches(a));
169: assertTrue("a.A", criteria.matches(a_A));
170: assertFalse("a.A.a", criteria.matches(a_A_a));
171: }
172:
173: public void testExcludeOnly() {
174: exclude.add("a.A.a");
175:
176: criteria = new CollectionSelectionCriteria(null, exclude);
177:
178: assertTrue("a", criteria.matches(a));
179: assertTrue("a.A", criteria.matches(a_A));
180: assertFalse("a.A.a", criteria.matches(a_A_a));
181: }
182: }
|