-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove deprecated coroutine test apis
- Loading branch information
Showing
1 changed file
with
5 additions
and
12 deletions.
There are no files selected for viewing
17 changes: 5 additions & 12 deletions
17
...s/testUtils/src/main/java/com/ezike/tobenna/starwarssearch/testutils/MainCoroutineRule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
package com.ezike.tobenna.starwarssearch.testutils | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.test.TestCoroutineDispatcher | ||
import kotlinx.coroutines.test.TestCoroutineExceptionHandler | ||
import kotlinx.coroutines.test.TestCoroutineScope | ||
import kotlinx.coroutines.test.createTestCoroutineScope | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
public class MainCoroutineRule( | ||
private val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() | ||
) : | ||
TestWatcher(), | ||
TestCoroutineScope by createTestCoroutineScope(TestCoroutineDispatcher() + TestCoroutineExceptionHandler() + dispatcher) { | ||
private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(), | ||
) : TestWatcher() { | ||
override fun starting(description: Description) { | ||
super.starting(description) | ||
Dispatchers.setMain(dispatcher) | ||
Dispatchers.setMain(testDispatcher) | ||
} | ||
|
||
override fun finished(description: Description) { | ||
super.finished(description) | ||
Dispatchers.resetMain() | ||
cleanupTestCoroutines() | ||
} | ||
} |