Created
May 17, 2019 09:17
-
-
Save varshabhatia007/c5fabc269f1113446c35568471a0c7e9 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
@Mock | |
private lateinit var repo: CustomerRepo | |
private lateinit var customerUsecase: CustomerUsecase | |
@Before | |
fun setUp() { | |
customerUsecase = CustomerInteractor(repo) | |
} | |
@Test | |
fun `should return customer data`() { | |
val expectedCustomerData = mock(CustomerDetail::class.java) | |
`when`(repo.fetchCustomerData()).thenReturn(Single.just(expectedCustomerData)) | |
customerUsecase.getCustomerData() | |
.test() | |
.assertComplete() | |
.assertNoErrors() | |
.assertValueCount(1)// Assert that this TestObserver/TestSubscriber received the specified number onNext events. | |
.assertValue { | |
assertEquals(expectedCustomerData, it) | |
true | |
} | |
verify(repo).fetchCustomerDetail() | |
} | |
@Test | |
fun `should handle error for customer`() { | |
val body = ResponseBody.create(MediaType.parse("application/json"), "Something went wrong") | |
val expectedResponse = Response.error<Response>(500, body) | |
`when`(repo.fetchCustomerDetail()).thenReturn(Single.error(HttpException(expectedResponse))) | |
customerUsecase | |
.getCustomerData() | |
.test() | |
.assertValueCount(0) | |
.assertError { | |
it is HttpException | |
} | |
verify(repo).fetchCustomerDatail() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment