Class Event

    • Method Detail

      • 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
      • 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
      • 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 <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)