Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
blockingMostRecent vs blockingFirst
@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