Search in sources :

Example 96 with PublishSubject

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

the class CompletableDisposeOnTest method errorAfterCancel.

@Test
public void errorAfterCancel() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestScheduler scheduler = new TestScheduler();
        PublishSubject<Integer> ps = PublishSubject.create();
        TestObserver<Void> to = ps.ignoreElements().unsubscribeOn(scheduler).test();
        to.dispose();
        ps.onError(new TestException());
        to.assertEmpty();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 97 with PublishSubject

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

the class ObservableDebounceTest method debounceSelectorNormal1.

@Test
public void debounceSelectorNormal1() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> debouncer = PublishSubject.create();
    Function<Integer, Observable<Integer>> debounceSel = new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return debouncer;
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    InOrder inOrder = inOrder(o);
    source.debounce(debounceSel).subscribe(o);
    source.onNext(1);
    debouncer.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onNext(4);
    debouncer.onNext(2);
    source.onNext(5);
    source.onComplete();
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(4);
    inOrder.verify(o).onNext(5);
    inOrder.verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
Also used : Function(io.reactivex.rxjava3.functions.Function) InOrder(org.mockito.InOrder)

Example 98 with PublishSubject

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

the class ObservableDelayTest method delayWithObservableNormal1.

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

        @Override
        public Observable<Integer> apply(Integer t1) {
            return delays.get(t1);
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    InOrder inOrder = inOrder(o);
    source.delay(delayFunc).subscribe(o);
    for (int i = 0; i < n; i++) {
        source.onNext(i);
        delays.get(i).onNext(i);
        inOrder.verify(o).onNext(i);
    }
    source.onComplete();
    inOrder.verify(o).onComplete();
    inOrder.verifyNoMoreInteractions();
    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)

Example 99 with PublishSubject

use of io.reactivex.rxjava3.subjects.PublishSubject 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)

Example 100 with PublishSubject

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

the class ObservableDelayTest method delayWithObservableSingleSend1.

@Test
public void delayWithObservableSingleSend1() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> delay = PublishSubject.create();
    Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return delay;
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    InOrder inOrder = inOrder(o);
    source.delay(delayFunc).subscribe(o);
    source.onNext(1);
    delay.onNext(1);
    delay.onNext(2);
    inOrder.verify(o).onNext(1);
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onError(any(Throwable.class));
}
Also used : InOrder(org.mockito.InOrder) Observable(io.reactivex.rxjava3.core.Observable)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)69 Test (org.junit.Test)68 InOrder (org.mockito.InOrder)36 Observable (io.reactivex.rxjava3.core.Observable)28 Disposable (io.reactivex.rxjava3.disposables.Disposable)17 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)17 TestObserver (io.reactivex.rxjava3.observers.TestObserver)14 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 ObservableReplay (io.reactivex.rxjava3.internal.operators.observable.ObservableReplay)4 IOException (java.io.IOException)4 TargetApi (android.annotation.TargetApi)3 Function (io.reactivex.rxjava3.functions.Function)3 CrashingIterable (io.reactivex.rxjava3.internal.util.CrashingIterable)3 PublishSubject (io.reactivex.rxjava3.subjects.PublishSubject)3 Matchers.anyString (org.mockito.Matchers.anyString)3 NonNull (io.reactivex.rxjava3.annotations.NonNull)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Observer (io.reactivex.rxjava3.core.Observer)1 GroupedObservable (io.reactivex.rxjava3.observables.GroupedObservable)1