Search in sources :

Example 11 with io.reactivex.rxjava3.subjects

use of io.reactivex.rxjava3.subjects in project RxJava by ReactiveX.

the class ObservableDelayTest method delayWithObservableReorder.

@Test
public void delayWithObservableReorder() {
    int n = 3;
    PublishSubject<Integer> source = PublishSubject.create();
    final List<PublishSubject<Integer>> subjects = new ArrayList<>();
    for (int i = 0; i < n; i++) {
        subjects.add(PublishSubject.<Integer>create());
    }
    Observable<Integer> result = source.delay(new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return subjects.get(t1);
        }
    });
    Observer<Object> o = TestHelper.mockObserver();
    InOrder inOrder = inOrder(o);
    result.subscribe(o);
    for (int i = 0; i < n; i++) {
        source.onNext(i);
    }
    source.onComplete();
    inOrder.verify(o, never()).onNext(anyInt());
    inOrder.verify(o, never()).onComplete();
    for (int i = n - 1; i >= 0; i--) {
        subjects.get(i).onComplete();
        inOrder.verify(o).onNext(i);
    }
    inOrder.verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
Also used : InOrder(org.mockito.InOrder) Observable(io.reactivex.rxjava3.core.Observable) PublishSubject(io.reactivex.rxjava3.subjects.PublishSubject)

Aggregations

Test (org.junit.Test)8 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 TestException (io.reactivex.rxjava3.exceptions.TestException)2 Pattern (java.util.regex.Pattern)2 InOrder (org.mockito.InOrder)2 Observable (io.reactivex.rxjava3.core.Observable)1 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)1 ConnectConsumer (io.reactivex.rxjava3.internal.util.ConnectConsumer)1 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)1 PublishSubject (io.reactivex.rxjava3.subjects.PublishSubject)1