Guest User

Untitled

a guest
Jul 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class MyPresenter(val api: Api, val view: MyView) {
  2. fun onSubmitClick() {
  3. api.submit().subscribe(
  4. onNext = { data -> view.showSuccess(data) },
  5. onError = { throwable -> view.showErrorDialog(throwable) }
  6. )
  7. }
  8. }
  9.  
  10. fun testMyPresenterOnSubmitFail() {
  11. val view: MyView = mock()
  12. val mockApi: Api = mock {
  13. // จัดฉาก
  14. on(it.submit()).thenReturn(Observable.error(Throwable()))
  15. }
  16. val presenter = MyPresenter(mockApi, view)
  17.  
  18. presenter.onSubmitClick()
  19. // วัดผล
  20. verify(view).showErrorDialog(any())
  21. }
Add Comment
Please, Sign In to add comment