Why does Mockito test the mock instead of the object under test?
<p>I am just getting up to speed with Mockito and I don't find it particularly useful.</p>

<p>I have a View and a Presenter. The view is a dumb activity and the presenter contains all the business logic. I want to mock the View and test the way the Presenter works.</p>

<p>Here comes Mockito, I can successfully mock the View and these two unit tests work just fine:</p>

<pre><code>@Test
public void testWhenUserNameIsEmptyShowErrorOnLoginClicked() throws Exception {
    Mockito.when(loginView.getUserName()).thenReturn("");
    Mockito.when(loginView.getPassword()).thenReturn("asdasd");
    loginPresenter.setLoginView(loginView);
    loginPresenter.onLoginClicked();
    Mockito.verify(loginView).setEmailFieldErrorMessage();
}

@Test
public void testWhenPasswordIsEmptyShowErrorOnPasswordClicked() throws Exception {
    Mockito.when(loginView.getUserName()).thenReturn("George");
    Mockito.when(loginView.getPassword()).thenReturn("");
    loginPresenter.setLoginView(loginView);
    loginPresenter.onLoginClicked();
    Mockito.verify(loginView).setPasswordFieldErrorMessage();
}
</code></pre>

<p>However, if I want to test the presenter's inner methods, this doesn't work:</p>

<pre><code>@Test
public void testWhenUserNameAndPasswordAreEnteredShouldAttemptLogin() throws Exception {
    LoginView loginView = Mockito.mock(LoginView.class);
    Mockito.when(loginView.getUserName()).thenReturn("George");
    Mockito.when(loginView.getPassword()).thenReturn("aaaaaa");
    loginPresenter.setLoginView(loginView);
    loginPresenter.onLoginClicked();
    Mockito.verify(loginPresenter).attemptLogin(loginView.getUserName(), loginView.getPassword());
}
</code></pre>

<p>it throws a NotAMockException - it says the object should be a Mock. Why would I want to test the mock? It is one of the first rules in testing - you don't create a mock and then test it, you have an object that you want to test and if it needs some dependencies - you mock them.</p>

<p>Maybe I don't understand Mockito properly but it seems useless to me this way. What do I do?</p>