Class AssertSubscriber<T>

  • Type Parameters:
    T - the type of the items
    All Implemented Interfaces:
    org.reactivestreams.Subscriber<T>

    public class AssertSubscriber<T>
    extends java.lang.Object
    implements org.reactivestreams.Subscriber<T>
    A Multi Subscriber for testing purposes that comes with useful assertion helpers.
    • Constructor Detail

      • AssertSubscriber

        public AssertSubscriber​(long requested,
                                boolean cancelled)
        Creates a new AssertSubscriber.
        Parameters:
        requested - the number of initially requested items
        cancelled - true if the subscription is immediately cancelled, false otherwise
      • AssertSubscriber

        public AssertSubscriber()
        Creates a new AssertSubscriber with 0 requested items and no upfront cancellation.
      • AssertSubscriber

        public AssertSubscriber​(long requested)
        Creates a new AssertSubscriber with no upfront cancellation.
        Parameters:
        requested - the number of initially requested items
    • Method Detail

      • create

        public static <T> AssertSubscriber<T> create()
        Creates a new AssertSubscriber with 0 requested items and no upfront cancellation.
        Type Parameters:
        T - the items type
        Returns:
        a new subscriber
      • create

        public static <T> AssertSubscriber<T> create​(long requested)
        Creates a new AssertSubscriber with no upfront cancellation.
        Type Parameters:
        T - the items type
        Parameters:
        requested - the number of initially requested items
        Returns:
        a new subscriber
      • assertFailedWith

        public AssertSubscriber<T> assertFailedWith​(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure,
                                                    java.lang.String expectedFailureMessage)
        Assert that the multi has failed.
        Parameters:
        expectedTypeOfFailure - the expected failure type
        expectedFailureMessage - a message to be contained in the failure message, or null when any message is fine
        Returns:
        this AssertSubscriber
      • assertItems

        @SafeVarargs
        public final AssertSubscriber<T> assertItems​(T... expected)
        Assert that a sequence of items has been received (in whole and in exact order).
        Parameters:
        expected - a sequence of items
        Returns:
        this AssertSubscriber
      • await

        public AssertSubscriber<T> await​(java.time.Duration duration)
        Await for the multi to be terminated.
        Parameters:
        duration - the timeout duration
        Returns:
        this AssertSubscriber
      • onSubscribe

        public void onSubscribe​(org.reactivestreams.Subscription s)
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
      • onNext

        public void onNext​(T t)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<T>
      • onError

        public void onError​(java.lang.Throwable t)
        Specified by:
        onError in interface org.reactivestreams.Subscriber<T>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
      • getItems

        public java.util.List<T> getItems()
        The list of items that have been received.
        Returns:
        the list
      • getFailure

        public java.lang.Throwable getFailure()
        The reported failure, if any.
        Returns:
        the failure or null
      • isCancelled

        public boolean isCancelled()
        Check whether the subscription has been cancelled or not.
        Returns:
        a boolean
      • hasCompleted

        public boolean hasCompleted()
        Check whether the multi has completed.
        Returns:
        a boolean