Skip to content

TestObserver always delegates to EMPTY, throws exception #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mttkay opened this issue Aug 12, 2014 · 4 comments
Closed

TestObserver always delegates to EMPTY, throws exception #1571

mttkay opened this issue Aug 12, 2014 · 4 comments
Labels
Milestone

Comments

@mttkay
Copy link
Contributor

mttkay commented Aug 12, 2014

I noticed that TestObserver was changed to always delegate calls, by default to the EMPTY Observer.

However, the EMPTY Observer does not define onError, so any attempt to use TestObserver with an observable that's supposed to fail in a unit test crashes the test with a OnErrorNotImplementedException

I wonder why this change was done? It adds complexity and surprise to something that should be void of behavior (mocks should record things, not perform logic IMHO)

@siggijons
Copy link

I had a problem with this to when using the TestObserver to test errors.
I'm using mockito so I worked this around creating my TestObservers like this:

    @SuppressWarnings("unchecked")
    public static <T> TestObserver<T> createTestObserver()
    {
        Observer<T> delegate = mock(Observer.class);
        return new TestObserver<T>(delegate);
    }

@benjchristensen benjchristensen added this to the 1.0 milestone Oct 7, 2014
@benjchristensen
Copy link
Member

Opening discussion about confusion between EmptyObserver and Observers.empty(): #1741

benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Oct 10, 2014
If a delegate is not provided then do nothing.
Fixes ReactiveX#1571
@benjchristensen
Copy link
Member

It will no longer throw an exception when a delegate is not provided. That was a mistake.

@mttkay
Copy link
Contributor Author

mttkay commented Oct 10, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants