Created
February 20, 2018 16:36
-
-
Save luserdroid/714dc1630ace48f4c7988f3587319d13 to your computer and use it in GitHub Desktop.
LiveModel Test
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
//code | |
fun loginWithUsernameAndPassword(username: String, password: String) { | |
liveSignInStatus.value = PasswordAuthState.LOADING | |
doAsync { | |
val resultBody = loginManager.loginWithCredential(username, password) | |
when (resultBody.getStatusCode()) { | |
200 -> liveSignInStatus.postValue(PasswordAuthState.SUCCESS) | |
401 -> liveSignInStatus.postValue(PasswordAuthState.INVALID_PASSWORD_OR_USERNAME) | |
else -> liveSignInStatus.postValue(PasswordAuthState.GENERAL_ERROR) | |
} | |
} | |
} | |
//test | |
@Test | |
fun testLoginWithUsernameAndPassword200() { | |
runAndVerifyLoginWithUsernameAndPassword(200, PasswordAuthState.SUCCESS) | |
} | |
private fun runAndVerifyLoginWithUsernameAndPassword(statusCode: Int, expectedState: PasswordAuthState) { | |
this.statusCode = statusCode | |
val task = loginViewModel.loginWithUsernameAndPassword(USER, PASSWORD) | |
verify(lifeData).value = PasswordAuthState.LOADING | |
task.get() | |
verify(lifeData, times(1)).postValue(expectedState) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment