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

@API(status=MAINTAINED, since="1.7") public final class Events extends Object
Events is a facade that provides a fluent API for working with events.
Since:
1.4
  • Method Details

    • list

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

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

      public <R> Stream<R> map(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 Stream<Event> filter(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(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(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.testEvents().assertEventsMatchExactly(
           event(test("exampleTestMethod"), started()),
           event(test("exampleTestMethod"), finishedSuccessfully())
       );
       
      Parameters:
      conditions - the conditions to match against; never null
      See Also:
      assertEventsMatchLoosely(Condition...), assertEventsMatchLooselyInOrder(Condition...), EventConditions, TestExecutionResultConditions
    • assertEventsMatchLoosely

      @SafeVarargs public final void assertEventsMatchLoosely(Condition<? super Event>... conditions)
      Assert that all provided conditions are matched by an event contained in this Events object, regardless of order.

      Note that this method performs a partial match. Thus, some events may not match any of the provided conditions.

      Conditions can be imported statically from EventConditions and TestExecutionResultConditions.

      Example

       executionResults.testEvents().assertEventsMatchLoosely(
           event(test("exampleTestMethod"), started()),
           event(test("exampleTestMethod"), finishedSuccessfully())
       );
       
      Parameters:
      conditions - the conditions to match against; never null
      Since:
      1.7
      See Also:
      assertEventsMatchExactly(Condition...), assertEventsMatchLooselyInOrder(Condition...), EventConditions, TestExecutionResultConditions
    • assertEventsMatchLooselyInOrder

      @SafeVarargs public final void assertEventsMatchLooselyInOrder(Condition<? super Event>... conditions)
      Assert that all provided conditions are matched by an event contained in this Events object.

      Note that this method performs a partial match. Thus, some events may not match any of the provided conditions; however, the conditions provided must be in the correct order.

      Conditions can be imported statically from EventConditions and TestExecutionResultConditions.

      Example

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

      public 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(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(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