| 144cbf7b Andy McCall ↶ |
1 |
package io.oxygenhub.android |
| 2 |
|
| 3 |
import kotlinx.coroutines.Dispatchers |
| 4 |
import kotlinx.coroutines.ExperimentalCoroutinesApi |
| 5 |
import kotlinx.coroutines.test.TestDispatcher |
| 6 |
import kotlinx.coroutines.test.UnconfinedTestDispatcher |
| 7 |
import kotlinx.coroutines.test.resetMain |
| 8 |
import kotlinx.coroutines.test.setMain |
| 9 |
import org.junit.rules.TestWatcher |
| 10 |
import org.junit.runner.Description |
| 11 |
|
| 12 |
/** viewModelScope runs on Main: a test dispatcher stands in for it. */ |
| 13 |
@OptIn(ExperimentalCoroutinesApi::class) |
| 14 |
class MainDispatcherRule(val dispatcher: TestDispatcher = UnconfinedTestDispatcher()) : TestWatcher() { |
| 15 |
override fun starting(description: Description) = Dispatchers.setMain(dispatcher) |
| 16 |
override fun finished(description: Description) = Dispatchers.resetMain() |
| 17 |
} |