Class TestPublisherSubscriber<T>

  • Type Parameters:
    T - The type of data in onNext(Object).
    All Implemented Interfaces:
    PublisherSource.Subscriber<T>

    public final class TestPublisherSubscriber<T>
    extends java.lang.Object
    implements PublisherSource.Subscriber<T>
    A PublisherSource.Subscriber that enqueues onNext(Object) and terminal signals while providing blocking methods to consume these events. There are two approaches to using this class:
         TestPublisherSubscriber<String> sub = new TestPublisherSubscriber<>();
    
         // Approach 1 - verify individual items sequentially.
         String s = sub.takeOnNext();
         // verify s
         sub.awaitOnComplete(); // this will verify that all onNext signals have been consumed
    
         // Approach 2 - wait for terminal, verify items in bulk.
         sub.awaitOnComplete(false); // wait for the terminal signal, ignore if there are unconsumed onNext signals.
         List<String> onNextSignals = sub.pollAllOnNext();
         // verify all onNextSignals occurred in the expected order