Last active
November 29, 2021 22:09
-
-
Save esilverberg/367c2e7f4beb3eefa22e0688512745b8 to your computer and use it in GitHub Desktop.
blockingMostRecent vs blockingFirst
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
@DisplayName("Given we are testing blockingFirst") | |
class BlockingFirstTest : KoinTest() { | |
private val behaviorSubject: BehaviorSubject<Int> = BehaviorSubject.createDefault(0) | |
private val observableSubject: Observable<Int> = behaviorSubject | |
@Test | |
fun `then it should have emitted six times`() { | |
var didEmit = 0 | |
observableSubject.doOnNext { didEmit += 1 }.blockingMostRecent(null).iterator().next() | |
observableSubject.doOnNext { didEmit += 1 }.blockingMostRecent(null).iterator().next() | |
observableSubject.doOnNext { didEmit += 1 }.blockingMostRecent(null).iterator().next() | |
didEmit.shouldBeEqualTo(3) | |
behaviorSubject.onNext(1) | |
didEmit.shouldBeEqualTo(6) // <-- did you mean to emit six times??? | |
// Not 0, the observable is not keeping a history and it emits the latest value | |
observableSubject.blockingFirst().shouldBeEqualTo(1) | |
} | |
@Test | |
fun `then it should only emitted three times`() { | |
var didEmit = 0 | |
observableSubject.doOnNext { didEmit += 1 }.blockingFirst() | |
observableSubject.doOnNext { didEmit += 1 }.blockingFirst() | |
observableSubject.doOnNext { didEmit += 1 }.blockingFirst() | |
didEmit.shouldBeEqualTo(3) | |
behaviorSubject.onNext(1) | |
didEmit.shouldBeEqualTo(3) | |
// Not 0, the observable is not keeping a history and it emits the latest value | |
observableSubject.blockingFirst().shouldBeEqualTo(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment