Class Events


  • @API(status=EXPERIMENTAL,
         since="1.4")
    public final class Events
    extends java.lang.Object
    Events is a facade that provides a fluent API for working with events.
    Since:
    1.4
    • Field Detail

      • events

        private final java.util.List<Event> events
      • category

        private final java.lang.String category
    • Constructor Detail

      • Events

        Events​(java.util.stream.Stream<Event> events,
               java.lang.String category)
      • Events

        Events​(java.util.List<Event> events,
               java.lang.String category)
    • Method Detail

      • getCategory

        java.lang.String getCategory()
      • list

        public java.util.List<Event> list()
        Get the events as a List.
        Returns:
        the list of events; never null
        See Also:
        stream()
      • stream

        public java.util.stream.Stream<Event> stream()
        Get the events as a Stream.
        Returns:
        the stream of events; never null
        See Also:
        list()
      • map

        public <R> java.util.stream.Stream<R> map​(java.util.function.Function<? super Event,​? extends R> mapper)
        Shortcut for events.stream().map(mapper).
        Parameters:
        mapper - a Function to apply to each event; never null
        Returns:
        the mapped stream of events; never null
        See Also:
        stream(), Stream.map(Function)
      • filter

        public java.util.stream.Stream<Event> filter​(java.util.function.Predicate<? super Event> predicate)
        Shortcut for events.stream().filter(predicate).
        Parameters:
        predicate - a Predicate to apply to each event to decide if it should be included in the filtered stream; never null
        Returns:
        the filtered stream of events; never null
        See Also:
        stream(), Stream.filter(Predicate)
      • executions

        public Executions executions()
        Get the Executions for the current set of events.
        Returns:
        an instance of Executions for the current set of events; never null
      • count

        public long count()
        Get the number of events contained in this Events object.
      • skipped

        public Events skipped()
        Get the skipped Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • started

        public Events started()
        Get the started Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • finished

        public Events finished()
        Get the finished Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • aborted

        public Events aborted()
        Get the aborted Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • succeeded

        public Events succeeded()
        Get the succeeded Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • failed

        public Events failed()
        Get the failed Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • reportingEntryPublished

        public Events reportingEntryPublished()
        Get the reporting entry publication Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • dynamicallyRegistered

        public Events dynamicallyRegistered()
        Get the dynamic registration Events contained in this Events object.
        Returns:
        the filtered Events; never null
      • assertStatistics

        public Events assertStatistics​(java.util.function.Consumer<EventStatistics> statisticsConsumer)
        Assert statistics for the events contained in this Events object.

        Example

        events.assertStatistics(stats -> stats.started(1).succeeded(1).failed(0));

        Parameters:
        statisticsConsumer - a Consumer of EventStatistics; never null
        Returns:
        this Events object for method chaining; never null
      • assertEventsMatchExactly

        @SafeVarargs
        public final void assertEventsMatchExactly​(org.assertj.core.api.Condition<? super Event>... conditions)
        Assert that all events contained in this Events object exactly match the provided conditions.

        Conditions can be imported statically from EventConditions and TestExecutionResultConditions.

        Example

         executionResults.tests().assertEventsMatchExactly(
             event(test("exampleTestMethod"), started()),
             event(test("exampleTestMethod"), finishedSuccessfully())
         );
         
        Parameters:
        conditions - the conditions to match against; never null
        See Also:
        EventConditions, TestExecutionResultConditions
      • assertThatEvents

        public org.assertj.core.api.ListAssert<Event> assertThatEvents()
        Shortcut for org.assertj.core.api.Assertions.assertThat(events.list()).
        Returns:
        an instance of ListAssert for events; never null
        See Also:
        Assertions.assertThat(List), ListAssert
      • debug

        public Events debug()
        Print all events to System.out.
        Returns:
        this Events object for method chaining; never null
      • debug

        public Events debug​(java.io.OutputStream out)
        Print all events to the supplied OutputStream.
        Parameters:
        out - the OutputStream to print to; never null
        Returns:
        this Events object for method chaining; never null
      • debug

        public Events debug​(java.io.Writer writer)
        Print all events to the supplied Writer.
        Parameters:
        writer - the Writer to print to; never null
        Returns:
        this Events object for method chaining; never null
      • debug

        private Events debug​(java.io.PrintWriter printWriter)
      • eventsByType

        private java.util.stream.Stream<Event> eventsByType​(EventType type)
      • assertEventsMatchExactly

        @SafeVarargs
        private static void assertEventsMatchExactly​(java.util.List<Event> events,
                                                     org.assertj.core.api.Condition<? super Event>... conditions)