Skip to content

Commit c9e66fc

Browse files
Ertjon Meckasbrannen
authored andcommitted
Document SuiteLauncherDiscoveryRequestBuilder
Closes #3702
1 parent 842fd0d commit c9e66fc

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* selectMethod("org.example.order.OrderTests", "test4"),
5959
* selectMethod(OrderTests.class, "test5"),
6060
* selectMethod(OrderTests.class, testMethod),
61-
* selectClasspathRoots(Collections.singleton(new File("/my/local/path1"))),
61+
* selectClasspathRoots(Collections.singleton(Paths.get("/my/local/path1"))),
6262
* selectUniqueId("unique-id-1"),
6363
* selectUniqueId("unique-id-2")
6464
* )

junit-platform-suite-commons/src/main/java/org/junit/platform/suite/commons/SuiteLauncherDiscoveryRequestBuilder.java

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,46 @@
6565
import org.junit.platform.suite.api.SelectUris;
6666

6767
/**
68+
* The {@code SuiteLauncherDiscoveryRequestBuilder} provides a builder for constructing instances
69+
* of {@link LauncherDiscoveryRequest} specifically tailored for suite execution.
70+
*
71+
* <h2>Example</h2>
72+
*
73+
* <pre>{@code
74+
* SuiteLauncherDiscoveryRequestBuilder.request()
75+
* .selectors(
76+
* selectPackage("org.example.user"),
77+
* selectClass("org.example.payment.PaymentTests"),
78+
* selectClass(File.class),
79+
* selectMethod("org.example.order.OrderTests#test1"),
80+
* selectMethod("org.example.order.OrderTests#test2()"),
81+
* selectMethod("org.example.order.OrderTests#test3(java.lang.String)"),
82+
* selectMethod("org.example.order.OrderTests", "test4"),
83+
* selectMethod(OrderTests.class, "test5"),
84+
* selectMethod(OrderTests.class, testMethod),
85+
* selectClasspathRoots(Collections.singleton(Paths.get("/my/local/path1"))),
86+
* selectUniqueId("unique-id-1"),
87+
* selectUniqueId("unique-id-2")
88+
* )
89+
* .filters(
90+
* includeEngines("junit-jupiter", "spek"),
91+
* // excludeEngines("junit-vintage"),
92+
* includeTags("fast"),
93+
* // excludeTags("slow"),
94+
* includeClassNamePatterns(".*Test[s]?")
95+
* // includeClassNamePatterns("org\.example\.tests.*")
96+
* )
97+
* .configurationParameter("key", "value")
98+
* .enableImplicitConfigurationParameters(true)
99+
* .suite(File.class)
100+
* .build();
101+
* }</pre>
102+
*
68103
* @since 1.8
104+
* @see org.junit.platform.engine.discovery.DiscoverySelectors
105+
* @see org.junit.platform.engine.discovery.ClassNameFilter
106+
* @see org.junit.platform.launcher.EngineFilter
107+
* @see org.junit.platform.launcher.TagFilter
69108
*/
70109
@API(status = Status.INTERNAL, since = "1.8", consumers = { "org.junit.platform.suite.engine",
71110
"org.junit.platform.runner" })
@@ -81,52 +120,146 @@ public final class SuiteLauncherDiscoveryRequestBuilder {
81120
private SuiteLauncherDiscoveryRequestBuilder() {
82121
}
83122

123+
/**
124+
* Creates a mew instance of {@code SuiteLauncherDiscoveryRequestBuilder}
125+
*
126+
* @return a new builder
127+
*/
84128
public static SuiteLauncherDiscoveryRequestBuilder request() {
85129
return new SuiteLauncherDiscoveryRequestBuilder();
86130
}
87131

132+
/**
133+
* Specifies whether to filter standard class name patterns.
134+
* <p>If set to {@code true}, standard class name patterns are filtered.
135+
*
136+
* @param filterStandardClassNamePatterns {@code true} to filter standard class name patterns,
137+
* {@code false} otherwise
138+
* @return this builder for method chaining
139+
*/
88140
public SuiteLauncherDiscoveryRequestBuilder filterStandardClassNamePatterns(
89141
boolean filterStandardClassNamePatterns) {
90142
this.filterStandardClassNamePatterns = filterStandardClassNamePatterns;
91143
return this;
92144
}
93145

146+
/**
147+
* Add all the supplied {@code selectors} to the request.
148+
*
149+
* @param selectors the {@code DiscoverySelectors} to add; never {@code null}
150+
* @return this builder for method chaining
151+
*/
94152
public SuiteLauncherDiscoveryRequestBuilder selectors(DiscoverySelector... selectors) {
95153
delegate.selectors(selectors);
96154
return this;
97155
}
98156

157+
/**
158+
* Add all the supplied {@code selectors} to the request.
159+
*
160+
* @param selectors the {@code DiscoverySelectors} to add; never {@code null}
161+
* @return this builder for method chaining
162+
*/
99163
public SuiteLauncherDiscoveryRequestBuilder selectors(List<? extends DiscoverySelector> selectors) {
100164
delegate.selectors(selectors);
101165
return this;
102166
}
103167

168+
/**
169+
* Add all the supplied {@code filters} to the request.
170+
*
171+
* <p>The {@code filters} are combined using AND semantics, i.e. all of them
172+
* have to include a resource for it to end up in the test plan.
173+
*
174+
* <p><strong>Warning</strong>: be cautious when registering multiple competing
175+
* {@link EngineFilter#includeEngines include} {@code EngineFilters} or multiple
176+
* competing {@link EngineFilter#excludeEngines exclude} {@code EngineFilters}
177+
* for the same discovery request since doing so will likely lead to
178+
* undesirable results (i.e., zero engines being active).
179+
*
180+
* @param filters the {@code Filter}s to add; never {@code null}
181+
* @return this builder for method chaining
182+
*/
104183
public SuiteLauncherDiscoveryRequestBuilder filters(Filter<?>... filters) {
105184
delegate.filters(filters);
106185
return this;
107186
}
108187

188+
/**
189+
* Add the supplied <em>configuration parameter</em> to the request.
190+
*
191+
* @param key the configuration parameter key under which to store the
192+
* value; never {@code null} or blank
193+
* @param value the value to store
194+
* @return this builder for method chaining
195+
*/
109196
public SuiteLauncherDiscoveryRequestBuilder configurationParameter(String key, String value) {
110197
delegate.configurationParameter(key, value);
111198
return this;
112199
}
113200

201+
/**
202+
* Add all the supplied configuration parameters to the request.
203+
*
204+
* @param configurationParameters the map of configuration parameters to add;
205+
* never {@code null}
206+
* @return this builder for method chaining
207+
* @see #configurationParameter(String, String)
208+
*/
114209
public SuiteLauncherDiscoveryRequestBuilder configurationParameters(Map<String, String> configurationParameters) {
115210
delegate.configurationParameters(configurationParameters);
116211
return this;
117212
}
118213

214+
/**
215+
* Set the parent configuration parameters to use for the request.
216+
*
217+
* <p>Any explicit configuration parameters configured via
218+
* {@link #configurationParameter(String, String)} or
219+
* {@link #configurationParameters(Map)} takes precedence over the supplied
220+
* configuration parameters.
221+
*
222+
* @param parentConfigurationParameters the parent instance to be used for looking
223+
* up configuration parameters that have not been explicitly configured;
224+
* never {@code null}
225+
* @return this builder for method chaining
226+
*
227+
* @see #configurationParameter(String, String)
228+
* @see #configurationParameters(Map)
229+
*/
119230
public SuiteLauncherDiscoveryRequestBuilder parentConfigurationParameters(
120231
ConfigurationParameters parentConfigurationParameters) {
121232
this.parentConfigurationParameters = parentConfigurationParameters;
122233
return this;
123234
}
124235

236+
/**
237+
* Configure whether implicit configuration parameters should be considered.
238+
*
239+
* <p>By default, in addition to those parameters that are passed explicitly
240+
* to this builder, configuration parameters are read from system properties
241+
* and from the {@code junit-platform.properties} classpath resource.
242+
* Passing {@code false} to this method, disables the latter two sources so
243+
* that only explicit configuration parameters are taken into account.
244+
* @return this builder for method chaining
245+
*
246+
* @see #configurationParameter(String, String)
247+
* @see #configurationParameters(Map)
248+
*/
125249
public SuiteLauncherDiscoveryRequestBuilder enableImplicitConfigurationParameters(boolean enabled) {
126250
delegate.enableImplicitConfigurationParameters(enabled);
127251
return this;
128252
}
129253

254+
/**
255+
* Configures the suite class for the suite launcher discovery request.
256+
*
257+
* <p>This method processes annotations on the suite class to customize
258+
* the suite discovery and execution.
259+
*
260+
* @param suiteClass the suite class to configure
261+
* @return this builder for method chaining
262+
*/
130263
public SuiteLauncherDiscoveryRequestBuilder suite(Class<?> suiteClass) {
131264
Preconditions.notNull(suiteClass, "Suite class must not be null");
132265

@@ -198,6 +331,10 @@ public SuiteLauncherDiscoveryRequestBuilder suite(Class<?> suiteClass) {
198331
return this;
199332
}
200333

334+
/**
335+
* Build the {@link LauncherDiscoveryRequest} that has been configured via
336+
* this builder.
337+
*/
201338
public LauncherDiscoveryRequest build() {
202339
if (filterStandardClassNamePatterns && !includeClassNamePatternsUsed) {
203340
delegate.filters(createIncludeClassNameFilter(STANDARD_INCLUDE_PATTERN));

0 commit comments

Comments
 (0)