How to fix this mockito error (chapter 9)

Hi,

I have been studying MVP testing (chapter 9) and I am getting this error:

io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.RuntimeException: Method d in android.util.Log not mocked. See http://g.co/androidstudio/not-mocked for details.
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
at io.reactivex.Observable.subscribe(Observable.java:12292)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.internal.schedulers.TrampolineScheduler.scheduleDirect(TrampolineScheduler.java:52)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn.subscribeActual(ObservableSubscribeOn.java:36)
at io.reactivex.Observable.subscribe(Observable.java:12285)
at io.reactivex.internal.operators.observable.ObservableObserveOn.subscribeActual(ObservableObserveOn.java:41)
at io.reactivex.Observable.subscribe(Observable.java:12285)
at io.reactivex.Observable.subscribeWith(Observable.java:12337)
at com.raywenderlich.wewatch.main.MainPresenter.getMyMoviesList(MainPresenter.kt:46)

Basically the problem is Presenter class has import android.util.Log. The tests on source code given with book is working fine (chapter 9 final) but mine is not working somehow. Can anyone help me fix this?

@yuncheng13 Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi! On the surface, this error message is happening because we have not mocked the Log.d method. Next time you encounter this error message, you can go ahead and comment out the logging on line 65 of MainPresenter and you should see the error message go away. However, on a deeper level, the reason this error message is thrown is that some error, such as a NullPointer, has occurred in the observable flow, leading the observer to invoke its observer’s onError method on line 64. (You should be able to confirm this if you put break points in the onError method and step through your code to see that onError gets invoked.) Please double check that your code for MainPresenter#getMyMoviesList() matches the solution, and that you’ve correctly mocked the observable’s behavior in MainPresenterTests#testGetMyMoviesList().

As you noted, the solution tests are working fine, because the onError method does NOT get called, and the test never touches the unmocked logging on line 65.