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

public Class Event

extends Object
Class Inheritance
Annotations
@API
status:MAINTAINED
since:1.7
Static Imports
org.apiguardian.api.API.Status.MAINTAINED, org.junit.platform.commons.util.FunctionUtils.where

Event represents a single event fired during execution of a test plan on the JUnit Platform.
Since
1.4
See Also
EventType

Field Summary

Modifier and TypeField and Description
private final @Nullable Object
private final TestDescriptor
private final Instant
private final EventType

Constructor Summary

AccessConstructor and Description
private
Event(EventType
the type of the event; never null
type
,
TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
,
@Nullable Object
the generic payload associated with the event; may be null
payload
)

Construct an Event with the supplied arguments.

Method Summary

Modifier and TypeMethod and Description
public static <T> Predicate<Event>

Returns:

the resulting Predicate
byPayload
(Class<T>
the required payload type
payloadType
,
Predicate<? super T>
a Predicate to match against payloads
payloadPredicate
)

Create a Predicate for events whose payload types match the supplied payloadType and whose payloads match the supplied payloadPredicate.

public static Predicate<Event>

Returns:

the resulting Predicate
byTestDescriptor
(Predicate<? super TestDescriptor>
a Predicate to match against test descriptors
testDescriptorPredicate
)

Create a Predicate for events whose TestDescriptors match the supplied testDescriptorPredicate.

public static Predicate<Event>

Returns:

the resulting Predicate
byType
(EventType
the type to match against
type
)

Create a Predicate for events whose event types match the supplied type.

public static Event

Returns:

the newly created Event
dynamicTestRegistered
(TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
)

Create an Event for the dynamic registration of the supplied TestDescriptor.

public static Event

Returns:

the newly created Event
executionFinished
(TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
,
TestExecutionResult
the TestExecutionResult for the supplied TestDescriptor; never null
result
)

Create a finished Event for the supplied TestDescriptor and TestExecutionResult.

public static Event

Returns:

the newly created Event
executionSkipped
(TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
,
@Nullable String
the reason the execution was skipped; may be null
reason
)

Create a skipped Event for the supplied TestDescriptor and reason.

public static Event

Returns:

the newly created Event
executionStarted
(TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
)

Create a started Event for the supplied TestDescriptor.

public static Event

Returns:

the newly created Event
fileEntryPublished
(TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
,
FileEntry
the FileEntry that was published; never null
file
)

Create an Event for a published file for the supplied TestDescriptor and FileEntry.

public Optional<Object>

Returns:

an Optional containing the payload; never null but potentially empty
getPayload
()

Get the payload, if available.

public <T> Optional<T>

Returns:

an Optional containing the payload; never null but potentially empty
getPayload
(Class<T>
the expected payload type; never null
payloadType
)

Get the payload of the expected type, if available.

public <T> T

Returns:

the payload
getRequiredPayload
(Class<T>
the required payload type; never null
payloadType
)

Get the payload of the required type.

public TestDescriptor

Returns:

the TestDescriptor; never null
getTestDescriptor
()

Get the TestDescriptor associated with this Event.

public Instant

Returns:

the Instant when this Event occurred; never null
getTimestamp
()

Get the Instant when this Event occurred.

public EventType

Returns:

the event type; never null
getType
()

Get the type of this Event.

public static Event

Returns:

the newly created Event
reportingEntryPublished
(TestDescriptor
the TestDescriptor associated with the event; never null
testDescriptor
,
ReportEntry
the ReportEntry that was published; never null
entry
)

Create an Event for a reporting entry published for the supplied TestDescriptor and ReportEntry.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

payloadback to summary
private final @Nullable Object payload
testDescriptorback to summary
private final TestDescriptor testDescriptor
timestampback to summary
private final Instant timestamp
typeback to summary
private final EventType type

Constructor Detail

Eventback to summary
private Event(EventType type, TestDescriptor testDescriptor, @Nullable Object payload)

Construct an Event with the supplied arguments.

Parameters
type:EventType

the type of the event; never null

testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

payload:@Nullable Object

the generic payload associated with the event; may be null

Method Detail

byPayloadback to summary
public static <T> Predicate<Event> byPayload(Class<T> payloadType, Predicate<? super T> payloadPredicate)

Create a Predicate for events whose payload types match the supplied payloadType and whose payloads match the supplied payloadPredicate.

Parameters
payloadType:Class<T>

the required payload type

payloadPredicate:Predicate<? super T>

a Predicate to match against payloads

Returns:Predicate<Event>

the resulting Predicate

byTestDescriptorback to summary
public static Predicate<Event> byTestDescriptor(Predicate<? super TestDescriptor> testDescriptorPredicate)

Create a Predicate for events whose TestDescriptors match the supplied testDescriptorPredicate.

Parameters
testDescriptorPredicate:Predicate<? super TestDescriptor>

a Predicate to match against test descriptors

Returns:Predicate<Event>

the resulting Predicate

byTypeback to summary
public static Predicate<Event> byType(EventType type)

Create a Predicate for events whose event types match the supplied type.

Parameters
type:EventType

the type to match against

Returns:Predicate<Event>

the resulting Predicate

dynamicTestRegisteredback to summary
public static Event dynamicTestRegistered(TestDescriptor testDescriptor)

Create an Event for the dynamic registration of the supplied TestDescriptor.

Parameters
testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

Returns:Event

the newly created Event

See Also
EventType#DYNAMIC_TEST_REGISTERED
executionFinishedback to summary
public static Event executionFinished(TestDescriptor testDescriptor, TestExecutionResult result)

Create a finished Event for the supplied TestDescriptor and TestExecutionResult.

Parameters
testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

result:TestExecutionResult

the TestExecutionResult for the supplied TestDescriptor; never null

Returns:Event

the newly created Event

See Also
EventType#FINISHED
executionSkippedback to summary
public static Event executionSkipped(TestDescriptor testDescriptor, @Nullable String reason)

Create a skipped Event for the supplied TestDescriptor and reason.

Parameters
testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

reason:@Nullable String

the reason the execution was skipped; may be null

Returns:Event

the newly created Event

See Also
EventType#SKIPPED
executionStartedback to summary
public static Event executionStarted(TestDescriptor testDescriptor)

Create a started Event for the supplied TestDescriptor.

Parameters
testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

Returns:Event

the newly created Event

See Also
EventType#STARTED
fileEntryPublishedback to summary
public static Event fileEntryPublished(TestDescriptor testDescriptor, FileEntry file)

Create an Event for a published file for the supplied TestDescriptor and FileEntry.

Parameters
testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

file:FileEntry

the FileEntry that was published; never null

Returns:Event

the newly created Event

Annotations
@API
status:MAINTAINED
since:1.13.3
Since
1.12
See Also
EventType#FILE_ENTRY_PUBLISHED
getPayloadback to summary
public Optional<Object> getPayload()

Get the payload, if available.

Returns:Optional<Object>

an Optional containing the payload; never null but potentially empty

See Also
getPayload(Class), getRequiredPayload(Class)
getPayloadback to summary
public <T> Optional<T> getPayload(Class<T> payloadType)

Get the payload of the expected type, if available.

This is a convenience method that automatically casts the payload to the expected type. If the payload is not present or is not of the expected type, this method will return Optional#empty().

Parameters
payloadType:Class<T>

the expected payload type; never null

Returns:Optional<T>

an Optional containing the payload; never null but potentially empty

See Also
getPayload(), getRequiredPayload(Class)
getRequiredPayloadback to summary
public <T> T getRequiredPayload(Class<T> payloadType) throws IllegalArgumentException

Get the payload of the required type.

This is a convenience method that automatically casts the payload to the required type. If the payload is not present or is not of the expected type, this method will throw an IllegalArgumentException.

Parameters
payloadType:Class<T>

the required payload type; never null

Returns:T

the payload

Exceptions
IllegalArgumentException:
if the payload is of a different type or is not present
See Also
getPayload(), getPayload(Class)
getTestDescriptorback to summary
public TestDescriptor getTestDescriptor()

Get the TestDescriptor associated with this Event.

Returns:TestDescriptor

the TestDescriptor; never null

getTimestampback to summary
public Instant getTimestamp()

Get the Instant when this Event occurred.

Returns:Instant

the Instant when this Event occurred; never null

getTypeback to summary
public EventType getType()

Get the type of this Event.

Returns:EventType

the event type; never null

See Also
EventType
reportingEntryPublishedback to summary
public static Event reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)

Create an Event for a reporting entry published for the supplied TestDescriptor and ReportEntry.

Parameters
testDescriptor:TestDescriptor

the TestDescriptor associated with the event; never null

entry:ReportEntry

the ReportEntry that was published; never null

Returns:Event

the newly created Event

See Also
EventType#REPORTING_ENTRY_PUBLISHED
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override