Created
May 17, 2019 09:22
-
-
Save varshabhatia007/10fbe4f33f69f9525456dd46d7de466a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Mock | |
private lateinit var endPoint: CustomerEndPoint | |
private lateinit var repo: CustomerRepoImpl | |
@Test | |
fun `should return customer data`() { | |
val expectedCustomerResponse = mock(CustomerDetailResponse::class.java) | |
`when`(endPoint.getCustomerData()).thenReturn(Single.create { it.onSuccess(Response.success(expectedCustomerResponse)) }) | |
val expectedCustomerDetail = mock(CustomerDetail::class.java) | |
`when`(expectedexpectedCustomerResponse.data).thenReturn(expectedCustomerDetail) | |
repo.fetchCustomerDetail().test() | |
.assertComplete() | |
.assertNoErrors() | |
.assertValue { | |
Assert.assertEquals(expectedCustomerDetail, it) | |
true | |
} | |
verify(endPoint).getCustomerDetail() | |
} | |
@Test | |
fun `should return error for customer detail`() { | |
val body = ResponseBody.create(MediaType.parse("application/json"), "Something went wrong") | |
val expectedResponse = Response.error<Response>(500, body) | |
`when`(endPoint.getDaily()).thenReturn(Single.error(HttpException(expectedResponse))) | |
repo.fetchCustomerDetail() | |
.test() | |
.assertValueCount(0) | |
.assertError { it is HttpException } | |
verify(endPoint).getCustomerDetail() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment