Created
July 22, 2018 14:29
-
-
Save travisdachi/3587e0ea3e0a847dbc84c6bd29a2bb46 to your computer and use it in GitHub Desktop.
This file contains 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
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