Search in sources :

Example 51 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class MaybeBlockingSubscribeTest method threeArgEmptyFails.

@Test
public void threeArgEmptyFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        Action action = mock(Action.class);
        doThrow(new TestException()).when(action).run();
        Maybe.<Integer>empty().delay(50, TimeUnit.MILLISECONDS, Schedulers.computation()).blockingSubscribe(success, consumer, action);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(success, never()).accept(any());
        verify(consumer, never()).accept(any());
        verify(action).run();
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 52 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class MaybeBlockingSubscribeTest method oneArgSuccessFails.

@Test
public void oneArgSuccessFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
        doThrow(new TestException()).when(success).accept(any());
        Maybe.just(1).blockingSubscribe(success);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(success).accept(1);
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 53 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class MaybeBlockingSubscribeTest method twoArgErrorFails.

@Test
public void twoArgErrorFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        doThrow(new TestException()).when(consumer).accept(any());
        Maybe.<Integer>error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation()).blockingSubscribe(success, consumer);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(success, never()).accept(any());
        verify(consumer).accept(any(TestException.class));
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 54 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class BooleanRunnableTest method runnableThrows.

@Test
public void runnableThrows() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        BooleanRunnable task = new BooleanRunnable(() -> {
            throw new TestException();
        });
        try {
            task.run();
            fail("Should have thrown!");
        } catch (TestException expected) {
        // expected
        }
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) BooleanRunnable(io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.ExecutorWorker.BooleanRunnable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 55 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class InstantPeriodicTaskTest method dispose3.

@Test
public void dispose3() throws Exception {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        InstantPeriodicTask task = new InstantPeriodicTask(new Runnable() {

            @Override
            public void run() {
                throw new TestException();
            }
        }, exec);
        task.dispose();
        FutureTask<Void> f1 = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
        task.setFirst(f1);
        assertTrue(f1.isCancelled());
        FutureTask<Void> f2 = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
        task.setRest(f2);
        assertTrue(f2.isCancelled());
    } finally {
        exec.shutdownNow();
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)656 Test (org.junit.Test)555 IOException (java.io.IOException)95 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)90 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)81 Disposable (io.reactivex.rxjava3.disposables.Disposable)56 InOrder (org.mockito.InOrder)54 TestObserver (io.reactivex.rxjava3.observers.TestObserver)47 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)40 Observable (io.reactivex.rxjava3.core.Observable)38 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)20 Action (io.reactivex.rxjava3.functions.Action)20 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)20 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)18 Observer (io.reactivex.rxjava3.core.Observer)15 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)15 Assert (org.junit.Assert)15 java.util (java.util)13 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)12