tenprint
05/19/2018, 4:26 PM...
api = mock(MyRetrofitApiClient::class.java)
...
@Test
fun getProfileFromServer_Error() {
`when`(api.getUser(USER_ID)).thenThrow(UnknownHostException()) <-- This throws a mockito error: "org.mockito.exceptions.base.MockitoException: Checked exception is invalid for this method!"
val testObserver = TestObserver<ProfileStateModel>()
api
.getUser(USER_ID))
.map { ProfileStateModel.Success(it) as ProfileStateModel }
.onErrorReturn { ProfileStateModel.Error(it) }
.subscribe(testObserver)
testObserver ... assert some things
}
I'm trying to write a test for a failed API call scenario, but I'm having trouble simulating the failure due to the above Mockito error. What's a better way to do this?