Package rx.subjects

Class TestSubject<T>

  • Type Parameters:
    T - the type of item observed by and emitted by the subject
    All Implemented Interfaces:
    Observer<T>

    public final class TestSubject<T>
    extends Subject<T,​T>
    A variety of Subject that is useful for testing purposes. It operates on a TestScheduler and allows you to precisely time emissions and notifications to the Subject's subscribers using relative virtual time controlled by the TestScheduler.
    • Method Detail

      • create

        public static <T> TestSubject<T> create​(TestScheduler scheduler)
        Creates and returns a new TestSubject.
        Type Parameters:
        T - the value type
        Parameters:
        scheduler - a TestScheduler on which to operate this Subject
        Returns:
        the new TestSubject
      • onCompleted

        public void onCompleted()
        Schedule a call to onCompleted on TestScheduler.
      • internalOnCompleted

        void internalOnCompleted()
      • onCompleted

        public void onCompleted​(long delayTime)
        Schedule a call to onCompleted relative to "now()" +n milliseconds in the future.
        Parameters:
        delayTime - the number of milliseconds in the future relative to "now()" at which to call onCompleted
      • onError

        public void onError​(java.lang.Throwable e)
        Schedule a call to onError on TestScheduler.
        Parameters:
        e - the exception encountered by the Observable
      • internalOnError

        void internalOnError​(java.lang.Throwable e)
      • onError

        public void onError​(java.lang.Throwable e,
                            long delayTime)
        Schedule a call to onError relative to "now()" +n milliseconds in the future.
        Parameters:
        e - the Throwable to pass to the onError method
        delayTime - the number of milliseconds in the future relative to "now()" at which to call onError
      • onNext

        public void onNext​(T v)
        Schedule a call to onNext on TestScheduler.
        Parameters:
        v - the item emitted by the Observable
      • internalOnNext

        void internalOnNext​(T v)
      • onNext

        public void onNext​(T v,
                           long delayTime)
        Schedule a call to onNext relative to "now()" +n milliseconds in the future.
        Parameters:
        v - the item to emit
        delayTime - the number of milliseconds in the future relative to "now()" at which to call onNext
      • hasObservers

        public boolean hasObservers()
        Description copied from class: Subject
        Indicates whether the Subject has Observers subscribed to it.
        Specified by:
        hasObservers in class Subject<T,​T>
        Returns:
        true if there is at least one Observer subscribed to this Subject, false otherwise