Skip to content

Instantly share code, notes, and snippets.

@varshabhatia007
Last active May 19, 2019 12:39
Show Gist options
  • Save varshabhatia007/3373f6597b5099b281462c42bd5ec828 to your computer and use it in GitHub Desktop.
Save varshabhatia007/3373f6597b5099b281462c42bd5ec828 to your computer and use it in GitHub Desktop.
@Mock
private lateinit var view: CustomerView
@Mock
private lateinit var usecase: CustomerUsecase
private lateinit var presenter: CustomerPresenter
@Test
fun `should show customer data`() {
val expectedResponse = mock(CustomerDetail::class.java)
`when`(usecase.getCustomerData()).thenReturn(Single.just(expectedResponse))
presenter.onResume()
verify(usecase).getCustomerData()
verify(view).showLoader()
verify(view).hideLoader()
verify(view).populateData(expectedResponse)
}
@Test
fun `should show error when customer response call fails`() {
`when`(usecase.getDaily()).thenReturn(Single.error(Exception()))
presenter.onResume()
verify(usecase).getCustomerData()
verify(view).showLoader()
verify(view).hideLoader()
verify(view).showError()
}
@Test
fun `should show error when network is unavailable`() {
val res = mock(Resources::class.java)
`when`(res.getString(R.string.generic_server_error)).thenReturn("Something went wrong")
`when`(usecase.getCustomerData()).thenReturn(Single.error(NetworkError(Exception(), res)))
presenter.onResume()
verify(usecase).getCustomerData()
verify(view).showLoader()
verify(view).hideLoader()
verify(view).showError(ErrorModel(-1, "Something went wrong"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment