Search in sources :

Example 11 with PublishSubject

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

the class ObservableDelayTest method delaySupplierErrors.

@Test
public void delaySupplierErrors() {
    final PublishSubject<Integer> ps = PublishSubject.create();
    Observable<Integer> source = Observable.range(1, 5);
    TestObserver<Integer> to = new TestObserver<>();
    source.delaySubscription(ps).subscribe(to);
    to.assertNoValues();
    to.assertNoErrors();
    to.assertNotComplete();
    ps.onError(new TestException());
    to.assertNoValues();
    to.assertNotComplete();
    to.assertError(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 12 with PublishSubject

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

the class ObservableDelayTest method delayWithObservableSourceThrows.

@Test
public void delayWithObservableSourceThrows() {
    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);
    source.onError(new TestException());
    delay.onNext(1);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) Observable(io.reactivex.rxjava3.core.Observable)

Example 13 with PublishSubject

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

the class ObservableDelayTest method delayWithObservableSubscriptionFunctionThrows.

@Test
public void delayWithObservableSubscriptionFunctionThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> delay = PublishSubject.create();
    Supplier<Observable<Integer>> subFunc = new Supplier<Observable<Integer>>() {

        @Override
        public Observable<Integer> get() {
            throw new TestException();
        }
    };
    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(Observable.defer(subFunc), delayFunc).subscribe(o);
    source.onNext(1);
    delay.onNext(1);
    source.onNext(2);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) Observable(io.reactivex.rxjava3.core.Observable)

Example 14 with PublishSubject

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

the class ObservableDelayTest method delayWithObservableSubscriptionRunCompletion.

@Test
public void delayWithObservableSubscriptionRunCompletion() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> sdelay = PublishSubject.create();
    final PublishSubject<Integer> delay = PublishSubject.create();
    Supplier<Observable<Integer>> subFunc = new Supplier<Observable<Integer>>() {

        @Override
        public Observable<Integer> get() {
            return sdelay;
        }
    };
    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(Observable.defer(subFunc), delayFunc).subscribe(o);
    source.onNext(1);
    sdelay.onComplete();
    source.onNext(2);
    delay.onNext(2);
    inOrder.verify(o).onNext(2);
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onError(any(Throwable.class));
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) Observable(io.reactivex.rxjava3.core.Observable)

Example 15 with PublishSubject

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

the class ObservableDelayTest method delayWithObservableDelayThrows.

@Test
public void delayWithObservableDelayThrows() {
    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.onError(new TestException());
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) 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