Search in sources :

Example 1 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project spring-framework by spring-projects.

the class RequestBodyMethodArgumentResolverTests method emptyBodyWithMaybe.

@Test
public void emptyBodyWithMaybe() {
    MethodParameter param = this.testMethod.annot(requestBody()).arg(Maybe.class, String.class);
    Maybe<String> maybe = resolveValueWithEmptyBody(param);
    StepVerifier.create(maybe.toFlowable()).expectNextCount(0).expectError(ServerWebInputException.class).verify();
    param = this.testMethod.annot(requestBody().notRequired()).arg(Maybe.class, String.class);
    maybe = resolveValueWithEmptyBody(param);
    StepVerifier.create(maybe.toFlowable()).expectNextCount(0).expectComplete().verify();
}
Also used : ServerWebInputException(org.springframework.web.server.ServerWebInputException) Maybe(io.reactivex.rxjava3.core.Maybe) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 2 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeCacheTest method crossCancelOnError.

@Test
public void crossCancelOnError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    Maybe<Integer> source = pp.singleElement().cache();
    source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            ts.cancel();
        }
    });
    source.toFlowable().subscribe(ts);
    pp.onError(new TestException());
    ts.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 3 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeDoOnEventTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final Disposable bs = Disposable.empty();
        new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                observer.onComplete();
                observer.onSuccess(1);
            }
        }.doOnSubscribe(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable d) throws Exception {
                throw new TestException("First");
            }
        }).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(bs.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 4 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeConcatArrayTest method errorAfterTermination.

@Test
public void errorAfterTermination() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final MaybeObserver<?>[] o = { null };
        Maybe.concatArrayDelayError(Maybe.just(1), Maybe.error(new IOException()), new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onSuccess(2);
                o[0] = observer;
            }
        }).test().assertFailure(IOException.class, 1, 2);
        o[0].onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeBlockingSubscribeTest method oneArgErrorAsync.

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

Aggregations

Test (org.junit.Test)55 TestException (io.reactivex.rxjava3.exceptions.TestException)38 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 Maybe (io.reactivex.rxjava3.core.Maybe)12 InOrder (org.mockito.InOrder)12 Flowable (io.reactivex.rxjava3.core.Flowable)10 Observable (io.reactivex.rxjava3.core.Observable)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Single (io.reactivex.rxjava3.core.Single)8 IOException (java.io.IOException)8 Predicate (io.reactivex.rxjava3.functions.Predicate)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Type (java.lang.reflect.Type)6 Test (org.junit.jupiter.api.Test)6 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Completable (io.reactivex.rxjava3.core.Completable)4 Action (io.reactivex.rxjava3.functions.Action)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)4 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)4