1 32 33 package com.jeantessier.dependency; 34 35 import java.io.*; 36 import java.util.*; 37 38 import junit.framework.*; 39 40 import org.apache.oro.text.perl.*; 41 42 public class TestRegularExpressionSelectionCriteria extends TestCase { 43 private RegularExpressionSelectionCriteria criteria; 44 private NodeFactory factory; 45 46 private PackageNode a; 47 private ClassNode a_A; 48 private FeatureNode a_A_a; 49 50 private PackageNode b; 51 private ClassNode b_B; 52 private FeatureNode b_B_b; 53 54 private PackageNode c; 55 private ClassNode c_C; 56 private FeatureNode c_C_c; 57 58 private List include; 59 private List exclude; 60 61 protected void setUp() throws Exception { 62 criteria = new RegularExpressionSelectionCriteria(); 63 factory = new NodeFactory(); 64 65 a = factory.createPackage("a"); 66 a_A = factory.createClass("a.A"); 67 a_A_a = factory.createFeature("a.A.a"); 68 69 b = factory.createPackage("b"); 70 b_B = factory.createClass("b.B"); 71 b_B_b = factory.createFeature("b.B.b"); 72 73 c = factory.createPackage("c"); 74 c_C = factory.createClass("c.C"); 75 c_C_c = factory.createFeature("c.C.c"); 76 77 include = new LinkedList(); 78 include.add("/^b/"); 79 80 exclude = new LinkedList(); 81 exclude.add("/^c/"); 82 } 83 84 public void testParseRE() { 85 List expected = new ArrayList(); 86 expected.add("/test/"); 87 88 List test = RegularExpressionSelectionCriteria.parseRE("/test/"); 89 90 assertEquals("size", expected.size(), test.size()); 91 assertEquals("/test/", expected.get(0), test.get(0)); 92 } 93 94 public void testParseBrokenRE() { 95 List expected = new ArrayList(); 96 expected.add("/test"); 97 98 List test = RegularExpressionSelectionCriteria.parseRE("/test"); 99 100 assertEquals("size", expected.size(), test.size()); 101 assertEquals("/test", expected.get(0), test.get(0)); 102 } 103 104 public void testParseMultipleREs() { 105 List expected = new ArrayList(); 106 expected.add("/test1/"); 107 expected.add("/test2/"); 108 109 List test = RegularExpressionSelectionCriteria.parseRE("/test1/,/test2/"); 110 111 assertEquals("size", expected.size(), test.size()); 112 assertEquals("/test1/", expected.get(0), test.get(0)); 113 assertEquals("/test2/", expected.get(1), test.get(1)); 114 } 115 116 public void testParseComplexREs() { 117 List expected = new ArrayList(); 118 expected.add("/test1\\/test2/"); 119 120 List test = RegularExpressionSelectionCriteria.parseRE("/test1\\/test2/"); 121 122 assertEquals("size", expected.size(), test.size()); 123 assertEquals("/test1\\/test2/", expected.get(0), test.get(0)); 124 } 125 126 public void testParseReallyComplexREs() { 127 List expected = new ArrayList(); 128 expected.add("m=test1\\=test2=i"); 129 130 List test = RegularExpressionSelectionCriteria.parseRE("m=test1\\=test2=i"); 131 132 assertEquals("size", expected.size(), test.size()); 133 assertEquals("m=test1\\=test2=i", expected.get(0), test.get(0)); 134 } 135 136 public void testMatch() { 137 criteria.setMatchingPackages(true); 138 criteria.setMatchingClasses(false); 139 criteria.setMatchingFeatures(false); 140 141 assertTrue("a not in package scope", criteria.matches(a)); 142 assertTrue("a.A in package scope", !criteria.matches(a_A)); 143 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 144 assertTrue("b not in package scope", criteria.matches(b)); 145 assertTrue("b.B in package scope", !criteria.matches(b_B)); 146 assertTrue("b.B.b in package scope", !criteria.matches(b_B_b)); 147 assertTrue("c not in package scope", criteria.matches(c)); 148 assertTrue("c.C in package scope", !criteria.matches(c_C)); 149 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 150 151 criteria.setMatchingPackages(false); 152 criteria.setMatchingClasses(true); 153 criteria.setMatchingFeatures(false); 154 155 assertTrue("a in package scope", !criteria.matches(a)); 156 assertTrue("a.A not in package scope", criteria.matches(a_A)); 157 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 158 assertTrue("b not in package scope", !criteria.matches(b)); 159 assertTrue("b.B in package scope", criteria.matches(b_B)); 160 assertTrue("b.B.b in package scope", !criteria.matches(b_B_b)); 161 assertTrue("c not in package scope", !criteria.matches(c)); 162 assertTrue("c.C in package scope", criteria.matches(c_C)); 163 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 164 165 criteria.setMatchingPackages(false); 166 criteria.setMatchingClasses(false); 167 criteria.setMatchingFeatures(true); 168 169 assertTrue("a in package scope", !criteria.matches(a)); 170 assertTrue("a.A in package scope", !criteria.matches(a_A)); 171 assertTrue("a.A.a not in package scope", criteria.matches(a_A_a)); 172 assertTrue("b not in package scope", !criteria.matches(b)); 173 assertTrue("b.B in package scope", !criteria.matches(b_B)); 174 assertTrue("b.B.b in package scope", criteria.matches(b_B_b)); 175 assertTrue("c not in package scope", !criteria.matches(c)); 176 assertTrue("c.C in package scope", !criteria.matches(c_C)); 177 assertTrue("c.C.c in package scope", criteria.matches(c_C_c)); 178 } 179 180 public void testGlobalIncludes() { 181 criteria.setGlobalIncludes(include); 182 183 criteria.setMatchingPackages(true); 184 criteria.setMatchingClasses(false); 185 criteria.setMatchingFeatures(false); 186 187 assertTrue("a in package scope", !criteria.matches(a)); 188 assertTrue("a.A in package scope", !criteria.matches(a_A)); 189 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 190 assertTrue("b not in package scope", criteria.matches(b)); 191 assertTrue("b.B in package scope", !criteria.matches(b_B)); 192 assertTrue("b.B.b in package scope", !criteria.matches(b_B_b)); 193 assertTrue("c in package scope", !criteria.matches(c)); 194 assertTrue("c.C in package scope", !criteria.matches(c_C)); 195 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 196 197 criteria.setMatchingPackages(false); 198 criteria.setMatchingClasses(true); 199 criteria.setMatchingFeatures(false); 200 201 assertTrue("a in package scope", !criteria.matches(a)); 202 assertTrue("a.A in package scope", !criteria.matches(a_A)); 203 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 204 assertTrue("b in package scope", !criteria.matches(b)); 205 assertTrue("b.B not in package scope", criteria.matches(b_B)); 206 assertTrue("b.B.b in package scope", !criteria.matches(b_B_b)); 207 assertTrue("c in package scope", !criteria.matches(c)); 208 assertTrue("c.C in package scope", !criteria.matches(c_C)); 209 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 210 211 criteria.setMatchingPackages(false); 212 criteria.setMatchingClasses(false); 213 criteria.setMatchingFeatures(true); 214 215 assertTrue("a in package scope", !criteria.matches(a)); 216 assertTrue("a.A in package scope", !criteria.matches(a_A)); 217 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 218 assertTrue("b in package scope", !criteria.matches(b)); 219 assertTrue("b.B in package scope", !criteria.matches(b_B)); 220 assertTrue("b.B.b not in package scope", criteria.matches(b_B_b)); 221 assertTrue("c in package scope", !criteria.matches(c)); 222 assertTrue("c.C in package scope", !criteria.matches(c_C)); 223 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 224 } 225 226 public void testGlobalExcludes() { 227 criteria.setGlobalExcludes(exclude); 228 229 criteria.setMatchingPackages(true); 230 criteria.setMatchingClasses(false); 231 criteria.setMatchingFeatures(false); 232 233 assertTrue("a not in package scope", criteria.matches(a)); 234 assertTrue("a.A in package scope", !criteria.matches(a_A)); 235 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 236 assertTrue("b not in package scope", criteria.matches(b)); 237 assertTrue("b.B in package scope", !criteria.matches(b_B)); 238 assertTrue("b.B.b in package scope", !criteria.matches(b_B_b)); 239 assertTrue("c in package scope", !criteria.matches(c)); 240 assertTrue("c.C in package scope", !criteria.matches(c_C)); 241 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 242 243 criteria.setMatchingPackages(false); 244 criteria.setMatchingClasses(true); 245 criteria.setMatchingFeatures(false); 246 247 assertTrue("a in package scope", !criteria.matches(a)); 248 assertTrue("a.A not in package scope", criteria.matches(a_A)); 249 assertTrue("a.A.a in package scope", !criteria.matches(a_A_a)); 250 assertTrue("b in package scope", !criteria.matches(b)); 251 assertTrue("b.B not in package scope", criteria.matches(b_B)); 252 assertTrue("b.B.b in package scope", !criteria.matches(b_B_b)); 253 assertTrue("c not in package scope", !criteria.matches(c)); 254 assertTrue("c.C in package scope", !criteria.matches(c_C)); 255 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 256 257 criteria.setMatchingPackages(false); 258 criteria.setMatchingClasses(false); 259 criteria.setMatchingFeatures(true); 260 261 assertTrue("a in package scope", !criteria.matches(a)); 262 assertTrue("a.A in package scope", !criteria.matches(a_A)); 263 assertTrue("a.A.a not in package scope", criteria.matches(a_A_a)); 264 assertTrue("b in package scope", !criteria.matches(b)); 265 assertTrue("b.B in package scope", !criteria.matches(b_B)); 266 assertTrue("b.B.b not in package scope", criteria.matches(b_B_b)); 267 assertTrue("c not in package scope", !criteria.matches(c)); 268 assertTrue("c.C in package scope", !criteria.matches(c_C)); 269 assertTrue("c.C.c in package scope", !criteria.matches(c_C_c)); 270 } 271 } 272 | Popular Tags |