KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
36
37 import junit.framework.*;
38
39 public class TestCollectionSelectionCriteria extends TestCase {
40     private Collection include;
41     private Collection exclude;
42     private CollectionSelectionCriteria criteria;
43
44     private PackageNode a;
45     private ClassNode a_A;
46     private FeatureNode a_A_a;
47     
48     private PackageNode b;
49     private ClassNode b_B;
50     private FeatureNode b_B_b;
51
52     protected void setUp() throws Exception JavaDoc {
53         include = new HashSet();
54         exclude = new HashSet();
55         criteria = new CollectionSelectionCriteria(include, exclude);
56
57         NodeFactory factory = new NodeFactory();
58
59         a = factory.createPackage("a");
60         a_A = factory.createClass("a.A");
61         a_A_a = factory.createFeature("a.A.a");
62         
63         b = factory.createPackage("b");
64         b_B = factory.createClass("b.B");
65         b_B_b = factory.createFeature("b.B.b");
66     }
67
68     public void testEmptyInclude() {
69         assertFalse("a", criteria.matches(a));
70         assertFalse("a.A", criteria.matches(a_A));
71         assertFalse("a.A.a", criteria.matches(a_A_a));
72
73         assertFalse("b", criteria.matches(b));
74         assertFalse("b.B", criteria.matches(b_B));
75         assertFalse("b.B.b", criteria.matches(b_B_b));
76     }
77
78     public void testNullInclude() {
79         criteria = new CollectionSelectionCriteria(null, exclude);
80
81         assertTrue("a", criteria.matches(a));
82         assertTrue("a.A", criteria.matches(a_A));
83         assertTrue("a.A.a", criteria.matches(a_A_a));
84
85         assertTrue("b", criteria.matches(b));
86         assertTrue("b.B", criteria.matches(b_B));
87         assertTrue("b.B.b", criteria.matches(b_B_b));
88     }
89
90     public void testMatchPackageNode() {
91         include.add("a");
92
93         assertTrue("a", criteria.matches(a));
94         assertFalse("a.A", criteria.matches(a_A));
95         assertFalse("a.A.a", criteria.matches(a_A_a));
96
97         assertFalse("b", criteria.matches(b));
98         assertFalse("b.B", criteria.matches(b_B));
99         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 }
183
Popular Tags