@API(status=MAINTAINED,
since="1.7")
public class Event
extends java.lang.Object
Event represents a single event fired during execution of
a test plan on the JUnit Platform.EventType| Modifier and Type | Field and Description |
|---|---|
private java.lang.Object |
payload |
private TestDescriptor |
testDescriptor |
private java.time.Instant |
timestamp |
private EventType |
type |
| Modifier | Constructor and Description |
|---|---|
private |
Event(EventType type,
TestDescriptor testDescriptor,
java.lang.Object payload)
Construct an
Event with the supplied arguments. |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.function.Predicate<Event> |
byPayload(java.lang.Class<T> payloadType,
java.util.function.Predicate<? super T> payloadPredicate)
Create a
Predicate for events whose payload
types match the supplied payloadType and whose payloads match the
supplied payloadPredicate. |
static java.util.function.Predicate<Event> |
byTestDescriptor(java.util.function.Predicate<? super TestDescriptor> testDescriptorPredicate)
|
static java.util.function.Predicate<Event> |
byType(EventType type)
|
static Event |
dynamicTestRegistered(TestDescriptor testDescriptor)
Create an
Event for the dynamic registration of the
supplied TestDescriptor. |
static Event |
executionFinished(TestDescriptor testDescriptor,
TestExecutionResult result)
|
static Event |
executionSkipped(TestDescriptor testDescriptor,
java.lang.String reason)
|
static Event |
executionStarted(TestDescriptor testDescriptor)
Create a started
Event for the supplied
TestDescriptor. |
java.util.Optional<java.lang.Object> |
getPayload()
Get the payload, if available.
|
<T> java.util.Optional<T> |
getPayload(java.lang.Class<T> payloadType)
Get the payload of the expected type, if available.
|
<T> T |
getRequiredPayload(java.lang.Class<T> payloadType)
Get the payload of the required type.
|
TestDescriptor |
getTestDescriptor()
Get the
TestDescriptor associated with this Event. |
java.time.Instant |
getTimestamp()
Get the
Instant when this Event occurred. |
EventType |
getType()
Get the type of this
Event. |
static Event |
reportingEntryPublished(TestDescriptor testDescriptor,
ReportEntry entry)
|
java.lang.String |
toString() |
private final java.time.Instant timestamp
private final EventType type
private final TestDescriptor testDescriptor
private final java.lang.Object payload
private Event(EventType type, TestDescriptor testDescriptor, java.lang.Object payload)
Event with the supplied arguments.type - the type of the event; never nulltestDescriptor - the TestDescriptor associated with the event;
never nullpayload - the generic payload associated with the event; may be nullpublic static Event reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)
testDescriptor - the TestDescriptor associated with the event;
never nullentry - the ReportEntry that was published; never nullEventEventType.REPORTING_ENTRY_PUBLISHEDpublic static Event dynamicTestRegistered(TestDescriptor testDescriptor)
Event for the dynamic registration of the
supplied TestDescriptor.testDescriptor - the TestDescriptor associated with the event;
never nullEventEventType.DYNAMIC_TEST_REGISTEREDpublic static Event executionSkipped(TestDescriptor testDescriptor, java.lang.String reason)
testDescriptor - the TestDescriptor associated with the event;
never nullreason - the reason the execution was skipped; may be nullEventEventType.SKIPPEDpublic static Event executionStarted(TestDescriptor testDescriptor)
Event for the supplied
TestDescriptor.testDescriptor - the TestDescriptor associated with the
event; never nullEventEventType.STARTEDpublic static Event executionFinished(TestDescriptor testDescriptor, TestExecutionResult result)
testDescriptor - the TestDescriptor associated with the
event; never nullresult - the TestExecutionResult for the supplied
TestDescriptor; never nullEventEventType.FINISHEDpublic static <T> java.util.function.Predicate<Event> byPayload(java.lang.Class<T> payloadType, java.util.function.Predicate<? super T> payloadPredicate)
Predicate for events whose payload
types match the supplied payloadType and whose payloads match the
supplied payloadPredicate.payloadType - the required payload typepayloadPredicate - a Predicate to match against payloadsPredicatepublic static java.util.function.Predicate<Event> byType(EventType type)
type - the type to match againstPredicatepublic static java.util.function.Predicate<Event> byTestDescriptor(java.util.function.Predicate<? super TestDescriptor> testDescriptorPredicate)
testDescriptorPredicate - a Predicate to match against test
descriptorsPredicatepublic EventType getType()
Event.nullEventTypepublic TestDescriptor getTestDescriptor()
TestDescriptor associated with this Event.TestDescriptor; never nullpublic java.time.Instant getTimestamp()
Instant when this Event occurred.Instant when this Event occurred;
never nullpublic java.util.Optional<java.lang.Object> getPayload()
Optional containing the payload; never null
but potentially emptygetPayload(Class),
getRequiredPayload(Class)public <T> java.util.Optional<T> getPayload(java.lang.Class<T> payloadType)
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().
payloadType - the expected payload type; never nullOptional containing the payload; never null
but potentially emptygetPayload(),
getRequiredPayload(Class)public <T> T getRequiredPayload(java.lang.Class<T> payloadType)
throws java.lang.IllegalArgumentException
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.
payloadType - the required payload type; never nulljava.lang.IllegalArgumentException - if the payload is of a different type
or is not presentgetPayload(),
getPayload(Class)public java.lang.String toString()
toString in class java.lang.Object