Skip to content

Instantly share code, notes, and snippets.

@luserdroid
Created February 20, 2018 16:36
Show Gist options
  • Save luserdroid/714dc1630ace48f4c7988f3587319d13 to your computer and use it in GitHub Desktop.
Save luserdroid/714dc1630ace48f4c7988f3587319d13 to your computer and use it in GitHub Desktop.
LiveModel Test
//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