OperationFromFunctionals { public static <R> OnSubscribeFunc<R> fromCallable(Callable<? extends R> callable) { return new InvokeAsyncCallable<R>(callable); } private  OperationFromFunctionals(); static OnSubscribeFunc<R> fromAction(Action0 action, R result); static OnSubscribeFunc<R> fromFunc0(Func0<? extends R> function); static OnSubscribeFunc<R> fromCallable(Callable<? extends R> callable); static OnSubscribeFunc<R> fromRunnable(final Runnable run, final R result);  }
@Test public void testFromCallable() { Callable<Integer> callable = new Callable<Integer>() { @Override public Integer call() throws Exception { return 1; } }; Observable<Integer> source = Async.fromCallable(callable, scheduler); for (int i = 0; i < 3; i++) { Observer<Object> observer = mock(Observer.class); source.subscribe(new TestObserver<Object>(observer)); InOrder inOrder = inOrder(observer); inOrder.verify(observer, never()).onNext(any()); inOrder.verify(observer, never()).onCompleted(); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); inOrder.verify(observer, times(1)).onNext(1); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); verify(observer, never()).onError(any(Throwable.class)); } }
@Test public void testFromCallableThrows() { Callable<Integer> callable = new Callable<Integer>() { @Override public Integer call() throws Exception { throw new IOException("Forced failure!"); } }; Observable<Integer> source = Async.fromCallable(callable, scheduler); testRunShouldThrow(source, IOException.class); }