Search in sources :

Example 26 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class DeferredScalarObserverTest method fusedReject.

@Test
public void fusedReject() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserverEx<Integer> to = new TestObserverEx<>(QueueFuseable.SYNC);
        TakeFirst source = new TakeFirst(to);
        Disposable d = Disposable.empty();
        source.onSubscribe(d);
        to.assertFuseable();
        to.assertFusionMode(QueueFuseable.NONE);
        source.onNext(1);
        source.onNext(1);
        source.onError(new TestException());
        source.onComplete();
        assertTrue(d.isDisposed());
        to.assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : QueueDisposable(io.reactivex.rxjava3.operators.QueueDisposable) Test(org.junit.Test)

Example 27 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class MaybeCreateTest method onCompleteThrows.

@Test
public void onCompleteThrows() {
    Maybe.create(new MaybeOnSubscribe<Object>() {

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            Disposable d = Disposable.empty();
            e.setDisposable(d);
            try {
                e.onComplete();
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            assertTrue(d.isDisposed());
            assertTrue(e.isDisposed());
        }
    }).subscribe(new MaybeObserver<Object>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(Object value) {
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
            throw new TestException();
        }
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 28 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class MaybeDoOnEventTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final Disposable bs = Disposable.empty();
        new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                observer.onComplete();
                observer.onSuccess(1);
            }
        }.doOnSubscribe(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable d) throws Exception {
                throw new TestException("First");
            }
        }).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(bs.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 29 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class MaybeCreateTest method onErrorThrows2.

@Test
public void onErrorThrows2() {
    Maybe.create(new MaybeOnSubscribe<Object>() {

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            try {
                e.onError(new IOException());
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            assertTrue(e.isDisposed());
        }
    }).subscribe(new MaybeObserver<Object>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(Object value) {
        }

        @Override
        public void onError(Throwable e) {
            throw new TestException();
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class MaybeCreateTest method onSuccessThrows.

@Test
public void onSuccessThrows() {
    Maybe.create(new MaybeOnSubscribe<Object>() {

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            Disposable d = Disposable.empty();
            e.setDisposable(d);
            try {
                e.onSuccess(1);
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            assertTrue(d.isDisposed());
            assertTrue(e.isDisposed());
        }
    }).subscribe(new MaybeObserver<Object>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(Object value) {
            throw new TestException();
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)251 Disposable (io.reactivex.rxjava3.disposables.Disposable)236 TestException (io.reactivex.rxjava3.exceptions.TestException)74 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)56 IOException (java.io.IOException)38 Scheduler (io.reactivex.rxjava3.core.Scheduler)36 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)35 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)34 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)32 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 TestObserver (io.reactivex.rxjava3.observers.TestObserver)18 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)15 QueueDisposable (io.reactivex.rxjava3.operators.QueueDisposable)13 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)10 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)9 LifecycleDisposable (org.thoughtcrime.securesms.util.LifecycleDisposable)8 Observable (io.reactivex.rxjava3.core.Observable)6 Observer (io.reactivex.rxjava3.core.Observer)6 ScalarDisposable (io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)6