Class Event
- java.lang.Object
-
- org.junit.platform.testkit.engine.Event
-
@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.- Since:
- 1.4
- See Also:
EventType
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
payload
private TestDescriptor
testDescriptor
private java.time.Instant
timestamp
private EventType
type
-
Constructor Summary
Constructors Modifier Constructor Description private
Event(EventType type, TestDescriptor testDescriptor, java.lang.Object payload)
Construct anEvent
with the supplied arguments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> java.util.function.Predicate<Event>
byPayload(java.lang.Class<T> payloadType, java.util.function.Predicate<? super T> payloadPredicate)
Create aPredicate
for events whose payload types match the suppliedpayloadType
and whose payloads match the suppliedpayloadPredicate
.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 anEvent
for the dynamic registration of the suppliedTestDescriptor
.static Event
executionFinished(TestDescriptor testDescriptor, TestExecutionResult result)
static Event
executionSkipped(TestDescriptor testDescriptor, java.lang.String reason)
static Event
executionStarted(TestDescriptor testDescriptor)
Create a startedEvent
for the suppliedTestDescriptor
.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 theTestDescriptor
associated with thisEvent
.java.time.Instant
getTimestamp()
Get theInstant
when thisEvent
occurred.EventType
getType()
Get the type of thisEvent
.static Event
reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)
java.lang.String
toString()
-
-
-
Field Detail
-
timestamp
private final java.time.Instant timestamp
-
type
private final EventType type
-
testDescriptor
private final TestDescriptor testDescriptor
-
payload
private final java.lang.Object payload
-
-
Constructor Detail
-
Event
private Event(EventType type, TestDescriptor testDescriptor, java.lang.Object payload)
Construct anEvent
with the supplied arguments.- Parameters:
type
- the type of the event; nevernull
testDescriptor
- theTestDescriptor
associated with the event; nevernull
payload
- the generic payload associated with the event; may benull
-
-
Method Detail
-
reportingEntryPublished
public static Event reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)
- Parameters:
testDescriptor
- theTestDescriptor
associated with the event; nevernull
entry
- theReportEntry
that was published; nevernull
- Returns:
- the newly created
Event
- See Also:
EventType.REPORTING_ENTRY_PUBLISHED
-
dynamicTestRegistered
public static Event dynamicTestRegistered(TestDescriptor testDescriptor)
Create anEvent
for the dynamic registration of the suppliedTestDescriptor
.- Parameters:
testDescriptor
- theTestDescriptor
associated with the event; nevernull
- Returns:
- the newly created
Event
- See Also:
EventType.DYNAMIC_TEST_REGISTERED
-
executionSkipped
public static Event executionSkipped(TestDescriptor testDescriptor, java.lang.String reason)
- Parameters:
testDescriptor
- theTestDescriptor
associated with the event; nevernull
reason
- the reason the execution was skipped; may benull
- Returns:
- the newly created
Event
- See Also:
EventType.SKIPPED
-
executionStarted
public static Event executionStarted(TestDescriptor testDescriptor)
Create a startedEvent
for the suppliedTestDescriptor
.- Parameters:
testDescriptor
- theTestDescriptor
associated with the event; nevernull
- Returns:
- the newly created
Event
- See Also:
EventType.STARTED
-
executionFinished
public static Event executionFinished(TestDescriptor testDescriptor, TestExecutionResult result)
- Parameters:
testDescriptor
- theTestDescriptor
associated with the event; nevernull
result
- theTestExecutionResult
for the suppliedTestDescriptor
; nevernull
- Returns:
- the newly created
Event
- See Also:
EventType.FINISHED
-
byPayload
public static <T> java.util.function.Predicate<Event> byPayload(java.lang.Class<T> payloadType, java.util.function.Predicate<? super T> payloadPredicate)
Create aPredicate
for events whose payload types match the suppliedpayloadType
and whose payloads match the suppliedpayloadPredicate
.- Parameters:
payloadType
- the required payload typepayloadPredicate
- aPredicate
to match against payloads- Returns:
- the resulting
Predicate
-
byType
public static java.util.function.Predicate<Event> byType(EventType type)
- Parameters:
type
- the type to match against- Returns:
- the resulting
Predicate
-
byTestDescriptor
public static java.util.function.Predicate<Event> byTestDescriptor(java.util.function.Predicate<? super TestDescriptor> testDescriptorPredicate)
- Parameters:
testDescriptorPredicate
- aPredicate
to match against test descriptors- Returns:
- the resulting
Predicate
-
getType
public EventType getType()
Get the type of thisEvent
.- Returns:
- the event type; never
null
- See Also:
EventType
-
getTestDescriptor
public TestDescriptor getTestDescriptor()
Get theTestDescriptor
associated with thisEvent
.- Returns:
- the
TestDescriptor
; nevernull
-
getTimestamp
public java.time.Instant getTimestamp()
Get theInstant
when thisEvent
occurred.- Returns:
- the
Instant
when thisEvent
occurred; nevernull
-
getPayload
public java.util.Optional<java.lang.Object> getPayload()
Get the payload, if available.- Returns:
- an
Optional
containing the payload; nevernull
but potentially empty - See Also:
getPayload(Class)
,getRequiredPayload(Class)
-
getPayload
public <T> java.util.Optional<T> getPayload(java.lang.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
- the expected payload type; nevernull
- Returns:
- an
Optional
containing the payload; nevernull
but potentially empty - See Also:
getPayload()
,getRequiredPayload(Class)
-
getRequiredPayload
public <T> T getRequiredPayload(java.lang.Class<T> payloadType) throws java.lang.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
- the required payload type; nevernull
- Returns:
- the payload
- Throws:
java.lang.IllegalArgumentException
- if the payload is of a different type or is not present- See Also:
getPayload()
,getPayload(Class)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-