Class Event
- java.lang.Object
-
- org.junit.platform.testkit.engine.Event
-
@API(status=MAINTAINED, since="1.7") public class Event extends java.lang.ObjectEventrepresents 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.Objectpayloadprivate TestDescriptortestDescriptorprivate java.time.Instanttimestampprivate EventTypetype
-
Constructor Summary
Constructors Modifier Constructor Description privateEvent(EventType type, TestDescriptor testDescriptor, java.lang.Object payload)Construct anEventwith 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 aPredicatefor events whose payload types match the suppliedpayloadTypeand 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 EventdynamicTestRegistered(TestDescriptor testDescriptor)Create anEventfor the dynamic registration of the suppliedTestDescriptor.static EventexecutionFinished(TestDescriptor testDescriptor, TestExecutionResult result)static EventexecutionSkipped(TestDescriptor testDescriptor, java.lang.String reason)static EventexecutionStarted(TestDescriptor testDescriptor)Create a startedEventfor 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> TgetRequiredPayload(java.lang.Class<T> payloadType)Get the payload of the required type.TestDescriptorgetTestDescriptor()Get theTestDescriptorassociated with thisEvent.java.time.InstantgetTimestamp()Get theInstantwhen thisEventoccurred.EventTypegetType()Get the type of thisEvent.static EventreportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)java.lang.StringtoString()
-
-
-
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 anEventwith the supplied arguments.- Parameters:
type- the type of the event; nevernulltestDescriptor- theTestDescriptorassociated with the event; nevernullpayload- the generic payload associated with the event; may benull
-
-
Method Detail
-
reportingEntryPublished
public static Event reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)
- Parameters:
testDescriptor- theTestDescriptorassociated with the event; nevernullentry- theReportEntrythat was published; nevernull- Returns:
- the newly created
Event - See Also:
EventType.REPORTING_ENTRY_PUBLISHED
-
dynamicTestRegistered
public static Event dynamicTestRegistered(TestDescriptor testDescriptor)
Create anEventfor the dynamic registration of the suppliedTestDescriptor.- Parameters:
testDescriptor- theTestDescriptorassociated 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- theTestDescriptorassociated with the event; nevernullreason- 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 startedEventfor the suppliedTestDescriptor.- Parameters:
testDescriptor- theTestDescriptorassociated with the event; nevernull- Returns:
- the newly created
Event - See Also:
EventType.STARTED
-
executionFinished
public static Event executionFinished(TestDescriptor testDescriptor, TestExecutionResult result)
- Parameters:
testDescriptor- theTestDescriptorassociated with the event; nevernullresult- theTestExecutionResultfor 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 aPredicatefor events whose payload types match the suppliedpayloadTypeand whose payloads match the suppliedpayloadPredicate.- Parameters:
payloadType- the required payload typepayloadPredicate- aPredicateto 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- aPredicateto 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 theTestDescriptorassociated with thisEvent.- Returns:
- the
TestDescriptor; nevernull
-
getTimestamp
public java.time.Instant getTimestamp()
Get theInstantwhen thisEventoccurred.- Returns:
- the
Instantwhen thisEventoccurred; nevernull
-
getPayload
public java.util.Optional<java.lang.Object> getPayload()
Get the payload, if available.- Returns:
- an
Optionalcontaining the payload; nevernullbut 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
Optionalcontaining the payload; nevernullbut potentially empty - See Also:
getPayload(),getRequiredPayload(Class)
-
getRequiredPayload
public <T> T getRequiredPayload(java.lang.Class<T> payloadType) throws java.lang.IllegalArgumentExceptionGet 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:
toStringin classjava.lang.Object
-
-