rx.lang.scala
Scheduler with artificial time, useful for testing.
For example, you could test the Observable.interval operation using a TestScheduler as follows:
Observable.interval
TestScheduler
@Test def testInterval() { import org.mockito.Matchers._ import org.mockito.Mockito._ import rx.lang.scala.JavaConversions._ val scheduler = TestScheduler() val observer = mock(classOf[rx.Observer[Long]]) val o = Observable.interval(1 second, scheduler) val sub = o.subscribe(toScalaObserver(new TestObserver(observer))) verify(observer, never).onNext(0L) verify(observer, never).onCompleted() verify(observer, never).onError(any(classOf[Throwable])) scheduler.advanceTimeTo(2 seconds) val inOrdr = inOrder(observer); inOrdr.verify(observer, times(1)).onNext(0L) inOrdr.verify(observer, times(1)).onNext(1L) inOrdr.verify(observer, never).onNext(2L) verify(observer, never).onCompleted() verify(observer, never).onError(any(classOf[Throwable])) sub.unsubscribe(); scheduler.advanceTimeTo(4 seconds) verify(observer, never).onNext(2L) verify(observer, times(1)).onCompleted() verify(observer, never).onError(any(classOf[Throwable])) }
Provides constructors for TestScheduler.
Scheduler with artificial time, useful for testing.
For example, you could test the
Observable.interval
operation using aTestScheduler
as follows: