What is the right way to mock an RxJava Observable
<p>I have an API which returns <code>Observable</code>'s to be used with RxJava. For testing I want to avoid network operations so plan to mock the responses. However as all responses must me wrapped with <code>Observable</code> and the <code>from()</code> method expects a <code>Future</code> not a concrete type, my mock class is convoluted with anonymous wrapper classes and I think there must be a better way. </p>

<p>Here is what I have:</p>

<pre><code>public class MockApi implements MyApi {

    @Override
    public Observable&lt;MyData&gt; getMyData() {
        return Observable.from(new Future&lt;MyData&gt;() {

            @Override public boolean cancel(boolean mayInterruptIfRunning) { return false; }
            @Override public boolean isCancelled() { return false; }
            @Override public boolean isDone() { return false; }

            @Override
            public MyData get(long timeout, TimeUnit unit) throws InterruptedException,
                    ExecutionException, TimeoutException {
                return get();
            }

            @Override
            public MyData get() throws InterruptedException, ExecutionException {
                return new MyData();
            }

        });
    }

    ...

}
</code></pre>

<p>Is there a better way?</p>