我正在尝试为以下rest api调用编写单元,我的方法如下所示:
fun authenticate(email: String,
password: String,
onSuccess: () -> Unit,
onError: (message: String) -> Unit): Disposable? {
val mapper = AuthMapper(email, password)
val request = RestRequest(AuthRestRequestErrorHandler(), this.restService.authenticate(mapper))
return request.handleObservable<AuthResponseMapper>(
onSuccess = { authResponseMapper ->
this.storeAuthSession(LoginProvider.regular, authResponseMapper)
onSuccess()
},
onError = { error ->
onError(error.message)
}
)
}
目标是呼叫身份验证端点,接收自动加密令牌并测试另一种只能通过授权令牌才能调用的类似方法。
我来自iOS,那里有waitForExpectations和Expectation.fulfill()方法,可帮助我等待api响应并检查结果。那么android上是否有类似的东西或其他建议或正确的方法来做到这一点?