Created
June 22, 2018 16:21
-
-
Save tcw165/e2e2951039c7eedcbe2696409a2b14e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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