Search in sources :

Example 46 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class ObservableMergeWithSingleTest method cancelMainOnOtherError.

@Test
public void cancelMainOnOtherError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    SingleSubject<Integer> ss = SingleSubject.create();
    TestObserver<Integer> to = ps.mergeWith(ss).test();
    assertTrue(ps.hasObservers());
    assertTrue(ss.hasObservers());
    ss.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("main has observers!", ps.hasObservers());
    assertFalse("other has observers", ss.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 47 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class ObservableMergeWithSingleTest method onErrorMainOverflow.

@Test
public void onErrorMainOverflow() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<Observer<?>> observerRef = new AtomicReference<>();
        TestObserver<Integer> to = new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observerRef.set(observer);
            }
        }.mergeWith(Single.<Integer>error(new IOException())).test();
        observerRef.get().onError(new TestException());
        to.assertFailure(IOException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Test(org.junit.Test)

Example 48 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class ObservableGroupByTest method newGroupValueSelectorFails.

@Test
public void newGroupValueSelectorFails() {
    TestObserver<Object> to1 = new TestObserver<>();
    final TestObserver<Object> to2 = new TestObserver<>();
    Observable.just(1).groupBy(Functions.<Integer>identity(), new Function<Integer, Object>() {

        @Override
        public Object apply(Integer v) throws Throwable {
            throw new TestException();
        }
    }).doOnNext(new Consumer<GroupedObservable<Integer, Object>>() {

        @Override
        public void accept(GroupedObservable<Integer, Object> g) throws Throwable {
            g.subscribe(to2);
        }
    }).subscribe(to1);
    to1.assertValueCount(1).assertError(TestException.class).assertNotComplete();
    to2.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) GroupedObservable(io.reactivex.rxjava3.observables.GroupedObservable) Test(org.junit.Test)

Example 49 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class ObservablePublishTest method onErrorAvailableUntilReset.

@Test
public void onErrorAvailableUntilReset() {
    ConnectableObservable<Integer> co = Observable.just(1).concatWith(Observable.<Integer>error(new TestException())).publish();
    TestObserver<Integer> to = co.test();
    to.assertEmpty();
    co.connect();
    to.assertFailure(TestException.class, 1);
    co.test().assertFailure(TestException.class);
    co.reset();
    to = co.test();
    to.assertEmpty();
    co.connect();
    to.assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 50 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class SerializedSubjectTest method onErrorOnErrorRace.

@Test
public void onErrorOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
        TestObserver<Integer> to = s.test();
        final TestException ex = new TestException();
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    s.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    s.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertFailure(TestException.class);
            TestHelper.assertUndeliverable(errors, 0, TestException.class);
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)225 TestException (io.reactivex.rxjava3.exceptions.TestException)169 TestObserver (io.reactivex.rxjava3.observers.TestObserver)90 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 Disposable (io.reactivex.rxjava3.disposables.Disposable)34 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)27 TargetApi (android.annotation.TargetApi)21 Observable (io.reactivex.rxjava3.core.Observable)19 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)19 IOException (java.io.IOException)19 Matchers.anyString (org.mockito.Matchers.anyString)16 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)13 Action (io.reactivex.rxjava3.functions.Action)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 InOrder (org.mockito.InOrder)7 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)6 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)6 List (java.util.List)6 Assert (org.junit.Assert)6 Activity (android.app.Activity)5