Skip to content

Commit c659dd3

Browse files
committed
Document & enforce preconditions in Events & Executions in Test Kit
Issue: #1621
1 parent 14aa558 commit c659dd3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public Stream<Event> stream() {
9090
/**
9191
* Shortcut for {@code events.stream().map(mapper)}.
9292
*
93+
* @param mapper a {@code Function} to apply to each event; never {@code null}
94+
* @return the mapped stream of events; never {@code null}
9395
* @see #stream()
9496
* @see Stream#map(Function)
9597
*/
@@ -101,6 +103,9 @@ public <R> Stream<R> map(Function<? super Event, ? extends R> mapper) {
101103
/**
102104
* Shortcut for {@code events.stream().filter(predicate)}.
103105
*
106+
* @param predicate a {@code Predicate} to apply to each event to decide if
107+
* it should be included in the filtered stream; never {@code null}
108+
* @return the filtered stream of events; never {@code null}
104109
* @see #stream()
105110
* @see Stream#filter(Predicate)
106111
*/
@@ -216,10 +221,12 @@ public Events dynamicallyRegistered() {
216221
*
217222
* <p>{@code events.assertStatistics(stats -> stats.started(1).succeeded(1).failed(0));}
218223
*
219-
* @param statisticsConsumer a consumer of {@link EventStatistics}
224+
* @param statisticsConsumer a {@link Consumer} of {@link EventStatistics};
225+
* never {@code null}
220226
* @return this {@code Events} object for method chaining; never {@code null}
221227
*/
222228
public Events assertStatistics(Consumer<EventStatistics> statisticsConsumer) {
229+
Preconditions.notNull(statisticsConsumer, "Consumer must not be null");
223230
EventStatistics eventStatistics = new EventStatistics(this, this.category);
224231
statisticsConsumer.accept(eventStatistics);
225232
eventStatistics.assertAll();
@@ -242,20 +249,20 @@ public Events assertStatistics(Consumer<EventStatistics> statisticsConsumer) {
242249
* );
243250
* </pre>
244251
*
245-
* @param conditions the conditions to match against
252+
* @param conditions the conditions to match against; never {@code null}
246253
* @see EventConditions
247254
* @see TestExecutionResultConditions
248255
*/
249256
@SafeVarargs
250257
public final void assertEventsMatchExactly(Condition<? super Event>... conditions) {
258+
Preconditions.notNull(conditions, "conditions must not be null");
251259
assertEventsMatchExactly(this.events, conditions);
252260
}
253261

254262
/**
255263
* Shortcut for {@code org.assertj.core.api.Assertions.assertThat(events.list())}.
256264
*
257-
* @return an instance of {@link ListAssert} for events; never
258-
* {@code null}
265+
* @return an instance of {@link ListAssert} for events; never {@code null}
259266
* @see org.assertj.core.api.Assertions#assertThat(List)
260267
* @see org.assertj.core.api.ListAssert
261268
*/
@@ -278,19 +285,23 @@ public Events debug() {
278285
/**
279286
* Print all events to the supplied {@link OutputStream}.
280287
*
288+
* @param out the {@code OutputStream} to print to; never {@code null}
281289
* @return this {@code Events} object for method chaining; never {@code null}
282290
*/
283291
public Events debug(OutputStream out) {
292+
Preconditions.notNull(out, "OutputStream must not be null");
284293
debug(new PrintWriter(out, true));
285294
return this;
286295
}
287296

288297
/**
289298
* Print all events to the supplied {@link Writer}.
290299
*
300+
* @param writer the {@code Writer} to print to; never {@code null}
291301
* @return this {@code Events} object for method chaining; never {@code null}
292302
*/
293303
public Events debug(Writer writer) {
304+
Preconditions.notNull(writer, "Writer must not be null");
294305
debug(new PrintWriter(writer, true));
295306
return this;
296307
}

junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Executions.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public Stream<Execution> stream() {
8585
/**
8686
* Shortcut for {@code executions.stream().map(mapper)}.
8787
*
88+
* @param mapper a {@code Function} to apply to each execution;
89+
* never {@code null}
90+
* @return the mapped stream of executions; never {@code null}
8891
* @see #stream()
8992
* @see Stream#map(Function)
9093
*/
@@ -96,6 +99,9 @@ public <R> Stream<R> map(Function<? super Execution, ? extends R> mapper) {
9699
/**
97100
* Shortcut for {@code executions.stream().filter(predicate)}.
98101
*
102+
* @param predicate a {@code Predicate} to apply to each execution to decide
103+
* if it should be included in the filtered stream; never {@code null}
104+
* @return the filtered stream of executions; never {@code null}
99105
* @see #stream()
100106
* @see Stream#filter(Predicate)
101107
*/
@@ -198,26 +204,30 @@ public Executions debug() {
198204
/**
199205
* Print all executions to the supplied {@link OutputStream}.
200206
*
207+
* @param out the {@code OutputStream} to print to; never {@code null}
201208
* @return this {@code Executions} object for method chaining; never {@code null}
202209
*/
203210
public Executions debug(OutputStream out) {
211+
Preconditions.notNull(out, "OutputStream must not be null");
204212
debug(new PrintWriter(out, true));
205213
return this;
206214
}
207215

208216
/**
209217
* Print all executions to the supplied {@link Writer}.
210218
*
219+
* @param writer the {@code Writer} to print to; never {@code null}
211220
* @return this {@code Executions} object for method chaining; never {@code null}
212221
*/
213222
public Executions debug(Writer writer) {
223+
Preconditions.notNull(writer, "Writer must not be null");
214224
debug(new PrintWriter(writer, true));
215225
return this;
216226
}
217227

218228
private Executions debug(PrintWriter printWriter) {
219229
printWriter.println(this.category + " Executions:");
220-
this.executions.forEach(event -> printWriter.printf("\t%s%n", event));
230+
this.executions.forEach(execution -> printWriter.printf("\t%s%n", execution));
221231
return this;
222232
}
223233

0 commit comments

Comments
 (0)