Search in sources :

Example 26 with TestException

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

the class MaybeFlattenStreamAsObservableTest method hasNextThrowsInDrain.

@Test
public void hasNextThrowsInDrain() {
    @SuppressWarnings("unchecked") Stream<Integer> stream = mock(Stream.class);
    when(stream.iterator()).thenReturn(new Iterator<Integer>() {

        int count;

        @Override
        public boolean hasNext() {
            if (count++ > 0) {
                throw new TestException();
            }
            return true;
        }

        @Override
        public Integer next() {
            return 1;
        }
    });
    Maybe.just(1).flattenStreamAsObservable(v -> stream).test().assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 27 with TestException

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

the class FlowableCollectWithCollectorTest method collectorAccumulatorDropSignals.

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

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onNext(2);
                s.onError(new IOException());
                s.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();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    });
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 28 with TestException

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

the class FlowableZipIterableTest method zipIterableNextThrows.

@Test
public void zipIterableNextThrows() {
    PublishProcessor<String> r1 = PublishProcessor.create();
    /* define a Subscriber to receive aggregated events */
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    InOrder io = inOrder(subscriber);
    Iterable<String> r2 = new Iterable<String>() {

        @Override
        public Iterator<String> iterator() {
            return new Iterator<String>() {

                @Override
                public boolean hasNext() {
                    return true;
                }

                @Override
                public String next() {
                    throw new TestException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }
    };
    r1.zipWith(r2, zipr2).subscribe(subscriber);
    r1.onError(new TestException());
    io.verify(subscriber).onError(any(TestException.class));
    verify(subscriber, never()).onNext(any(String.class));
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) CrashingIterable(io.reactivex.rxjava3.internal.util.CrashingIterable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 29 with TestException

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

the class NotificationLiteTest method errorNotification.

@Test
public void errorNotification() {
    Object o = NotificationLite.error(new TestException());
    assertEquals("NotificationLite.Error[io.reactivex.rxjava3.exceptions.TestException]", o.toString());
    assertTrue(NotificationLite.isError(o));
    assertFalse(NotificationLite.isComplete(o));
    assertFalse(NotificationLite.isDisposable(o));
    assertFalse(NotificationLite.isSubscription(o));
    assertTrue(NotificationLite.getError(o) instanceof TestException);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 30 with TestException

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

the class MaybeAmbTest method noWinnerErrorDispose.

@Test
public void noWinnerErrorDispose() throws Exception {
    final TestException ex = new TestException();
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        final AtomicBoolean interrupted = new AtomicBoolean();
        final CountDownLatch cdl = new CountDownLatch(1);
        Maybe.ambArray(Maybe.error(ex).subscribeOn(Schedulers.single()).observeOn(Schedulers.computation()), Maybe.never()).subscribe(Functions.emptyConsumer(), new Consumer<Throwable>() {

            @Override
            public void accept(Throwable e) throws Exception {
                interrupted.set(Thread.currentThread().isInterrupted());
                cdl.countDown();
            }
        });
        assertTrue(cdl.await(500, TimeUnit.SECONDS));
        assertFalse("Interrupted!", interrupted.get());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) 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