Search in sources :

Example 31 with Disposable

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

the class MaybeCreateTest method onCompleteThrows2.

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

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            try {
                e.onComplete();
                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) {
        }

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

Example 32 with Disposable

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

the class MaybeCreateTest method onErrorThrows.

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

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            Disposable d = Disposable.empty();
            e.setDisposable(d);
            try {
                e.onError(new IOException());
                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) {
            throw new TestException();
        }

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

Example 33 with Disposable

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

the class SingleSafeSubscribeTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
        doThrow(new TestException()).when(consumer).onSubscribe(any());
        Disposable d = Disposable.empty();
        new Single<Integer>() {

            @Override
            protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
                observer.onSubscribe(d);
                // none of the following should arrive at the consumer
                observer.onSuccess(1);
                observer.onError(new IOException());
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verifyNoMoreInteractions();
        assertTrue(d.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        TestHelper.assertUndeliverable(errors, 1, IOException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 34 with Disposable

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

the class SingleCreateTest method createConsumerThrowsResource.

@Test
public void createConsumerThrowsResource() {
    Single.create(new SingleOnSubscribe<Object>() {

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

        @Override
        public void onSubscribe(Disposable d) {
        }

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

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

Example 35 with Disposable

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

the class SingleDetachTest method errorDetaches.

@Test
public void errorDetaches() throws Exception {
    Disposable d = Disposable.empty();
    final WeakReference<Disposable> wr = new WeakReference<>(d);
    TestObserver<Integer> to = new Single<Integer>() {

        @Override
        protected void subscribeActual(SingleObserver<? super Integer> observer) {
            observer.onSubscribe(wr.get());
            observer.onError(new TestException());
            observer.onError(new IOException());
        }
    }.onTerminateDetach().test();
    d = null;
    System.gc();
    Thread.sleep(200);
    to.assertFailure(TestException.class);
    assertNull(wr.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) WeakReference(java.lang.ref.WeakReference) IOException(java.io.IOException) 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