|
26 | 26 | import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod;
|
27 | 27 | import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;
|
28 | 28 | import static org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId;
|
| 29 | +import static org.junit.platform.engine.discovery.PackageNameFilter.includePackageNames; |
29 | 30 | import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
|
30 | 31 |
|
31 | 32 | import java.lang.reflect.Method;
|
@@ -268,6 +269,22 @@ void resolvesApplyingClassNameFilters() throws Exception {
|
268 | 269 | // @formatter:on
|
269 | 270 | }
|
270 | 271 |
|
| 272 | + @Test |
| 273 | + void resolvesApplyingPackageNameFilters() throws Exception { |
| 274 | + Path root = getClasspathRoot(PlainJUnit4TestCaseWithSingleTestWhichFails.class); |
| 275 | + |
| 276 | + LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClasspathRoots(singleton(root))).filters( |
| 277 | + includePackageNames("org"), includePackageNames("org.junit")).build(); |
| 278 | + |
| 279 | + TestDescriptor engineDescriptor = discoverTests(discoveryRequest); |
| 280 | + |
| 281 | + // @formatter:off |
| 282 | + assertThat(engineDescriptor.getChildren()) |
| 283 | + .extracting(TestDescriptor::getDisplayName) |
| 284 | + .contains(PlainJUnit4TestCaseWithSingleTestWhichFails.class.getName()); |
| 285 | + // @formatter:on |
| 286 | + } |
| 287 | + |
271 | 288 | @Test
|
272 | 289 | void resolvesPackageSelectorForJUnit4SamplesPackage() {
|
273 | 290 | Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
|
@@ -560,6 +577,19 @@ void doesNotResolveMethodOfClassNotAcceptedByClassNameFilter() throws Exception
|
560 | 577 | assertYieldsNoDescriptors(request);
|
561 | 578 | }
|
562 | 579 |
|
| 580 | + @Test |
| 581 | + void doesNotResolveMethodOfClassNotAcceptedByPackageNameFilter() throws Exception { |
| 582 | + Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class; |
| 583 | + // @formatter:off |
| 584 | + LauncherDiscoveryRequest request = request() |
| 585 | + .selectors(selectMethod(testClass, testClass.getMethod("failingTest"))) |
| 586 | + .filters(includePackageNames("com.acme")) |
| 587 | + .build(); |
| 588 | + // @formatter:on |
| 589 | + |
| 590 | + assertYieldsNoDescriptors(request); |
| 591 | + } |
| 592 | + |
563 | 593 | @Test
|
564 | 594 | void resolvesClassForMethodSelectorForClassWithNonFilterableRunner() throws Exception {
|
565 | 595 | Class<?> testClass = IgnoredJUnit4TestCase.class;
|
|
0 commit comments