-
-
Save jmfayard/26ed2c2a3eddb98560c47d7414e26455 to your computer and use it in GitHub Desktop.
RxJava testing with the trampoline scheduler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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