Skip to content

Commit f1a1f07

Browse files
konrad-kaminskielizarov
authored andcommitted
Added test case for awaitFirstOrXXX functions on Rx1 Observable with null.
1 parent b8ed47c commit f1a1f07

File tree

1 file changed

+20
-0
lines changed
  • reactive/kotlinx-coroutines-rx1/src/test/kotlin/kotlinx/coroutines/experimental/rx1

1 file changed

+20
-0
lines changed

reactive/kotlinx-coroutines-rx1/src/test/kotlin/kotlinx/coroutines/experimental/rx1/IntegrationTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ class IntegrationTest(
9090
assertThat(cnt, IsEqual(1))
9191
}
9292

93+
@Test
94+
fun testObservableWithNull() = runBlocking<Unit> {
95+
val observable = rxObservable<String?>(ctx(coroutineContext)) {
96+
if (delay) delay(1)
97+
send(null)
98+
}
99+
assertThat(observable.awaitFirst(), IsNull())
100+
assertThat(observable.awaitFirstOrDefault("OK"), IsNull())
101+
assertThat(observable.awaitFirstOrNull(), IsNull())
102+
assertThat(observable.awaitFirstOrElse { "OK" }, IsNull())
103+
assertThat(observable.awaitLast(), IsNull())
104+
assertThat(observable.awaitSingle(), IsNull())
105+
var cnt = 0
106+
observable.consumeEach {
107+
assertThat(it, IsNull())
108+
cnt++
109+
}
110+
assertThat(cnt, IsEqual(1))
111+
}
112+
93113
@Test
94114
fun testNumbers() = runBlocking<Unit> {
95115
val n = 100 * stressTestMultiplier

0 commit comments

Comments
 (0)