Skip to content

Instantly share code, notes, and snippets.

@travisdachi
Created July 22, 2018 14:29
Show Gist options
  • Save travisdachi/3587e0ea3e0a847dbc84c6bd29a2bb46 to your computer and use it in GitHub Desktop.
Save travisdachi/3587e0ea3e0a847dbc84c6bd29a2bb46 to your computer and use it in GitHub Desktop.
class MyPresenter(val api: Api, val view: MyView) {
fun onSubmitClick() {
api.submit().subscribe(
onNext = { data -> view.showSuccess(data) },
onError = { throwable -> view.showErrorDialog(throwable) }
)
}
}
fun testMyPresenterOnSubmitFail() {
val view: MyView = mock()
val mockApi: Api = mock {
// จัดฉาก
on(it.submit()).thenReturn(Observable.error(Throwable()))
}
val presenter = MyPresenter(mockApi, view)
presenter.onSubmitClick()
// วัดผล
verify(view).showErrorDialog(any())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment