Last active
June 14, 2016 10:45
-
-
Save rafakob/d4df8a6b3ffeffbd929aa2ff915e189f to your computer and use it in GitHub Desktop.
test mockito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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