JavaScript is disabled on your browser.
Skip navigation links
io.reactivex.subscribers

Class TestSubscriber<T>

  • Type Parameters:
    T - the value type
    All Implemented Interfaces:
    Disposable, FlowableSubscriber<T>, Subscriber<T>, Subscription


    public class TestSubscriber<T>
    extends BaseTestConsumer<T,TestSubscriber<T>>
    implements FlowableSubscriber<T>, Subscription, Disposable 
    A subscriber that records events and allows making assertions about them.

    You can override the onSubscribe, onNext, onError, onComplete, request and cancel methods but not the others (this is by design).

    The TestSubscriber implements Disposable for convenience where dispose calls cancel.

    When calling the default request method, you are requesting on behalf of the wrapped actual subscriber.

    • Constructor Detail

      • TestSubscriber

        public TestSubscriber()
        Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE.
      • TestSubscriber

        public TestSubscriber(long initialRequest)
        Constructs a non-forwarding TestSubscriber with the specified initial request value.

        The TestSubscriber doesn't validate the initialRequest value so one can test sources with invalid values as well.

        Parameters:
        initialRequest - the initial request value
      • TestSubscriber

        public TestSubscriber(Subscriber<? super T> downstream)
        Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber.
        Parameters:
        downstream - the actual Subscriber to forward events to
      • TestSubscriber

        public TestSubscriber(Subscriber<? super T> actual,
         long initialRequest)
        Constructs a forwarding TestSubscriber with the specified initial request value.

        The TestSubscriber doesn't validate the initialRequest value so one can test sources with invalid values as well.

        Parameters:
        actual - the actual Subscriber to forward events to
        initialRequest - the initial request value
    • Method Detail

      • create

        public static <T> TestSubscriber<T> create()
        Creates a TestSubscriber with Long.MAX_VALUE initial request.
        Type Parameters:
        T - the value type
        Returns:
        the new TestSubscriber instance.
      • create

        public static <T> TestSubscriber<T> create(long initialRequested)
        Creates a TestSubscriber with the given initial request.
        Type Parameters:
        T - the value type
        Parameters:
        initialRequested - the initial requested amount
        Returns:
        the new TestSubscriber instance.
      • create

        public static <T> TestSubscriber<T> create(Subscriber<? super T> delegate)
        Constructs a forwarding TestSubscriber.
        Type Parameters:
        T - the value type received
        Parameters:
        delegate - the actual Subscriber to forward events to
        Returns:
        the new TestObserver instance
      • onStart

        protected void onStart()
        Called after the onSubscribe is called and handled.
      • isCancelled

        public final boolean isCancelled()
        Returns true if this TestSubscriber has been cancelled.
        Returns:
        true if this TestSubscriber has been cancelled
      • dispose

        public final void dispose()
        Description copied from interface: Disposable
        Dispose the resource, the operation should be idempotent.
        Specified by:
        dispose in interface Disposable
      • isDisposed

        public final boolean isDisposed()
        Description copied from interface: Disposable
        Returns true if this resource has been disposed.
        Specified by:
        isDisposed in interface Disposable
        Returns:
        true if this resource has been disposed
      • hasSubscription

        public final boolean hasSubscription()
        Returns true if this TestSubscriber received a subscription.
        Returns:
        true if this TestSubscriber received a subscription
      • assertOf

        public final TestSubscriber<T> assertOf(Consumer<? super TestSubscriber<T>> check)
        Run a check consumer with this TestSubscriber instance.
        Parameters:
        check - the check consumer to run
        Returns:
        this
      • requestMore

        public final TestSubscriber<T> requestMore(long n)
        Calls request(long) and returns this.

        History: 2.0.1 - experimental

        Parameters:
        n - the request amount
        Returns:
        this
        Since:
        2.1
Skip navigation links

AltStyle によって変換されたページ (->オリジナル) /