Search in sources :

Example 1 with TestException

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

the class FlowableFromCompletionStageTest method syncFailure.

@Test
public void syncFailure() {
    CompletableFuture<Integer> cf = new CompletableFuture<>();
    cf.completeExceptionally(new TestException());
    Flowable.fromCompletionStage(cf).test().assertFailure(TestException.class);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 2 with TestException

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

the class FlowableFromStreamTest method closeCalledOnItemCrashConditional.

@Test
public void closeCalledOnItemCrashConditional() {
    AtomicInteger calls = new AtomicInteger();
    AtomicInteger counter = new AtomicInteger();
    Flowable.fromStream(Stream.<Integer>generate(() -> {
        int value = counter.getAndIncrement();
        if (value == 1) {
            throw new TestException();
        }
        return value;
    }).onClose(() -> calls.getAndIncrement())).filter(v -> true).test().assertFailure(TestException.class, 0);
    assertEquals(1, calls.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 3 with TestException

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

the class FlowableFromStreamTest method hasNextCrash.

@Test
public void hasNextCrash() {
    AtomicInteger v = new AtomicInteger();
    Flowable.fromStream(Stream.<Integer>generate(() -> {
        int value = v.getAndIncrement();
        if (value == 1) {
            throw new TestException();
        }
        return value;
    })).test().assertFailure(TestException.class, 0);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 4 with TestException

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

the class ObservableCollectWithCollectorTest method collectorAccumulatorDropSignalsToObservable.

@Test
public void collectorAccumulatorDropSignalsToObservable() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Observable<Integer> source = new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new IOException());
                observer.onComplete();
            }
        };
        source.collect(new Collector<Integer, Integer, Integer>() {

            @Override
            public Supplier<Integer> supplier() {
                return () -> 1;
            }

            @Override
            public BiConsumer<Integer, Integer> accumulator() {
                return (a, b) -> {
                    throw new TestException();
                };
            }

            @Override
            public BinaryOperator<Integer> combiner() {
                return (a, b) -> a + b;
            }

            @Override
            public Function<Integer, Integer> finisher() {
                return a -> a;
            }

            @Override
            public Set<Characteristics> characteristics() {
                return Collections.emptySet();
            }
        }).toObservable().test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    });
}
Also used : java.util(java.util) Observer(io.reactivex.rxjava3.core.Observer) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Assert.assertFalse(org.junit.Assert.assertFalse) Observable(io.reactivex.rxjava3.core.Observable) PublishSubject(io.reactivex.rxjava3.subjects.PublishSubject) Disposable(io.reactivex.rxjava3.disposables.Disposable) java.util.function(java.util.function) TestException(io.reactivex.rxjava3.exceptions.TestException) Observer(io.reactivex.rxjava3.core.Observer) TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) Observable(io.reactivex.rxjava3.core.Observable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 5 with TestException

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

the class ObservableFromCompletionStageTest method syncFailure.

@Test
public void syncFailure() {
    CompletableFuture<Integer> cf = new CompletableFuture<>();
    cf.completeExceptionally(new TestException());
    Observable.fromCompletionStage(cf).test().assertFailure(TestException.class);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestException(io.reactivex.rxjava3.exceptions.TestException) 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