kingsley.gomes
04/26/2018, 11:59 AM@RunWith(JUnitPlatform::class)
class AccountCheckViewModelTest : Spek({
include(RxSchedulersOverrideRule)
val httpException = mock<HttpException> {
on { code() }.thenReturn(400)
}
given(" account check") {
var accountCheckRequest = mock<CheckExistingAccountRequest>()
var accountCheckResponse = mock<CheckExistingAccountResponse>()
var webService = mock<IAPICalls>()
val accountCheckViewModel = spy(VMAccountCheck(webService))
beforeEachTest {
accountCheckRequest = mock<CheckExistingAccountRequest>() {
on { email }.thenReturn("foo@mail")
}
accountCheckResponse = mock<CheckExistingAccountResponse>() {
on { firstName }.thenReturn("foo")
on { email }.thenReturn("foo@mail")
}
webService = mock<IAPICalls> {
on { checkExistingAccount(accountCheckRequest) }.thenReturn(Flowable.just(accountCheckResponse))
}
}
on("api success") {
accountCheckViewModel.checkIfAccountExists(request = accountCheckRequest)
it("it:: should call live data with first name as foo") {
verify(accountCheckViewModel, times(1)).updateLiveData(accountCheckResponse.firstName, accountCheckResponse.email, null)
}
}
}
and associated stacktrace : https://pastebin.com/gy6dLtGgraniejade
04/27/2018, 1:15 AMVMAccountCheck
?raniejade
04/27/2018, 2:02 AM