Search in sources :

Example 41 with Maybe

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

the class HttpEntityMethodArgumentResolverTests method httpEntityWithMaybeBody.

@Test
public void httpEntityWithMaybeBody() {
    ServerWebExchange exchange = postExchange("line1");
    ResolvableType type = httpEntityType(Maybe.class, String.class);
    HttpEntity<Maybe<String>> httpEntity = resolveValue(exchange, type);
    assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
    assertThat(httpEntity.getBody().blockingGet()).isEqualTo("line1");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) Maybe(io.reactivex.rxjava3.core.Maybe) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 42 with Maybe

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

the class HttpEntityMethodArgumentResolverTests method emptyBodyWithMaybe.

@Test
public void emptyBodyWithMaybe() {
    ResolvableType type = httpEntityType(Maybe.class, String.class);
    HttpEntity<Maybe<String>> entity = resolveValueWithEmptyBody(type);
    StepVerifier.create(entity.getBody().toFlowable()).expectNextCount(0).expectComplete().verify();
}
Also used : Maybe(io.reactivex.rxjava3.core.Maybe) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 43 with Maybe

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

the class TransformerTest method maybeTransformerThrows.

@Test
public void maybeTransformerThrows() {
    try {
        Maybe.just(1).compose(new MaybeTransformer<Integer, Integer>() {

            @Override
            public Maybe<Integer> apply(Maybe<Integer> v) {
                throw new TestException("Forced failure");
            }
        });
        fail("Should have thrown!");
    } catch (TestException ex) {
        assertEquals("Forced failure", ex.getMessage());
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test) ConverterTest(io.reactivex.rxjava3.core.ConverterTest)

Example 44 with Maybe

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

the class XFlatMapTest method maybeMaybe.

@Test
public void maybeMaybe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Maybe.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 45 with Maybe

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

the class XFlatMapTest method maybeCombiner.

@Test
public void maybeCombiner() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Maybe.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }, (a, b) -> a + b).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) List(java.util.List) CyclicBarrier(java.util.concurrent.CyclicBarrier) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) Publisher(org.reactivestreams.Publisher) Assert.assertTrue(org.junit.Assert.assertTrue) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) org.junit(org.junit) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) TestException(io.reactivex.rxjava3.exceptions.TestException)

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