@Test public void flatMapSingleElementError() { RuntimeException exception = new RuntimeException("test"); Maybe.error(exception).flatMapSingleElement(new Function<Object, SingleSource<Object>>() { @Override public SingleSource<Object> apply(final Object integer) throws Exception { return Single.just(new Object()); } }) .test() .assertError(exception); }
@Test public void errorCallableThrows() { Maybe.error(new Callable<Throwable>() { @Override public Throwable call() throws Exception { throw new TestException(); } }) .test() .assertFailure(TestException.class); } }
@Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.<Integer>error(new TestException()).subscribeOn(Schedulers.computation()); } }, true, 128)
@Test public void onExceptionResumeNextPassthrough() { Maybe.error(new AssertionError()) .onExceptionResumeNext(Maybe.just(1)) .test() .assertFailure(AssertionError.class); }
@Test public void error() { Maybe.error(new TestException()) .test() .assertFailure(TestException.class); }
@SuppressWarnings("unchecked") @Test public void firstError() { Maybe.zip(Arrays.asList(Maybe.error(new TestException()), Maybe.just(1)), addString) .test() .assertFailure(TestException.class); }
@Test public void errorCallable() { Maybe.error(Functions.justCallable(new TestException())) .test() .assertFailure(TestException.class); }
@Test public void ignoreElementError() { Maybe.error(new TestException()) .ignoreElement() .test() .assertFailure(TestException.class); }
@Test public void error() { Maybe.error(new TestException()) .isEmpty() .test() .assertFailure(TestException.class); }
@SuppressWarnings("unchecked") @Test public void onErrorCompletePredicateThrows() { TestHelper.assertCompositeExceptions(Maybe.error(new TestException()) .onErrorComplete(new Predicate<Throwable>() { @Override public boolean test(Throwable v) throws Exception { throw new IOException(); } }) .test(), TestException.class, IOException.class); }
@Test public void andThenMaybeCompleteError() { Completable.complete() .andThen(Maybe.error(new RuntimeException("test"))) .test() .assertNotComplete() .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("test"); }
@Test public void errorConditional() { Maybe.<Integer>error(new TestException()) .doAfterSuccess(afterSuccess) .filter(Functions.alwaysTrue()) .subscribeWith(to) .assertFailure(TestException.class); assertTrue(values.isEmpty()); }
@Test public void mainError() { Maybe.error(new TestException()) .delaySubscription(Flowable.empty()) .test() .assertFailure(TestException.class); }
@Test public void ignoreElementErrorMaybe() { Maybe.error(new TestException()) .ignoreElement() .toMaybe() .test() .assertFailure(TestException.class); }
@Test public void mergeErrorSuccess() { Maybe.merge(Maybe.error(new TestException()), Maybe.just(1)) .test() .assertFailure(TestException.class); }
@Test public void onExceptionResumeNext() { Maybe.error(new TestException()) .onExceptionResumeNext(Maybe.just(1)) .test() .assertResult(1); }
@Test public void error() { Maybe.<Integer>error(new TestException()).switchIfEmpty(Single.just(2)) .test().assertFailure(TestException.class); }
@Test public void error() { Maybe.error(new TestException()).delay(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); }
@Test public void concatPublisherDelayError() { Maybe.concatDelayError(Flowable.just(Maybe.empty(), Maybe.just(1), Maybe.error(new TestException()))) .test() .assertFailure(TestException.class, 1); Maybe.concatDelayError(Flowable.just(Maybe.error(new TestException()), Maybe.empty(), Maybe.just(1))) .test() .assertFailure(TestException.class, 1); }
@Test public void onErrorNull() { TestObserver<Integer> to = Maybe.<Integer>error(new TestException()) .flatMap(Functions.justFunction(Maybe.just(1)), Functions.justFunction((Maybe<Integer>)null), Functions.justCallable(Maybe.just(1))) .test() .assertFailure(CompositeException.class); List<Throwable> ce = TestHelper.compositeList(to.errors().get(0)); TestHelper.assertError(ce, 0, TestException.class); TestHelper.assertError(ce, 1, NullPointerException.class); }