Created
December 12, 2018 02:39
-
-
Save william-reed/4b21a1cc4f85dde20806625b4c8fef84 to your computer and use it in GitHub Desktop.
JUnit 5 executor version of InstantTaskExecutorRule
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
import androidx.arch.core.executor.ArchTaskExecutor | |
import androidx.arch.core.executor.TaskExecutor | |
import org.junit.jupiter.api.extension.ExtensionContext | |
import org.junit.jupiter.api.extension.TestInstancePostProcessor | |
class InstantTaskExecutor : TestInstancePostProcessor { | |
override fun postProcessTestInstance(testInstance: Any?, context: ExtensionContext?) { | |
ArchTaskExecutor.getInstance().setDelegate(object : TaskExecutor() { | |
override fun executeOnDiskIO(runnable: Runnable) { | |
runnable.run() | |
} | |
override fun postToMainThread(runnable: Runnable) { | |
runnable.run() | |
} | |
override fun isMainThread(): Boolean { | |
return true | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment