Slide 118
Slide 118 text
RemoteTest
118
@Test
fun observePurchasesUpdated_error() {
val subject = spy(PublishSubject.create())
`when`(remote.observePurchasesUpdated()).thenReturn(subject)
val latch = CountDownLatch(2)
var responseCode = 0
remote.observePurchasesUpdated()
.subscribe({
responseCode += 1
latch.countDown()
}, {
latch.countDown()
})
subject.onNext(PurchasesUpdatedResponse(0, null))
subject.onError(PurchaseException(BillingClient.BillingResponse.ERROR, "ΤϥʔͰ͢ʂʂ"))
subject.onNext(PurchasesUpdatedResponse(1, null))
subject.onError(PurchaseException(BillingClient.BillingResponse.ERROR, "ΤϥʔͰ͢ʂʂ"))
latch.await()
assertThat(responseCode).isEqualTo(1)
verify(subject, times(2)).onNext(any())
verify(subject, times(2)).onError(any())
}