blakelee
12/12/2019, 7:47 PM@Test fun `test poll`() {
open class MyClient {
fun fetchItemFromServer(): Single<Boolean> = Single.just(true)
}
val testScheduler = TestScheduler()
val client = mock<MyClient>()
whenever(client.fetchItemFromServer())
.thenReturn(Single.just(false), Single.just(true))
val test = client.fetchItemFromServer()
.repeatWhen { it.delay(10, TimeUnit.SECONDS, testScheduler) }
.distinctUntilChanged()
.test()
testScheduler.advanceTimeBy(10, TimeUnit.SECONDS)
test.assertResult(false, true)
}
Daniel Rodak
12/13/2019, 11:05 AMadvanceTimeBy
is working correctly here, the issue is in the mocks. You are getting only a first value because resubscribtion from repeatWhen
returns false
again which is filtered by the distinctUntilChanged
blakelee
12/13/2019, 6:10 PM