Created
December 12, 2017 11:21
-
-
Save alaershov/3f33f4830607c9c79143620f10aab2df to your computer and use it in GitHub Desktop.
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
@RunWith(MockitoJUnitRunner.class) | |
public final class LoginPresenterTest { | |
private static final String LOGIN_CORRECT = "79990001234"; | |
private static final String LOGIN_WRONG = "79990001111"; | |
private static final String PASSWORD_CORRECT = "123456"; | |
private static final String PASSWORD_WRONG = "111222333"; | |
private static final UserInfo USER_INFO = UserInfo.fromLogin(LOGIN_CORRECT); | |
@Mock | |
Router router; | |
@Mock | |
LoginUseCase loginUseCase; | |
@Mock | |
GetUserInfoUseCase getUserInfoUseCase; | |
@Mock | |
LoginTracker loginTracker; | |
@Mock | |
LoginView loginView; | |
private LoginPresenter presenter; | |
@Before | |
public void setUp() { | |
presenter = new LoginPresenter(router, Schedulers.trampoline(), loginUseCase, getUserInfoUseCase, loginTracker); | |
presenter.attachView(loginView); | |
when(loginUseCase.login(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())) | |
.thenReturn(Single.error(ErrorBundle.fromCode(ErrorCodes.Auth.WRONG_CREDENTIALS))); | |
when(loginUseCase.login(LOGIN_CORRECT, PASSWORD_CORRECT)) | |
.thenReturn(Single.just(LoginUseCase.LoginResult.NEW_SESSION)); | |
when(getUserInfoUseCase.get()) | |
.thenReturn(Single.just(USER_INFO)); | |
} | |
@Test | |
public void login_correctCredentialsNewSession_Success() throws Exception { | |
presenter.onLoginClicked(LOGIN_CORRECT, PASSWORD_CORRECT); | |
verify(router).navigateTo(Screens.PIN_CODE_CREATE); | |
verify(loginView).showProgress(); | |
verify(loginView).hideProgress(); | |
verify(loginView, never()).showErrorBundle(ArgumentMatchers.any()); | |
} | |
@Test | |
public void login_correctCredentialsResumeSession_Success() throws Exception { | |
when(loginUseCase.login(LOGIN_CORRECT, PASSWORD_CORRECT)) | |
.thenReturn(Single.just(LoginUseCase.LoginResult.RESUMED_SESSION)); | |
presenter.onLoginClicked(LOGIN_CORRECT, PASSWORD_CORRECT); | |
verify(router).navigateTo(Screens.PIN_CODE_CREATE); | |
verify(loginView).showProgress(); | |
verify(loginView).hideProgress(); | |
verifyNoMoreInteractions(loginView); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment