Skip to content

Instantly share code, notes, and snippets.

@rafakob
Last active June 14, 2016 10:45
Show Gist options
  • Save rafakob/d4df8a6b3ffeffbd929aa2ff915e189f to your computer and use it in GitHub Desktop.
Save rafakob/d4df8a6b3ffeffbd929aa2ff915e189f to your computer and use it in GitHub Desktop.
test mockito
public class LoginPresenter extends MvpPresenter<LoginView> {
public void register() {
blablaMethod();
}
public void blablaMethod(){
}
}
///////// TEST /////////
public class LoginPresenterTest {
private LoginPresenter loginPresenter;
private LoginView view;
@Before
public void setUp() throws Exception {
loginPresenter = Mockito.mock(LoginPresenter.class);
view = Mockito.mock(LoginView.class);
loginPresenter.bindView(view);
}
@Test
public void testLogin() throws Exception {
loginPresenter.register();
verify(loginPresenter).blablaMethod();
}
}
/////// RESULT /////
Wanted but not invoked:
loginPresenter.blablaMethod();
-> at io.tsh.spincar.ui.login.LoginPresenterTest.testLogin(LoginPresenterTest.java:23)
However, there were other interactions with this mock:
loginPresenter.register();
-> at io.tsh.spincar.ui.login.LoginPresenterTest.testLogin(LoginPresenterTest.java:22)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment