Search in sources :

Example 21 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class BaseTestConsumer method fail.

/**
 * Fail with the given message and add the sequence of errors as suppressed ones.
 * <p>Note this is deliberately the only fail method. Most of the times an assertion
 * would fail but it is possible it was due to an exception somewhere. This construct
 * will capture those potential errors and report it along with the original failure.
 *
 * @param message the message to use
 * @return AssertionError the prepared AssertionError instance
 */
@NonNull
protected final AssertionError fail(@NonNull String message) {
    StringBuilder b = new StringBuilder(64 + message.length());
    b.append(message);
    b.append(" (").append("latch = ").append(done.getCount()).append(", ").append("values = ").append(values.size()).append(", ").append("errors = ").append(errors.size()).append(", ").append("completions = ").append(completions);
    if (timeout) {
        b.append(", timeout!");
    }
    if (isDisposed()) {
        b.append(", disposed!");
    }
    CharSequence tag = this.tag;
    if (tag != null) {
        b.append(", tag = ").append(tag);
    }
    b.append(')');
    AssertionError ae = new AssertionError(b.toString());
    if (!errors.isEmpty()) {
        if (errors.size() == 1) {
            ae.initCause(errors.get(0));
        } else {
            CompositeException ce = new CompositeException(errors);
            ae.initCause(ce);
        }
    }
    return ae;
}
Also used : CompositeException(io.reactivex.rxjava3.exceptions.CompositeException)

Example 22 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class SerializedProcessorTest method onErrorQueued.

@Test
public void onErrorQueued() {
    FlowableProcessor<Integer> sp = PublishProcessor.<Integer>create().toSerialized();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(@NonNull Integer t) {
            super.onNext(t);
            if (t == 1) {
                sp.onNext(2);
                sp.onSubscribe(new BooleanSubscription());
                sp.onError(new TestException());
            }
        }
    };
    sp.subscribe(ts);
    sp.onNext(1);
    // errors skip ahead
    ts.assertFailure(TestException.class, 1);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) NonNull(io.reactivex.rxjava3.annotations.NonNull) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 23 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class MaybeSafeSubscribeTest method onCompleteCrash.

@Test
public void onCompleteCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
        doThrow(new TestException()).when(consumer).onComplete();
        new Maybe<Integer>() {

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

Example 24 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class SerializedSubjectTest method onErrorQueued.

@Test
public void onErrorQueued() {
    Subject<Integer> sp = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = new TestObserver<Integer>() {

        @Override
        public void onNext(@NonNull Integer t) {
            super.onNext(t);
            if (t == 1) {
                sp.onNext(2);
                sp.onNext(3);
                sp.onSubscribe(Disposable.empty());
                sp.onError(new TestException());
            }
        }
    };
    sp.subscribe(to);
    sp.onNext(1);
    // errors skip ahead
    to.assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) NonNull(io.reactivex.rxjava3.annotations.NonNull) TestObserver(io.reactivex.rxjava3.observers.TestObserver) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 25 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class CompletableSafeSubscribeTest method onCompleteCrash.

@Test
public void onCompleteCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        CompletableObserver consumer = mock(CompletableObserver.class);
        doThrow(new TestException()).when(consumer).onComplete();
        new Completable() {

            @Override
            protected void subscribeActual(@NonNull CompletableObserver observer) {
                observer.onSubscribe(Disposable.empty());
                // none of the following should arrive at the consumer
                observer.onComplete();
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verify(consumer).onComplete();
        order.verifyNoMoreInteractions();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 Disposable (io.reactivex.rxjava3.disposables.Disposable)15 NonNull (io.reactivex.rxjava3.annotations.NonNull)10 InOrder (org.mockito.InOrder)10 TestException (io.reactivex.rxjava3.exceptions.TestException)9 IOException (java.io.IOException)9 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 Assert (org.junit.Assert)7 java.util.stream (java.util.stream)6 Iterator (java.util.Iterator)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 QueueFuseable (io.reactivex.rxjava3.operators.QueueFuseable)4 QueueSubscription (io.reactivex.rxjava3.operators.QueueSubscription)4 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)4 Mockito (org.mockito.Mockito)4 Subscription (org.reactivestreams.Subscription)4 Schedulers (io.reactivex.rxjava3.schedulers.Schedulers)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)3 Function (io.reactivex.rxjava3.functions.Function)2