Skip to content

Instantly share code, notes, and snippets.

@jmfayard
Created January 16, 2018 14:37
Show Gist options
  • Save jmfayard/26ed2c2a3eddb98560c47d7414e26455 to your computer and use it in GitHub Desktop.
Save jmfayard/26ed2c2a3eddb98560c47d7414e26455 to your computer and use it in GitHub Desktop.
RxJava testing with the trampoline scheduler
package com.github.rongi.rxpresenter.example
import io.reactivex.android.plugins.RxAndroidPlugins
import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.schedulers.Schedulers
import org.junit.Assert
import org.junit.rules.TestRule
import org.junit.runners.model.Statement
val testSchedulersTestRule = TestRule { base, _ ->
object : Statement() {
override fun evaluate() {
RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
try {
base.evaluate()
} finally {
RxJavaPlugins.reset()
RxAndroidPlugins.reset()
}
}
}
}
infix fun Any.assertEquals(another: Any) {
Assert.assertEquals(this, another)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment