Skip to content

Commit 3579e95

Browse files
committed
modify rx tests to work with real asynchronous observables
1 parent 0c7e028 commit 3579e95

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

kotlinx-coroutines-rx/src/test/kotlin/AsyncRxTest.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kotlinx.coroutines
22

33
import org.junit.Test
44
import rx.Observable
5+
import java.util.concurrent.TimeUnit
56
import kotlin.test.assertEquals
67
import kotlin.test.fail
78

@@ -17,6 +18,18 @@ class AsyncRxTest {
1718
}
1819
}
1920

21+
@Test
22+
fun testSingleWithDelay() {
23+
val observable = asyncRx<String> {
24+
Observable.timer(50, TimeUnit.MILLISECONDS).map { "O" }.awaitSingle() + "K"
25+
}
26+
27+
checkObservableWithSingleValue(observable) {
28+
assertEquals("OK", it)
29+
}
30+
}
31+
32+
2033
@Test
2134
fun testSingleException() {
2235
val observable = asyncRx<String> {
@@ -117,26 +130,15 @@ class AsyncRxTest {
117130
observable: Observable<*>,
118131
checker: (Throwable) -> Unit
119132
) {
120-
var onErrorCalled = false
121-
observable.subscribe({ fail("Next item on erroneous observable") }) {
122-
checker(it)
123-
onErrorCalled = true
124-
}
125-
126-
assert(onErrorCalled)
133+
val singleNotification = observable.materialize().toBlocking().single()
134+
checker(singleNotification.throwable)
127135
}
128136

129137
private fun <T> checkObservableWithSingleValue(
130138
observable: Observable<T>,
131139
checker: (T) -> Unit
132140
) {
133-
var subscribeCalled = false
134-
135-
observable.single().subscribe {
136-
checker(it)
137-
subscribeCalled = true
138-
}
139-
140-
assert(subscribeCalled)
141+
val singleValue = observable.toBlocking().single()
142+
checker(singleValue)
141143
}
142144
}

0 commit comments

Comments
 (0)