1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.surefire.api.testset; 20 21 import org.junit.Test; 22 23 import static org.hamcrest.MatcherAssert.assertThat; 24 import static org.hamcrest.Matchers.is; 25 26 @SuppressWarnings({"javadoc", "checkstyle:javadoctype"}) 27 /** 28 * Inclusive test patters:<p> 29 * 30 * <table cellspacing=0 border=0> 31 * <tr> 32 * <td style=min-width:50px> test</td> 33 * <td style=min-width:50px></td> 34 * <td style=min-width:50px> pattern</td> 35 * <td style=min-width:50px></td> 36 * <td style=min-width:50px></td> 37 * <td style=min-width:50px></td> 38 * </tr> 39 * <tr> 40 * <td style=min-width:50px>class</td> 41 * <td style=min-width:50px>method</td> 42 * <td style=min-width:50px>class</td> 43 * <td style=min-width:50px>method</td> 44 * <td style=min-width:50px>shouldRunAsInclusive</td> 45 * <td style=min-width:50px></td> 46 * </tr> 47 * <tr> 48 * <td style=min-width:50px>n</td> 49 * <td style=min-width:50px>n</td> 50 * <td style=min-width:50px>n</td> 51 * <td style=min-width:50px>n</td> 52 * <td style=min-width:50px>y (wildcard pattern)</td> 53 * <td style=min-width:50px>testIncludes1</td> 54 * </tr> 55 * <tr> 56 * <td style=min-width:50px>n</td> 57 * <td style=min-width:50px>n</td> 58 * <td style=min-width:50px>n</td> 59 * <td style=min-width:50px>y</td> 60 * <td style=min-width:50px>y (suppose suite and custome filter)</td> 61 * <td style=min-width:50px>testIncludes2</td> 62 * </tr> 63 * <tr> 64 * <td style=min-width:50px>n</td> 65 * <td style=min-width:50px>n</td> 66 * <td style=min-width:50px>y</td> 67 * <td style=min-width:50px>n</td> 68 * <td style=min-width:50px>y (suppose Suite)</td> 69 * <td style=min-width:50px>testIncludes3</td> 70 * </tr> 71 * <tr> 72 * <td style=min-width:50px>n</td> 73 * <td style=min-width:50px>n</td> 74 * <td style=min-width:50px>y</td> 75 * <td style=min-width:50px>y</td> 76 * <td style=min-width:50px>y (suppose Suite)</td> 77 * <td style=min-width:50px>testIncludes4</td> 78 * </tr> 79 * <tr> 80 * <td style=min-width:50px>n</td> 81 * <td style=min-width:50px>y</td> 82 * <td style=min-width:50px>n</td> 83 * <td style=min-width:50px>n</td> 84 * <td style=min-width:50px>y (wildcard pattern)</td> 85 * <td style=min-width:50px>testIncludes5</td> 86 * </tr> 87 * <tr> 88 * <td style=min-width:50px>n</td> 89 * <td style=min-width:50px>y</td> 90 * <td style=min-width:50px>n</td> 91 * <td style=min-width:50px>y</td> 92 * <td style=min-width:50px>match methods</td> 93 * <td style=min-width:50px>testIncludes6</td> 94 * </tr> 95 * <tr> 96 * <td style=min-width:50px>n</td> 97 * <td style=min-width:50px>y</td> 98 * <td style=min-width:50px>y</td> 99 * <td style=min-width:50px>n</td> 100 * <td style=min-width:50px>y (due to Cucumber)</td> 101 * <td style=min-width:50px>testIncludes7</td> 102 * </tr> 103 * <tr> 104 * <td style=min-width:50px>n</td> 105 * <td style=min-width:50px>y</td> 106 * <td style=min-width:50px>y</td> 107 * <td style=min-width:50px>y</td> 108 * <td style=min-width:50px>y (due to Cucumber)</td> 109 * <td style=min-width:50px>testIncludes8</td> 110 * </tr> 111 * <tr> 112 * <td style=min-width:50px>y</td> 113 * <td style=min-width:50px>n</td> 114 * <td style=min-width:50px>n</td> 115 * <td style=min-width:50px>n</td> 116 * <td style=min-width:50px>y (wildcard pattern)</td> 117 * <td style=min-width:50px>testIncludes9</td> 118 * </tr> 119 * <tr> 120 * <td style=min-width:50px>y</td> 121 * <td style=min-width:50px>n</td> 122 * <td style=min-width:50px>n</td> 123 * <td style=min-width:50px>y</td> 124 * <td style=min-width:50px>y (suppose suite and custome filter)</td> 125 * <td style=min-width:50px>testIncludes10</td> 126 * </tr> 127 * <tr> 128 * <td style=min-width:50px>y</td> 129 * <td style=min-width:50px>n</td> 130 * <td style=min-width:50px>y</td> 131 * <td style=min-width:50px>n</td> 132 * <td style=min-width:50px>match classes</td> 133 * <td style=min-width:50px>testIncludes11</td> 134 * </tr> 135 * <tr> 136 * <td style=min-width:50px>y</td> 137 * <td style=min-width:50px>n</td> 138 * <td style=min-width:50px>y</td> 139 * <td style=min-width:50px>y</td> 140 * <td style=min-width:50px>match classes</td> 141 * <td style=min-width:50px>testIncludes12</td> 142 * </tr> 143 * <tr> 144 * <td style=min-width:50px>y</td> 145 * <td style=min-width:50px>y</td> 146 * <td style=min-width:50px>n</td> 147 * <td style=min-width:50px>n</td> 148 * <td style=min-width:50px>y (wildcard pattern)</td> 149 * <td style=min-width:50px>testIncludes13</td> 150 * </tr> 151 * <tr> 152 * <td style=min-width:50px>y</td> 153 * <td style=min-width:50px>y</td> 154 * <td style=min-width:50px>n</td> 155 * <td style=min-width:50px>y</td> 156 * <td style=min-width:50px>match methods</td> 157 * <td style=min-width:50px>testIncludes14</td> 158 * </tr> 159 * <tr> 160 * <td style=min-width:50px>y</td> 161 * <td style=min-width:50px>y</td> 162 * <td style=min-width:50px>y</td> 163 * <td style=min-width:50px>n</td> 164 * <td style=min-width:50px>match classes</td> 165 * <td style=min-width:50px>testIncludes15</td> 166 * </tr> 167 * <tr> 168 * <td style=min-width:50px>y</td> 169 * <td style=min-width:50px>y</td> 170 * <td style=min-width:50px>y</td> 171 * <td style=min-width:50px>y</td> 172 * <td style=min-width:50px>match all</td> 173 * <td style=min-width:50px>testIncludes16</td> 174 * </tr> 175 * </table> 176 * <p> 177 * <p> 178 * Exclusive test patters:<p> 179 * 180 * <table cellspacing=0 border=0> 181 * <tr> 182 * <td style=min-width:50px> test</td> 183 * <td style=min-width:50px></td> 184 * <td style=min-width:50px> pattern</td> 185 * <td style=min-width:50px></td> 186 * <td style=min-width:50px></td> 187 * <td style=min-width:50px></td> 188 * </tr> 189 * <tr> 190 * <td style=min-width:50px>class</td> 191 * <td style=min-width:50px>method</td> 192 * <td style=min-width:50px>class</td> 193 * <td style=min-width:50px>method</td> 194 * <td style=min-width:50px>shouldRunAsExclusive</td> 195 * <td style=min-width:50px></td> 196 * </tr> 197 * <tr> 198 * <td style=min-width:50px>n</td> 199 * <td style=min-width:50px>n</td> 200 * <td style=min-width:50px>n</td> 201 * <td style=min-width:50px>n</td> 202 * <td style=min-width:50px>n (wildcard pattern)</td> 203 * <td style=min-width:50px>testExcludes1</td> 204 * </tr> 205 * <tr> 206 * <td style=min-width:50px>n</td> 207 * <td style=min-width:50px>n</td> 208 * <td style=min-width:50px>n</td> 209 * <td style=min-width:50px>y</td> 210 * <td style=min-width:50px>n (suppose suite and custome filter)</td> 211 * <td style=min-width:50px>testExcludes2</td> 212 * </tr> 213 * <tr> 214 * <td style=min-width:50px>n</td> 215 * <td style=min-width:50px>n</td> 216 * <td style=min-width:50px>y</td> 217 * <td style=min-width:50px>n</td> 218 * <td style=min-width:50px>n (suppose Suite)</td> 219 * <td style=min-width:50px>testExcludes3</td> 220 * </tr> 221 * <tr> 222 * <td style=min-width:50px>n</td> 223 * <td style=min-width:50px>n</td> 224 * <td style=min-width:50px>y</td> 225 * <td style=min-width:50px>y</td> 226 * <td style=min-width:50px>n (suppose Suite)</td> 227 * <td style=min-width:50px>testExcludes4</td> 228 * </tr> 229 * <tr> 230 * <td style=min-width:50px>n</td> 231 * <td style=min-width:50px>y</td> 232 * <td style=min-width:50px>n</td> 233 * <td style=min-width:50px>n</td> 234 * <td style=min-width:50px>n (wildcard pattern)</td> 235 * <td style=min-width:50px>testExcludes5</td> 236 * </tr> 237 * <tr> 238 * <td style=min-width:50px>n</td> 239 * <td style=min-width:50px>y</td> 240 * <td style=min-width:50px>n</td> 241 * <td style=min-width:50px>y</td> 242 * <td style=min-width:50px>match methods</td> 243 * <td style=min-width:50px>testExcludes6</td> 244 * </tr> 245 * <tr> 246 * <td style=min-width:50px>n</td> 247 * <td style=min-width:50px>y</td> 248 * <td style=min-width:50px>y</td> 249 * <td style=min-width:50px>n</td> 250 * <td style=min-width:50px>n (due to Cucumber)</td> 251 * <td style=min-width:50px>testExcludes7</td> 252 * </tr> 253 * <tr> 254 * <td style=min-width:50px>n</td> 255 * <td style=min-width:50px>y</td> 256 * <td style=min-width:50px>y</td> 257 * <td style=min-width:50px>y</td> 258 * <td style=min-width:50px>n (due to Cucumber)</td> 259 * <td style=min-width:50px>testExcludes8</td> 260 * </tr> 261 * <tr> 262 * <td style=min-width:50px>y</td> 263 * <td style=min-width:50px>n</td> 264 * <td style=min-width:50px>n</td> 265 * <td style=min-width:50px>n</td> 266 * <td style=min-width:50px>n (wildcard pattern)</td> 267 * <td style=min-width:50px>testExcludes9</td> 268 * </tr> 269 * <tr> 270 * <td style=min-width:50px>y</td> 271 * <td style=min-width:50px>n</td> 272 * <td style=min-width:50px>n</td> 273 * <td style=min-width:50px>y</td> 274 * <td style=min-width:50px>n (suppose suite and custome filter)</td> 275 * <td style=min-width:50px>testExcludes10</td> 276 * </tr> 277 * <tr> 278 * <td style=min-width:50px>y</td> 279 * <td style=min-width:50px>n</td> 280 * <td style=min-width:50px>y</td> 281 * <td style=min-width:50px>n</td> 282 * <td style=min-width:50px>match classes</td> 283 * <td style=min-width:50px>testExcludes11</td> 284 * </tr> 285 * <tr> 286 * <td style=min-width:50px>y</td> 287 * <td style=min-width:50px>n</td> 288 * <td style=min-width:50px>y</td> 289 * <td style=min-width:50px>y</td> 290 * <td style=min-width:50px>n (cannot exclude in dir.scanner)</td> 291 * <td style=min-width:50px>testExcludes12</td> 292 * </tr> 293 * <tr> 294 * <td style=min-width:50px>y</td> 295 * <td style=min-width:50px>y</td> 296 * <td style=min-width:50px>n</td> 297 * <td style=min-width:50px>n</td> 298 * <td style=min-width:50px>n (wildcard pattern)</td> 299 * <td style=min-width:50px>testExcludes13</td> 300 * </tr> 301 * <tr> 302 * <td style=min-width:50px>y</td> 303 * <td style=min-width:50px>y</td> 304 * <td style=min-width:50px>n</td> 305 * <td style=min-width:50px>y</td> 306 * <td style=min-width:50px>match methods</td> 307 * <td style=min-width:50px>testExcludes14</td> 308 * </tr> 309 * <tr> 310 * <td style=min-width:50px>y</td> 311 * <td style=min-width:50px>y</td> 312 * <td style=min-width:50px>y</td> 313 * <td style=min-width:50px>n</td> 314 * <td style=min-width:50px>match classes</td> 315 * <td style=min-width:50px>testExcludes15</td> 316 * </tr> 317 * <tr> 318 * <td style=min-width:50px>y</td> 319 * <td style=min-width:50px>y</td> 320 * <td style=min-width:50px>y</td> 321 * <td style=min-width:50px>y</td> 322 * <td style=min-width:50px>match all</td> 323 * <td style=min-width:50px>testExcludes16</td> 324 * </tr> 325 * </table> 326 */ 327 public class FundamentalFilterTest { 328 @Test 329 public void testIncludes1() { 330 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 331 assertThat(pattern.matchAsInclusive(null, null), is(true)); 332 } 333 334 @Test 335 public void testIncludes2() { 336 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 337 assertThat(pattern.matchAsInclusive(null, null), is(true)); 338 } 339 340 @Test 341 public void testIncludes3() { 342 ResolvedTest pattern = new ResolvedTest("Test", null, false); 343 assertThat(pattern.matchAsInclusive(null, null), is(true)); 344 } 345 346 @Test 347 public void testIncludes4() { 348 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 349 assertThat(pattern.matchAsInclusive(null, null), is(true)); 350 } 351 352 @Test 353 public void testIncludes5() { 354 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 355 assertThat(pattern.matchAsInclusive(null, "method"), is(true)); 356 } 357 358 @Test 359 public void testIncludes6() { 360 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 361 assertThat(pattern.matchAsInclusive(null, "method"), is(true)); 362 assertThat(pattern.matchAsInclusive(null, "otherMethod"), is(false)); 363 } 364 365 /** 366 * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL. 367 */ 368 @Test 369 public void testIncludes7() { 370 ResolvedTest pattern = new ResolvedTest("Test", null, false); 371 assertThat(pattern.matchAsInclusive(null, "method"), is(true)); 372 } 373 374 /** 375 * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL. 376 */ 377 @Test 378 public void testIncludes8() { 379 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 380 assertThat(pattern.matchAsInclusive(null, "method"), is(true)); 381 assertThat(pattern.matchAsInclusive(null, "otherMethod"), is(true)); 382 } 383 384 @Test 385 public void testIncludes9() { 386 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 387 assertThat(pattern.matchAsInclusive("Test.class", null), is(true)); 388 } 389 390 @Test 391 public void testIncludes10() { 392 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 393 assertThat(pattern.matchAsInclusive("Test.class", null), is(true)); 394 } 395 396 @Test 397 public void testIncludes11() { 398 ResolvedTest pattern = new ResolvedTest("Test", null, false); 399 assertThat(pattern.matchAsInclusive("Test.class", null), is(true)); 400 assertThat(pattern.matchAsInclusive("Other.class", null), is(false)); 401 } 402 403 @Test 404 public void testIncludes12() { 405 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 406 assertThat(pattern.matchAsInclusive("Test.class", null), is(true)); 407 assertThat(pattern.matchAsInclusive("Other.class", null), is(false)); 408 } 409 410 @Test 411 public void testIncludes13() { 412 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 413 assertThat(pattern.matchAsInclusive("Test.class", "method"), is(true)); 414 } 415 416 @Test 417 public void testIncludes14() { 418 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 419 assertThat(pattern.matchAsInclusive("Test.class", "method"), is(true)); 420 assertThat(pattern.matchAsInclusive("Test.class", "otherMethod"), is(false)); 421 } 422 423 @Test 424 public void testIncludes15() { 425 ResolvedTest pattern = new ResolvedTest("Test", null, false); 426 assertThat(pattern.matchAsInclusive("Test.class", "method"), is(true)); 427 assertThat(pattern.matchAsInclusive("Other.class", "method"), is(false)); 428 } 429 430 @Test 431 public void testIncludes16() { 432 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 433 assertThat(pattern.matchAsInclusive("Test.class", "method"), is(true)); 434 assertThat(pattern.matchAsInclusive("Test.class", "otherMethod"), is(false)); 435 assertThat(pattern.matchAsInclusive("Other.class", "method"), is(false)); 436 assertThat(pattern.matchAsInclusive("Other.class", "otherMethod"), is(false)); 437 } 438 439 @Test 440 public void testExcludes1() { 441 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 442 assertThat(pattern.matchAsExclusive(null, null), is(false)); 443 } 444 445 @Test 446 public void testExcludes2() { 447 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 448 assertThat(pattern.matchAsExclusive(null, null), is(false)); 449 } 450 451 @Test 452 public void testExcludes3() { 453 ResolvedTest pattern = new ResolvedTest("Test", null, false); 454 assertThat(pattern.matchAsExclusive(null, null), is(false)); 455 } 456 457 @Test 458 public void testExcludes4() { 459 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 460 assertThat(pattern.matchAsExclusive(null, null), is(false)); 461 } 462 463 @Test 464 public void testExcludes5() { 465 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 466 assertThat(pattern.matchAsExclusive(null, "method"), is(false)); 467 } 468 469 @Test 470 public void testExcludes6() { 471 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 472 assertThat(pattern.matchAsExclusive(null, "method"), is(true)); 473 assertThat(pattern.matchAsExclusive(null, "otherMethod"), is(false)); 474 } 475 476 /** 477 * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL. 478 */ 479 @Test 480 public void testExcludes7() { 481 ResolvedTest pattern = new ResolvedTest("Test", null, false); 482 assertThat(pattern.matchAsExclusive(null, "method"), is(false)); 483 } 484 485 /** 486 * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL. 487 */ 488 @Test 489 public void testExcludes8() { 490 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 491 assertThat(pattern.matchAsExclusive(null, "method"), is(false)); 492 assertThat(pattern.matchAsExclusive(null, "otherMethod"), is(false)); 493 } 494 495 @Test 496 public void testExcludes9() { 497 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 498 assertThat(pattern.matchAsExclusive("Test.class", null), is(false)); 499 } 500 501 @Test 502 public void testExcludes10() { 503 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 504 assertThat(pattern.matchAsExclusive("Test.class", null), is(false)); 505 } 506 507 @Test 508 public void testExcludes11() { 509 ResolvedTest pattern = new ResolvedTest("Test", null, false); 510 assertThat(pattern.matchAsExclusive("Test.class", null), is(true)); 511 assertThat(pattern.matchAsExclusive("Other.class", null), is(false)); 512 } 513 514 @Test 515 public void testExcludes12() { 516 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 517 assertThat(pattern.matchAsExclusive("Test.class", null), is(false)); 518 assertThat(pattern.matchAsExclusive("Other.class", null), is(false)); 519 } 520 521 @Test 522 public void testExcludes13() { 523 ResolvedTest pattern = new ResolvedTest((String) null, null, false); 524 assertThat(pattern.matchAsExclusive("Test.class", "method"), is(false)); 525 } 526 527 @Test 528 public void testExcludes14() { 529 ResolvedTest pattern = new ResolvedTest((String) null, "method", false); 530 assertThat(pattern.matchAsExclusive("Test.class", "method"), is(true)); 531 assertThat(pattern.matchAsExclusive("Test.class", "otherMethod"), is(false)); 532 } 533 534 @Test 535 public void testExcludes15() { 536 ResolvedTest pattern = new ResolvedTest("Test", null, false); 537 assertThat(pattern.matchAsExclusive("Test.class", "method"), is(true)); 538 assertThat(pattern.matchAsExclusive("Other.class", "method"), is(false)); 539 } 540 541 @Test 542 public void testExcludes16() { 543 ResolvedTest pattern = new ResolvedTest("Test", "method", false); 544 assertThat(pattern.matchAsExclusive("Test.class", "method"), is(true)); 545 assertThat(pattern.matchAsExclusive("Test.class", "otherMethod"), is(false)); 546 assertThat(pattern.matchAsExclusive("Other.class", "method"), is(false)); 547 assertThat(pattern.matchAsExclusive("Other.class", "otherMethod"), is(false)); 548 } 549 }