Skip to content

Instantly share code, notes, and snippets.

@tcw165
Created June 22, 2018 16:21
Show Gist options
  • Select an option

  • Save tcw165/e2e2951039c7eedcbe2696409a2b14e9 to your computer and use it in GitHub Desktop.

Select an option

Save tcw165/e2e2951039c7eedcbe2696409a2b14e9 to your computer and use it in GitHub Desktop.
class TakeWhenObservableTest {
@Test
fun openThrottle_shouldSeeTheItemsAreSentThen() {
val src = PublishSubject.create<Int>()
val whenSrc = PublishSubject.create<Boolean>()
val tester = TakeWhenObservable(src = src,
whenSrc = whenSrc)
.test()
src.onNext(0)
src.onNext(1)
src.onNext(2)
src.onNext(3)
// Open the throttle
whenSrc.onNext(true)
// Close the throttle
whenSrc.onNext(false)
src.onNext(4)
src.onNext(5)
src.onNext(6)
src.onNext(7)
tester.assertValues(0, 1, 2, 3)
// Open the throttle again!
whenSrc.onNext(true)
tester.assertValues(0, 1, 2, 3, 4, 5, 6, 7)
}
@Test
fun disposeIt_shouldNotSeeAnyItemsFired() {
val src = PublishSubject.create<Int>()
val whenSrc = PublishSubject.create<Boolean>()
val tester = TakeWhenObservable(src = src,
whenSrc = whenSrc)
.test()
// Open the throttle
whenSrc.onNext(true)
tester.dispose()
src.onNext(0)
src.onNext(1)
src.onNext(2)
src.onNext(3)
tester.assertNoValues()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment