Last active
May 19, 2019 08:43
-
-
Save r4jiv007/6080f9cc1984e23f1cf80a71981f3e98 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
@Test | |
fun test_polling_behaviour() { | |
Mockito.`when`(dataManager.getMatch(Mockito.anyInt())).thenReturn( | |
just(matchResponse)) | |
Mockito.`when`(matchResponse.match()).thenReturn(mMatch) | |
val testScheduler = TestScheduler() | |
mSpyPresenter.setMatch(mMatch) | |
val testObserver = mSpyPresenter.getPollingObservable(MATCH_UPDATE_INTERVAL, testScheduler, testScheduler) | |
.subscribeOn(testScheduler) | |
.observeOn(testScheduler) | |
.test() | |
testObserver.assertNotCompleted() | |
.assertNoErrors() | |
.assertValueCount(0) | |
testScheduler.advanceTimeBy(0L, TimeUnit.SECONDS) | |
testObserver.assertValueCount(1) | |
testScheduler.advanceTimeBy(10L, TimeUnit.SECONDS) | |
testObserver.assertValueCount(2) | |
testScheduler.advanceTimeBy(10L, TimeUnit.SECONDS) | |
testObserver.assertValueCount(3) | |
} | |
@Test | |
fun test_polling_result_behaviour() { | |
Mockito.`when`(dataManager.getMatch(Mockito.anyInt())).thenReturn( | |
just(matchResponse)) | |
Mockito.`when`(matchResponse.match()).thenReturn(mMatch) | |
val testScheduler = TestScheduler() | |
mSpyPresenter.setMatch(mMatch) | |
val spySubscriber: Subscriber<MatchResponse> = Mockito.spy(mSpyPresenter.pollSubscriber) | |
mSpyPresenter.getPollingObservable(MATCH_UPDATE_INTERVAL, testScheduler, testScheduler) | |
.subscribeOn(testScheduler) | |
.observeOn(testScheduler) | |
.subscribe(spySubscriber) | |
testScheduler.advanceTimeBy(0L, TimeUnit.SECONDS) | |
Mockito.verify(spySubscriber, Mockito.times(1)).onNext(matchResponse) | |
Mockito.verify(mSpyPresenter, Mockito.times(1)).updateScoreCard(mMatch) | |
testScheduler.advanceTimeBy(10, TimeUnit.SECONDS) | |
Mockito.verify(spySubscriber, Mockito.times(2)).onNext(matchResponse) | |
Mockito.verify(mSpyPresenter, Mockito.times(2)).updateScoreCard(mMatch) | |
testScheduler.advanceTimeBy(10, TimeUnit.SECONDS) | |
Mockito.verify(spySubscriber, Mockito.times(3)).onNext(matchResponse) | |
Mockito.verify(mSpyPresenter, Mockito.times(3)).updateScoreCard(mMatch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment