diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.java index 3b46df45e24..744fd1a71be 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.java @@ -124,7 +124,7 @@ public LauncherDiscoveryRequestBuilder() { } /** - * Add all of the supplied {@code selectors} to the request. + * Add all supplied {@code selectors} to the request. * * @param selectors the {@code DiscoverySelectors} to add; never {@code null} * @return this builder for method chaining @@ -136,7 +136,7 @@ public LauncherDiscoveryRequestBuilder selectors(DiscoverySelector... selectors) } /** - * Add all of the supplied {@code selectors} to the request. + * Add all supplied {@code selectors} to the request. * * @param selectors the {@code DiscoverySelectors} to add; never {@code null} * @return this builder for method chaining @@ -149,7 +149,7 @@ public LauncherDiscoveryRequestBuilder selectors(ListThe {@code filters} are combined using AND semantics, i.e. all of them * have to include a resource for it to end up in the test plan. @@ -185,7 +185,7 @@ public LauncherDiscoveryRequestBuilder configurationParameter(String key, String } /** - * Add all of the supplied configuration parameters to the request. + * Add all supplied configuration parameters to the request. * * @param configurationParameters the map of configuration parameters to add; * never {@code null} @@ -206,23 +206,46 @@ public LauncherDiscoveryRequestBuilder configurationParameters(MapBy default, in addition to those parameters that are passed explicitly + * to this builder, configuration parameters are read from system properties + * and from the {@code junit-platform.properties} classpath resource. + * Passing {@code false} to this method, disables the latter two sources so + * that only explicit configuration parameters are taken into account. + * + * @param enabled {@code true} if implicit configuration parameters should be + * considered + * @return this builder for method chaining + * @since 1.7 + * @see #configurationParameter(String, String) + * @see #configurationParameters(Map) + */ + @API(status = STABLE, since = "1.10") + public LauncherDiscoveryRequestBuilder enableImplicitConfigurationParameters(boolean enabled) { + this.implicitConfigurationParametersEnabled = enabled; + return this; + } + + /** + * Add all supplied discovery listeners to the request. * *

In addition to the {@linkplain LauncherDiscoveryListener listeners} * registered using this method, this builder will add a default listener @@ -246,25 +269,6 @@ public LauncherDiscoveryRequestBuilder listeners(LauncherDiscoveryListener... li return this; } - /** - * Configure whether implicit configuration parameters should be considered. - * - *

By default, in addition to those parameters that are passed explicitly - * to this builder, configuration parameters are read from system properties - * and from the {@code junit-platform.properties} classpath resource. - * Passing {@code false} to this method, disables the latter two sources so - * that only explicit configuration parameters are taken into account. - * - * @since 1.7 - * @see #configurationParameter(String, String) - * @see #configurationParameters(Map) - */ - @API(status = STABLE, since = "1.10") - public LauncherDiscoveryRequestBuilder enableImplicitConfigurationParameters(boolean enabled) { - this.implicitConfigurationParametersEnabled = enabled; - return this; - } - private void storeFilter(Filter filter) { if (filter instanceof EngineFilter) { this.engineFilters.add((EngineFilter) filter); @@ -298,7 +302,7 @@ private LauncherConfigurationParameters buildLauncherConfigurationParameters() { .explicitParameters(this.configurationParameters) // .enableImplicitProviders(this.implicitConfigurationParametersEnabled); - if (parentConfigurationParameters != null) { + if (this.parentConfigurationParameters != null) { builder.parentConfigurationParameters(this.parentConfigurationParameters); } @@ -308,14 +312,14 @@ private LauncherConfigurationParameters buildLauncherConfigurationParameters() { private LauncherDiscoveryListener getLauncherDiscoveryListener(ConfigurationParameters configurationParameters) { LauncherDiscoveryListener defaultDiscoveryListener = getDefaultLauncherDiscoveryListener( configurationParameters); - if (discoveryListeners.isEmpty()) { + if (this.discoveryListeners.isEmpty()) { return defaultDiscoveryListener; } - if (discoveryListeners.contains(defaultDiscoveryListener)) { - return LauncherDiscoveryListeners.composite(discoveryListeners); + if (this.discoveryListeners.contains(defaultDiscoveryListener)) { + return LauncherDiscoveryListeners.composite(this.discoveryListeners); } - List allDiscoveryListeners = new ArrayList<>(discoveryListeners.size() + 1); - allDiscoveryListeners.addAll(discoveryListeners); + List allDiscoveryListeners = new ArrayList<>(this.discoveryListeners.size() + 1); + allDiscoveryListeners.addAll(this.discoveryListeners); allDiscoveryListeners.add(defaultDiscoveryListener); return LauncherDiscoveryListeners.composite(allDiscoveryListeners); } diff --git a/junit-platform-suite-commons/src/main/java/org/junit/platform/suite/commons/SuiteLauncherDiscoveryRequestBuilder.java b/junit-platform-suite-commons/src/main/java/org/junit/platform/suite/commons/SuiteLauncherDiscoveryRequestBuilder.java index bb82f1663da..02e208ebad5 100644 --- a/junit-platform-suite-commons/src/main/java/org/junit/platform/suite/commons/SuiteLauncherDiscoveryRequestBuilder.java +++ b/junit-platform-suite-commons/src/main/java/org/junit/platform/suite/commons/SuiteLauncherDiscoveryRequestBuilder.java @@ -65,39 +65,40 @@ import org.junit.platform.suite.api.SelectUris; /** - * The {@code SuiteLauncherDiscoveryRequestBuilder} provides a builder for constructing instances - * of {@link LauncherDiscoveryRequest} specifically tailored for suite execution. + * The {@code SuiteLauncherDiscoveryRequestBuilder} provides a light-weight DSL + * for generating a {@link LauncherDiscoveryRequest} specifically tailored for + * suite execution. * *

Example

* *
{@code
  * SuiteLauncherDiscoveryRequestBuilder.request()
- * 		.selectors(
- * 			selectPackage("org.example.user"),
- * 			selectClass("org.example.payment.PaymentTests"),
- * 			selectClass(File.class),
- * 			selectMethod("org.example.order.OrderTests#test1"),
- * 			selectMethod("org.example.order.OrderTests#test2()"),
- * 			selectMethod("org.example.order.OrderTests#test3(java.lang.String)"),
- * 			selectMethod("org.example.order.OrderTests", "test4"),
- * 			selectMethod(OrderTests.class, "test5"),
- * 			selectMethod(OrderTests.class, testMethod),
- * 			selectClasspathRoots(Collections.singleton(Paths.get("/my/local/path1"))),
- * 			selectUniqueId("unique-id-1"),
- * 			selectUniqueId("unique-id-2")
- * 		)
- * 		.filters(
- * 			includeEngines("junit-jupiter", "spek"),
- * 			// excludeEngines("junit-vintage"),
- * 			includeTags("fast"),
- * 			// excludeTags("slow"),
- * 			includeClassNamePatterns(".*Test[s]?")
- * 			// includeClassNamePatterns("org\.example\.tests.*")
- * 		)
- * 		.configurationParameter("key", "value")
- * 		.enableImplicitConfigurationParameters(true)
- * 		.suite(File.class)
- * 		.build();
+ *   .selectors(
+ *        selectPackage("org.example.user"),
+ *        selectClass("org.example.payment.PaymentTests"),
+ *        selectClass(ShippingTests.class),
+ *        selectMethod("org.example.order.OrderTests#test1"),
+ *        selectMethod("org.example.order.OrderTests#test2()"),
+ *        selectMethod("org.example.order.OrderTests#test3(java.lang.String)"),
+ *        selectMethod("org.example.order.OrderTests", "test4"),
+ *        selectMethod(OrderTests.class, "test5"),
+ *        selectMethod(OrderTests.class, testMethod),
+ *        selectClasspathRoots(Collections.singleton(Paths.get("/my/local/path1"))),
+ *        selectUniqueId("unique-id-1"),
+ *        selectUniqueId("unique-id-2")
+ *   )
+ *   .filters(
+ *        includeEngines("junit-jupiter", "spek"),
+ *        // excludeEngines("junit-vintage"),
+ *        includeTags("fast"),
+ *        // excludeTags("slow"),
+ *        includeClassNamePatterns(".*Test[s]?")
+ *        // includeClassNamePatterns("org\.example\.tests.*")
+ *   )
+ *   .configurationParameter("key", "value")
+ *   .enableImplicitConfigurationParameters(true)
+ *   .suite(File.class)
+ *   .build();
  * }
* * @since 1.8 @@ -121,7 +122,7 @@ private SuiteLauncherDiscoveryRequestBuilder() { } /** - * Creates a mew instance of {@code SuiteLauncherDiscoveryRequestBuilder} + * Create a new {@code SuiteLauncherDiscoveryRequestBuilder}. * * @return a new builder */ @@ -130,43 +131,29 @@ public static SuiteLauncherDiscoveryRequestBuilder request() { } /** - * Specifies whether to filter standard class name patterns. - *

If set to {@code true}, standard class name patterns are filtered. - * - * @param filterStandardClassNamePatterns {@code true} to filter standard class name patterns, - * {@code false} otherwise - * @return this builder for method chaining - */ - public SuiteLauncherDiscoveryRequestBuilder filterStandardClassNamePatterns( - boolean filterStandardClassNamePatterns) { - this.filterStandardClassNamePatterns = filterStandardClassNamePatterns; - return this; - } - - /** - * Add all the supplied {@code selectors} to the request. + * Add all supplied {@code selectors} to the request. * * @param selectors the {@code DiscoverySelectors} to add; never {@code null} * @return this builder for method chaining */ public SuiteLauncherDiscoveryRequestBuilder selectors(DiscoverySelector... selectors) { - delegate.selectors(selectors); + this.delegate.selectors(selectors); return this; } /** - * Add all the supplied {@code selectors} to the request. + * Add all supplied {@code selectors} to the request. * * @param selectors the {@code DiscoverySelectors} to add; never {@code null} * @return this builder for method chaining */ public SuiteLauncherDiscoveryRequestBuilder selectors(List selectors) { - delegate.selectors(selectors); + this.delegate.selectors(selectors); return this; } /** - * Add all the supplied {@code filters} to the request. + * Add all supplied {@code filters} to the request. * *

The {@code filters} are combined using AND semantics, i.e. all of them * have to include a resource for it to end up in the test plan. @@ -181,7 +168,21 @@ public SuiteLauncherDiscoveryRequestBuilder selectors(List... filters) { - delegate.filters(filters); + this.delegate.filters(filters); + return this; + } + + /** + * Specify whether to filter standard class name patterns. + *

If set to {@code true}, standard class name patterns are filtered. + * + * @param filterStandardClassNamePatterns {@code true} to filter standard class + * name patterns, {@code false} otherwise + * @return this builder for method chaining + */ + public SuiteLauncherDiscoveryRequestBuilder filterStandardClassNamePatterns( + boolean filterStandardClassNamePatterns) { + this.filterStandardClassNamePatterns = filterStandardClassNamePatterns; return this; } @@ -194,12 +195,12 @@ public SuiteLauncherDiscoveryRequestBuilder filters(Filter... filters) { * @return this builder for method chaining */ public SuiteLauncherDiscoveryRequestBuilder configurationParameter(String key, String value) { - delegate.configurationParameter(key, value); + this.delegate.configurationParameter(key, value); return this; } /** - * Add all the supplied configuration parameters to the request. + * Add all supplied configuration parameters to the request. * * @param configurationParameters the map of configuration parameters to add; * never {@code null} @@ -207,7 +208,7 @@ public SuiteLauncherDiscoveryRequestBuilder configurationParameter(String key, S * @see #configurationParameter(String, String) */ public SuiteLauncherDiscoveryRequestBuilder configurationParameters(Map configurationParameters) { - delegate.configurationParameters(configurationParameters); + this.delegate.configurationParameters(configurationParameters); return this; } @@ -219,11 +220,10 @@ public SuiteLauncherDiscoveryRequestBuilder configurationParameters(MapThis method processes annotations on the suite class to customize * the suite discovery and execution. @@ -268,7 +270,7 @@ public SuiteLauncherDiscoveryRequestBuilder suite(Class suiteClass) { findRepeatableAnnotations(suiteClass, ConfigurationParameter.class) .forEach(configuration -> configurationParameter(configuration.key(), configuration.value())); findAnnotation(suiteClass, DisableParentConfigurationParameters.class) - .ifPresent(__ -> enableParentConfigurationParameters = false); + .ifPresent(__ -> this.enableParentConfigurationParameters = false); findAnnotationValues(suiteClass, ExcludeClassNamePatterns.class, ExcludeClassNamePatterns::value) .flatMap(SuiteLauncherDiscoveryRequestBuilder::trimmed) .map(ClassNameFilter::excludeClassNamePatterns) @@ -295,7 +297,7 @@ public SuiteLauncherDiscoveryRequestBuilder suite(Class suiteClass) { .flatMap(SuiteLauncherDiscoveryRequestBuilder::trimmed) .map(this::createIncludeClassNameFilter) .ifPresent(filters -> { - includeClassNamePatternsUsed = true; + this.includeClassNamePatternsUsed = true; filters(filters); }); findAnnotationValues(suiteClass, IncludeEngines.class, IncludeEngines::value) @@ -336,15 +338,15 @@ public SuiteLauncherDiscoveryRequestBuilder suite(Class suiteClass) { * this builder. */ public LauncherDiscoveryRequest build() { - if (filterStandardClassNamePatterns && !includeClassNamePatternsUsed) { - delegate.filters(createIncludeClassNameFilter(STANDARD_INCLUDE_PATTERN)); + if (this.filterStandardClassNamePatterns && !this.includeClassNamePatternsUsed) { + this.delegate.filters(createIncludeClassNameFilter(STANDARD_INCLUDE_PATTERN)); } - if (enableParentConfigurationParameters && parentConfigurationParameters != null) { - delegate.parentConfigurationParameters(parentConfigurationParameters); + if (this.enableParentConfigurationParameters && this.parentConfigurationParameters != null) { + this.delegate.parentConfigurationParameters(this.parentConfigurationParameters); } - return delegate.build(); + return this.delegate.build(); } private List selectClasses(Class suiteClass, SelectClasses annotation) { @@ -366,7 +368,7 @@ private static Stream toClassSelectors(Class suiteClass, Selec private MethodSelector selectMethod(Class suiteClass, SelectMethod annotation) { MethodSelector methodSelector = toMethodSelector(suiteClass, annotation); - selectedClassNames.add(methodSelector.getClassName()); + this.selectedClassNames.add(methodSelector.getClassName()); return methodSelector; }