use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class XFlatMapTest method observerMaybe.
@Test
public void observerMaybe() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Integer> to = Observable.just(1).subscribeOn(Schedulers.io()).flatMapMaybe(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();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class XFlatMapTest method singleMaybe.
@Test
public void singleMaybe() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Integer> to = Single.just(1).subscribeOn(Schedulers.io()).flatMapMaybe(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();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class XFlatMapTest method flowableMaybe.
@Test
public void flowableMaybe() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Flowable.just(1).subscribeOn(Schedulers.io()).flatMapMaybe(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(ts);
ts.cancel();
Thread.sleep(SLEEP_AFTER_CANCEL);
ts.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class ConverterTest method maybeConverterThrows.
@Test
public void maybeConverterThrows() {
try {
Maybe.just(1).to(new MaybeConverter<Integer, Integer>() {
@Override
public Integer apply(Maybe<Integer> v) {
throw new TestException("Forced failure");
}
});
fail("Should have thrown!");
} catch (TestException ex) {
assertEquals("Forced failure", ex.getMessage());
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class FlowableMergeWithMaybeTest method onErrorMainOverflow.
@Test
public void onErrorMainOverflow() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final AtomicReference<Subscriber<?>> subscriber = new AtomicReference<>();
TestSubscriber<Integer> ts = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
subscriber.set(s);
}
}.mergeWith(Maybe.<Integer>error(new IOException())).test();
subscriber.get().onError(new TestException());
ts.assertFailure(IOException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations