|
16 | 16 |
|
17 | 17 | package rx.lang.kotlin |
18 | 18 |
|
19 | | -import rx.Observable |
20 | 19 | import org.junit.Test |
21 | 20 | import org.mockito.Mockito.* |
22 | 21 | import org.mockito.Matchers.* |
23 | 22 | import org.junit.Assert.* |
24 | | -import rx.Notification |
25 | 23 | import kotlin.concurrent.thread |
26 | | -import rx.Subscriber |
27 | 24 | import org.funktionale.partials.* |
| 25 | +import rx.* |
| 26 | +import rx.schedulers.TestScheduler |
| 27 | +import java.util.concurrent.TimeUnit |
28 | 28 |
|
29 | 29 | /** |
30 | 30 | * This class contains tests using the extension functions provided by the language adaptor. |
@@ -236,6 +236,41 @@ public class ExtensionTests : KotlinTests() { |
236 | 236 | assertEquals(listOf(3, 6, 9), values[2]) |
237 | 237 | } |
238 | 238 |
|
| 239 | + @Test |
| 240 | + public fun testSwitchOnNext() { |
| 241 | + val testScheduler = TestScheduler() |
| 242 | + val worker = testScheduler.createWorker() |
| 243 | + |
| 244 | + val observable = observable<Observable<Long>> { s -> |
| 245 | + fun at(delay: Long, func : () -> Unit){ |
| 246 | + worker.schedule({ |
| 247 | + func() |
| 248 | + }, delay, TimeUnit.MILLISECONDS) |
| 249 | + } |
| 250 | + |
| 251 | + val first = Observable.interval(5, TimeUnit.MILLISECONDS, testScheduler).take(3) |
| 252 | + at(0, { s.onNext(first) }) |
| 253 | + |
| 254 | + val second = Observable.interval(5, TimeUnit.MILLISECONDS, testScheduler).take(3) |
| 255 | + at(11, { s.onNext(second) }) |
| 256 | + |
| 257 | + at(40, { s.onCompleted() }) |
| 258 | + } |
| 259 | + |
| 260 | + observable.switchOnNext().subscribe(received) |
| 261 | + |
| 262 | + val inOrder = inOrder(a) |
| 263 | + testScheduler.advanceTimeTo(10, TimeUnit.MILLISECONDS) |
| 264 | + inOrder.verify(a, times(1)).received(0L) |
| 265 | + inOrder.verify(a, times(1)).received(1L) |
| 266 | + |
| 267 | + testScheduler.advanceTimeTo(40, TimeUnit.MILLISECONDS) |
| 268 | + inOrder.verify(a, times(1)).received(0L) |
| 269 | + inOrder.verify(a, times(1)).received(1L) |
| 270 | + inOrder.verify(a, times(1)).received(2L) |
| 271 | + inOrder.verifyNoMoreInteractions() |
| 272 | + } |
| 273 | + |
239 | 274 | val funOnSubscribe: (Int, Subscriber<in String>) -> Unit = { counter, subscriber -> |
240 | 275 | subscriber.onNext("hello_$counter") |
241 | 276 | subscriber.onCompleted() |
|
0 commit comments