Class TestSubscriber<T>

java.lang.Object
io.reactivex.rxjava4.observers.BaseTestConsumer<T, TestSubscriber<T>>
io.reactivex.rxjava4.subscribers.TestSubscriber<T>
Type Parameters:
T - the value type
All Implemented Interfaces:
FlowableSubscriber<T>, Flow.Subscriber<T>, Flow.Subscription

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

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

When calling the default request method, you are requesting on behalf of the wrapped actual Flow.Subscriber if any.

  • Constructor Details

    • 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 amount so one can test sources with invalid values as well.

      Parameters:
      initialRequest - the initial request amount
    • TestSubscriber

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

      public TestSubscriber(@NonNull @NonNull Flow.Subscriber<? super T> actual, long initialRequest)
      Constructs a forwarding TestSubscriber with the specified initial request amount and an actual Flow.Subscriber to forward events to.

      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 amount
  • Method Details