java.lang.Object
org.junit.platform.testkit.engine.Event

@API(status=MAINTAINED, since="1.7") public class Event extends Object
Event represents a single event fired during execution of a test plan on the JUnit Platform.
Since:
1.4
See Also:
EventType
  • Method Details

    • reportingEntryPublished

      public static Event reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry)
      Create an Event for a reporting entry published for the supplied TestDescriptor and ReportEntry.
      Parameters:
      testDescriptor - the TestDescriptor associated with the event; never null
      entry - the ReportEntry that was published; never null
      Returns:
      the newly created Event
      See Also:
      EventType.REPORTING_ENTRY_PUBLISHED
    • dynamicTestRegistered

      public static Event dynamicTestRegistered(TestDescriptor testDescriptor)
      Create an Event for the dynamic registration of the supplied TestDescriptor.
      Parameters:
      testDescriptor - the TestDescriptor associated with the event; never null
      Returns:
      the newly created Event
      See Also:
      EventType.DYNAMIC_TEST_REGISTERED
    • executionSkipped

      public static Event executionSkipped(TestDescriptor testDescriptor, String reason)
      Create a skipped Event for the supplied TestDescriptor and reason.
      Parameters:
      testDescriptor - the TestDescriptor associated with the event; never null
      reason - the reason the execution was skipped; may be null
      Returns:
      the newly created Event
      See Also:
      EventType.SKIPPED
    • executionStarted

      public static Event executionStarted(TestDescriptor testDescriptor)
      Create a started Event for the supplied TestDescriptor.
      Parameters:
      testDescriptor - the TestDescriptor associated with the event; never null
      Returns:
      the newly created Event
      See Also:
      EventType.STARTED
    • executionFinished

      public static Event executionFinished(TestDescriptor testDescriptor, TestExecutionResult result)
      Create a finished Event for the supplied TestDescriptor and TestExecutionResult.
      Parameters:
      testDescriptor - the TestDescriptor associated with the event; never null
      result - the TestExecutionResult for the supplied TestDescriptor; never null
      Returns:
      the newly created Event
      See Also:
      EventType.FINISHED
    • byPayload

      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 - the required payload type
      payloadPredicate - a Predicate to match against payloads
      Returns:
      the resulting Predicate
    • byType

      public static Predicate<Event> byType(EventType type)
      Create a Predicate for events whose event types match the supplied type.
      Parameters:
      type - the type to match against
      Returns:
      the resulting Predicate
    • byTestDescriptor

      public static Predicate<Event> byTestDescriptor(Predicate<? super TestDescriptor> testDescriptorPredicate)
      Create a Predicate for events whose TestDescriptors match the supplied testDescriptorPredicate.
      Parameters:
      testDescriptorPredicate - a Predicate to match against test descriptors
      Returns:
      the resulting Predicate
    • getType

      public EventType getType()
      Get the type of this Event.
      Returns:
      the event type; never null
      See Also:
      EventType
    • getTestDescriptor

      public TestDescriptor getTestDescriptor()
      Get the TestDescriptor associated with this Event.
      Returns:
      the TestDescriptor; never null
    • getTimestamp

      public Instant getTimestamp()
      Get the Instant when this Event occurred.
      Returns:
      the Instant when this Event occurred; never null
    • getPayload

      public Optional<Object> getPayload()
      Get the payload, if available.
      Returns:
      an Optional containing the payload; never null but potentially empty
      See Also:
      getPayload(Class), getRequiredPayload(Class)
    • getPayload

      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 - the expected payload type; never null
      Returns:
      an Optional containing the payload; never null but potentially empty
      See Also:
      getPayload(), getRequiredPayload(Class)
    • getRequiredPayload

      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 - the required payload type; never null
      Returns:
      the payload
      Throws:
      IllegalArgumentException - if the payload is of a different type or is not present
      See Also:
      getPayload(), getPayload(Class)
    • toString

      public String toString()
      Overrides:
      toString in class Object