Top Description Fields Constructors Methods
org.junit.platform.testkit.engine

public final Class Events

extends Object
Class Inheritance
Annotations
@API
status:MAINTAINED
since:1.7
Static Imports
java.util.Collections.sort, java.util.function.Predicate.isEqual, org.apiguardian.api.API.Status.MAINTAINED, org.junit.platform.commons.util.FunctionUtils.where, org.junit.platform.testkit.engine.Event.byPayload, .Event.byType

Events is a facade that provides a fluent API for working with events.
Since
1.4

Field Summary

Modifier and TypeField and Description
private final String
private final List<Event>

Constructor Summary

AccessConstructor and Description
pack-priv
Events(Stream<Event> events, String category)

pack-priv
Events(List<Event> events, String category)

Method Summary

Modifier and TypeMethod and Description
public Events

Returns:

the filtered Events; never null
aborted
()

Get the aborted Events contained in this Events object.

public final void
assertEventsMatchExactly(Condition<? super Event>...
the conditions to match against; never null
conditions
)

Assert that all events contained in this Events object exactly match the provided conditions.

private static void
assertEventsMatchExactly(List<Event> events, Condition<? super Event>... conditions)

public final void
assertEventsMatchLoosely(Condition<? super Event>...
the conditions to match against; never null
conditions
)

Assert that all provided conditions are matched by an event contained in this Events object, regardless of order.

private static void
assertEventsMatchLoosely(List<Event> events, Condition<? super Event>... conditions)

public final void
assertEventsMatchLooselyInOrder(Condition<? super Event>...
the conditions to match against; never null
conditions
)

Assert that all provided conditions are matched by an event contained in this Events object.

private static void
assertEventsMatchLooselyInOrder(List<Event> events, Condition<? super Event>... conditions)

public Events

Returns:

this Events object for method chaining; never null
assertStatistics
(Consumer<EventStatistics>
a Consumer of EventStatistics; never null
statisticsConsumer
)

Assert statistics for the events contained in this Events object.

public ListAssert<Event>

Returns:

an instance of ListAssert for events; never null
assertThatEvents
()

Shortcut for org.assertj.core.api.Assertions.assertThat(events.list()).

private static void
checkCondition(List<Event> events, SoftAssertions softly, Condition<? super Event> condition)

public long
count()

Get the number of events contained in this Events object.

public Events

Returns:

this Events object for method chaining; never null
debug
()

Print all events to System#out.

public Events

Returns:

this Events object for method chaining; never null
debug
(OutputStream
the OutputStream to print to; never null
out
)

Print all events to the supplied OutputStream.

public Events

Returns:

this Events object for method chaining; never null
debug
(Writer
the Writer to print to; never null
writer
)

Print all events to the supplied Writer.

private Events
debug(PrintWriter printWriter)

public Events

Returns:

the filtered Events; never null
dynamicallyRegistered
()

Get the dynamic registration Events contained in this Events object.

private Stream<Event>
public Executions

Returns:

an instance of Executions for the current set of events; never null
executions
()

Get the Executions for the current set of events.

public Events

Returns:

the filtered Events; never null
failed
()

Get the failed Events contained in this Events object.

public Events

Returns:

the filtered Events; never null
fileEntryPublished
()

Get the file entry publication Events contained in this Events object.

public Stream<Event>

Returns:

the filtered stream of events; never null
filter
(Predicate<? super Event>
a Predicate to apply to each event to decide if it should be included in the filtered stream; never null
predicate
)

Shortcut for events.stream().filter(predicate).

private static @Nullable Event
findEvent(List<Event> events, SoftAssertions softly, Condition<? super Event> condition)

public Events

Returns:

the filtered Events; never null
finished
()

Get the finished Events contained in this Events object.

private Stream<Event>
pack-priv String
private static boolean
public List<Event>

Returns:

the list of events; never null
list
()

Get the events as a List.

public <R> Stream<R>

Returns:

the mapped stream of events; never null
map
(Function<? super Event, ? extends R>
a Function to apply to each event; never null
mapper
)

Shortcut for events.stream().map(mapper).

public Events

Returns:

the filtered Events; never null
reportingEntryPublished
()

Get the reporting entry publication Events contained in this Events object.

public Events

Returns:

the filtered Events; never null
skipped
()

Get the skipped Events contained in this Events object.

public Events

Returns:

the filtered Events; never null
started
()

Get the started Events contained in this Events object.

public Stream<Event>

Returns:

the stream of events; never null
stream
()

Get the events as a Stream.

public Events

Returns:

the filtered Events; never null
succeeded
()

Get the succeeded Events contained in this Events object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

categoryback to summary
private final String category
eventsback to summary
private final List<Event> events

Constructor Detail

Eventsback to summary
pack-priv Events(Stream<Event> events, String category)
Eventsback to summary
pack-priv Events(List<Event> events, String category)

Method Detail

abortedback to summary
public Events aborted()

Get the aborted Events contained in this Events object.

Returns:Events

the filtered Events; never null

assertEventsMatchExactlyback to summary
public final void assertEventsMatchExactly(Condition<? super Event>... conditions)

Assert that all events contained in this Events object exactly match the provided conditions.

Conditions can be imported statically from EventConditions and TestExecutionResultConditions.

Example

executionResults.testEvents().assertEventsMatchExactly(
    event(test("exampleTestMethod"), started()),
    event(test("exampleTestMethod"), finishedSuccessfully())
);
Parameters
conditions:Condition<? super Event>[]

the conditions to match against; never null

Annotations
@SafeVarargs
See Also
assertEventsMatchLoosely(Condition...), assertEventsMatchLooselyInOrder(Condition...), EventConditions, TestExecutionResultConditions
assertEventsMatchExactlyback to summary
private static void assertEventsMatchExactly(List<Event> events, Condition<? super Event>... conditions)
Annotations
@SafeVarargs
assertEventsMatchLooselyback to summary
public final void assertEventsMatchLoosely(Condition<? super Event>... conditions)

Assert that all provided conditions are matched by an event contained in this Events object, regardless of order.

Note that this method performs a partial match. Thus, some events may not match any of the provided conditions.

Conditions can be imported statically from EventConditions and TestExecutionResultConditions.

Example

executionResults.testEvents().assertEventsMatchLoosely(
    event(test("exampleTestMethod"), started()),
    event(test("exampleTestMethod"), finishedSuccessfully())
);
Parameters
conditions:Condition<? super Event>[]

the conditions to match against; never null

Annotations
@SafeVarargs
@SuppressWarnings:varargs
Since
1.7
See Also
assertEventsMatchExactly(Condition...), assertEventsMatchLooselyInOrder(Condition...), EventConditions, TestExecutionResultConditions
assertEventsMatchLooselyback to summary
private static void assertEventsMatchLoosely(List<Event> events, Condition<? super Event>... conditions)
Annotations
@SafeVarargs
assertEventsMatchLooselyInOrderback to summary
public final void assertEventsMatchLooselyInOrder(Condition<? super Event>... conditions)

Assert that all provided conditions are matched by an event contained in this Events object.

Note that this method performs a partial match. Thus, some events may not match any of the provided conditions; however, the conditions provided must be in the correct order.

Conditions can be imported statically from EventConditions and TestExecutionResultConditions.

Example

executionResults.testEvents().assertEventsMatchLooselyInOrder(
    event(test("exampleTestMethod"), started()),
    event(test("exampleTestMethod"), finishedSuccessfully())
);
Parameters
conditions:Condition<? super Event>[]

the conditions to match against; never null

Annotations
@SafeVarargs
@SuppressWarnings:varargs
Since
1.7
See Also
assertEventsMatchExactly(Condition...), assertEventsMatchLoosely(Condition...), EventConditions, TestExecutionResultConditions
assertEventsMatchLooselyInOrderback to summary
private static void assertEventsMatchLooselyInOrder(List<Event> events, Condition<? super Event>... conditions)
Annotations
@SafeVarargs
@SuppressWarnings:varargs
assertStatisticsback to summary
public Events assertStatistics(Consumer<EventStatistics> statisticsConsumer)

Assert statistics for the events contained in this Events object.

Example

events.assertStatistics(stats -> stats.started(1).succeeded(1).failed(0));

Parameters
statisticsConsumer:Consumer<EventStatistics>

a Consumer of EventStatistics; never null

Returns:Events

this Events object for method chaining; never null

assertThatEventsback to summary
public ListAssert<Event> assertThatEvents()

Shortcut for org.assertj.core.api.Assertions.assertThat(events.list()).

Returns:ListAssert<Event>

an instance of ListAssert for events; never null

See Also
org.assertj.core.api.Assertions#assertThat(List), org.assertj.core.api.ListAssert
checkConditionback to summary
private static void checkCondition(List<Event> events, SoftAssertions softly, Condition<? super Event> condition)
countback to summary
public long count()

Get the number of events contained in this Events object.

debugback to summary
public Events debug()

Print all events to System#out.

Returns:Events

this Events object for method chaining; never null

debugback to summary
public Events debug(OutputStream out)

Print all events to the supplied OutputStream.

Parameters
out:OutputStream

the OutputStream to print to; never null

Returns:Events

this Events object for method chaining; never null

Annotations
@SuppressWarnings:DefaultCharset
debugback to summary
public Events debug(Writer writer)

Print all events to the supplied Writer.

Parameters
writer:Writer

the Writer to print to; never null

Returns:Events

this Events object for method chaining; never null

debugback to summary
private Events debug(PrintWriter printWriter)
dynamicallyRegisteredback to summary
public Events dynamicallyRegistered()

Get the dynamic registration Events contained in this Events object.

Returns:Events

the filtered Events; never null

eventsByTypeback to summary
private Stream<Event> eventsByType(EventType type)
executionsback to summary
public Executions executions()

Get the Executions for the current set of events.

Returns:Executions

an instance of Executions for the current set of events; never null

failedback to summary
public Events failed()

Get the failed Events contained in this Events object.

Returns:Events

the filtered Events; never null

fileEntryPublishedback to summary
public Events fileEntryPublished()

Get the file entry publication Events contained in this Events object.

Returns:Events

the filtered Events; never null

Annotations
@API
status:MAINTAINED
since:1.13.3
Since
1.12
filterback to summary
public Stream<Event> filter(Predicate<? super Event> predicate)

Shortcut for events.stream().filter(predicate).

Parameters
predicate:Predicate<? super Event>

a Predicate to apply to each event to decide if it should be included in the filtered stream; never null

Returns:Stream<Event>

the filtered stream of events; never null

See Also
stream(), Stream#filter(Predicate)
findEventback to summary
private static @Nullable Event findEvent(List<Event> events, SoftAssertions softly, Condition<? super Event> condition)
finishedback to summary
public Events finished()

Get the finished Events contained in this Events object.

Returns:Events

the filtered Events; never null

finishedEventsByStatusback to summary
private Stream<Event> finishedEventsByStatus(TestExecutionResult.Status status)
getCategoryback to summary
pack-priv String getCategory()
isNotInIncreasingOrderback to summary
private static boolean isNotInIncreasingOrder(List<Integer> indices)
listback to summary
public List<Event> list()

Get the events as a List.

Returns:List<Event>

the list of events; never null

See Also
stream()
mapback to summary
public <R> Stream<R> map(Function<? super Event, ? extends R> mapper)

Shortcut for events.stream().map(mapper).

Parameters
mapper:Function<? super Event, ? extends R>

a Function to apply to each event; never null

Returns:Stream<R>

the mapped stream of events; never null

See Also
stream(), Stream#map(Function)
reportingEntryPublishedback to summary
public Events reportingEntryPublished()

Get the reporting entry publication Events contained in this Events object.

Returns:Events

the filtered Events; never null

skippedback to summary
public Events skipped()

Get the skipped Events contained in this Events object.

Returns:Events

the filtered Events; never null

startedback to summary
public Events started()

Get the started Events contained in this Events object.

Returns:Events

the filtered Events; never null

streamback to summary
public Stream<Event> stream()

Get the events as a Stream.

Returns:Stream<Event>

the stream of events; never null

See Also
list()
succeededback to summary
public Events succeeded()

Get the succeeded Events contained in this Events object.

Returns:Events

the filtered Events; never null