@Override public SingleSource<Integer> apply(Integer v) throws Exception { return Single.error(new TestException()); } })
@Override public Single<Integer> apply(Integer v) throws Exception { sleep(); return Single.<Integer>error(new TestException()); } })
@Test public void flatMapError() { RuntimeException exception = new RuntimeException("test"); Single.error(exception).flatMap(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 flatMapMaybeError() { RuntimeException exception = new RuntimeException("test"); Single.error(exception).flatMapMaybe(new Function<Object, MaybeSource<Object>>() { @Override public MaybeSource<Object> apply(final Object integer) throws Exception { return Maybe.just(new Object()); } }) .test() .assertError(exception); }
@Test(timeout = 5000) public void toFutureThrows() throws Exception { try { Single.error(new TestException()).toFuture().get(); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); } }
@Test(timeout = 5000, expected = TestException.class) public void fromSingleThrows() { Completable c = Completable.fromSingle(Single.error(new Callable<Throwable>() { @Override public Throwable call() { return new TestException(); } })); c.blockingAwait(); }
@Test public void errorCallableThrows() { Single.error(new Callable<Throwable>() { @Override public Throwable call() throws Exception { throw new TestException(); } }) .test() .assertFailure(TestException.class); } }
@SuppressWarnings("unchecked") @Test public void ambIterableOrder() { Single<Integer> error = Single.error(new RuntimeException()); Single.amb(Arrays.asList(Single.just(1), error)).test().assertValue(1); }
@Test public void doOnError() { final Object[] event = { null }; Single.error(new TestException()).doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable e) throws Exception { event[0] = e; } }) .test(); assertTrue(event[0].toString(), event[0] instanceof TestException); }
@Test public void ambWithOrder() { Single<Integer> error = Single.error(new RuntimeException()); Single.just(1).ambWith(error).test().assertValue(1); }
@SuppressWarnings("unchecked") @Test public void ambArrayOrder() { Single<Integer> error = Single.error(new RuntimeException()); Single.ambArray(Single.just(1), error).test().assertValue(1); }
@Test public void error() { Single.<Integer>error(new TestException()) .doAfterSuccess(afterSuccess) .subscribeWith(to) .assertFailure(TestException.class); assertTrue(values.isEmpty()); }
@SuppressWarnings("unchecked") @Test public void secondError() { Single.zip(Arrays.asList(Single.just(1), Single.<Integer>error(new TestException())), addString) .test() .assertFailure(TestException.class); }
@Test public void singleToMaybeError() { Single.error(new TestException()) .toMaybe() .test() .assertFailure(TestException.class); }
@Test public void error() { Single.<Integer>error(new TestException()).flattenAsObservable(new Function<Integer, Iterable<Integer>>() { @Override public Iterable<Integer> apply(Integer v) throws Exception { return Arrays.asList(v, v + 1); } }) .test() .assertFailure(TestException.class); }
@Test public void withSingleErrors() { Single.just(1) .delaySubscription(Single.error(new TestException())) .test() .assertFailure(TestException.class); }
@Test public void noRequestOnError() { Flowable.empty() .mergeWith(Single.error(new TestException())) .test(0) .assertFailure(TestException.class); }
@Test public void innerError() { Flowable.just(1) .concatMapSingle(Functions.justFunction(Single.error(new TestException()))) .test() .assertFailure(TestException.class); }
@Test public void error() { Single.error(new TestException()) .observeOn(Schedulers.single()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); } }
@Test public void delayedErrorOnError() { final TestScheduler scheduler = new TestScheduler(); final TestObserver<?> observer = Single.error(new TestException()) .delay(5, TimeUnit.SECONDS, scheduler, true) .test(); scheduler.advanceTimeTo(2, TimeUnit.SECONDS); observer.assertNoErrors(); scheduler.advanceTimeTo(5, TimeUnit.SECONDS); observer.assertError(TestException.class); }