Search in sources :

Example 26 with TestObserver

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

the class SingleTimeoutTest method shouldUnsubscribeFromUnderlyingSubscriptionOnDispose.

@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
    final PublishSubject<String> subject = PublishSubject.create();
    final TestScheduler scheduler = new TestScheduler();
    final TestObserver<String> observer = subject.single("").timeout(100, TimeUnit.MILLISECONDS, scheduler).test();
    assertTrue(subject.hasObservers());
    observer.dispose();
    assertFalse(subject.hasObservers());
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 27 with TestObserver

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

the class SingleZipIterableTest method innerErrorRace.

@Test
public void innerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp0 = PublishProcessor.create();
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final TestObserver<Object> to = Single.zip(Arrays.asList(pp0.single(0), pp1.single(0)), addString).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

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

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

Example 28 with TestObserver

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

the class AsyncSubjectTest method onErrorCrossCancel.

@Test
@SuppressUndeliverable
public void onErrorCrossCancel() {
    AsyncSubject<Object> p = AsyncSubject.create();
    final TestObserver<Object> to2 = new TestObserver<>();
    TestObserver<Object> to1 = new TestObserver<Object>() {

        @Override
        public void onError(Throwable t) {
            to2.dispose();
            super.onError(t);
        }
    };
    p.subscribe(to1);
    p.subscribe(to2);
    p.onError(new TestException());
    to1.assertFailure(TestException.class);
    to2.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 29 with TestObserver

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

the class ObservableConcatWithMaybeTest method normalEmpty.

@Test
public void normalEmpty() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.range(1, 5).concatWith(Maybe.<Integer>fromAction(new Action() {

        @Override
        public void run() throws Exception {
            to.onNext(100);
        }
    })).subscribe(to);
    to.assertResult(1, 2, 3, 4, 5, 100);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 30 with TestObserver

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

the class ObservableConcatWithMaybeTest method otherError.

@Test
public void otherError() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.range(1, 5).concatWith(Maybe.<Integer>error(new TestException())).subscribe(to);
    to.assertFailure(TestException.class, 1, 2, 3, 4, 5);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) 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