Search in sources :

Example 26 with Observable

use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.

the class ObservableDeferTest method deferFunctionThrows.

@Test
public void deferFunctionThrows() throws Throwable {
    Supplier<Observable<String>> factory = mock(Supplier.class);
    when(factory.get()).thenThrow(new TestException());
    Observable<String> result = Observable.defer(factory);
    Observer<String> o = TestHelper.mockObserver();
    result.subscribe(o);
    verify(o).onError(any(TestException.class));
    verify(o, never()).onNext(any(String.class));
    verify(o, never()).onComplete();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 27 with Observable

use of io.reactivex.rxjava3.core.Observable 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 28 with Observable

use of io.reactivex.rxjava3.core.Observable 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 29 with Observable

use of io.reactivex.rxjava3.core.Observable 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 30 with Observable

use of io.reactivex.rxjava3.core.Observable 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)

Aggregations

Test (org.junit.Test)132 TestException (io.reactivex.rxjava3.exceptions.TestException)109 Observable (io.reactivex.rxjava3.core.Observable)83 InOrder (org.mockito.InOrder)60 TestObserver (io.reactivex.rxjava3.observers.TestObserver)38 Disposable (io.reactivex.rxjava3.disposables.Disposable)35 IOException (java.io.IOException)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)22 Observer (io.reactivex.rxjava3.core.Observer)19 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)17 Function (io.reactivex.rxjava3.functions.Function)10 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Collections (java.util.Collections)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Assert (org.junit.Assert)6