How / I unit test EventBus Events with Mockito?

I am using Otto EventBus in my Android app.

In my class, LoginNetworkOperationI detect various types of network connection errors, and I send different bus events for each of them, and the class is LoginPresenterregistered as a listener and certain methods are called when these events are fired.

My question is how (and should I) do a unit test, did I select LoginNetworkOperationthis event and LoginPresenterhandle it with Mockito?

I considered this question: unit tests of Guava EventBus , but it does not contain enough information, especially regarding implementation.

public class LoginNetworkOperation {

    public void execute(String username, String password) {
        try {
            // retrofit attempt
        } catch (Exception e) {
            bus.post(new ExceptionEvent(e));
        }
    }
}

public class LoginPresenter {

    void onExceptionEvent(ExceptionEvent exceptionEvent) {
        // Do Something with the exception event
    }
}

Also, should there be Subject Under Testand which should be the mocked object?

JUnit + Mockito + Robolectric Android Studio, -

+4
1

, ( ) unit testLoginNetworkOperation , LoginPresenter Mockito?

: .

" " LoginNetworkOperation, EventBus LoginPresenter, LoginNetworkOperation , LoginPresenter.


:

  • LoginNetworkOperation.execute: mock EventBus , ExceptionEvent .
  • LoginPresenter.onExceptionEvent: ExceptionEvents.
  • EventBus.post: mocked ExceptionEvent -Handler, ExceptionEvent , .
+3

All Articles