-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'replace-testcoroutinedispatcher-droid-279'
- Loading branch information
Showing
4 changed files
with
19 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
14 changes: 9 additions & 5 deletions
14
...lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.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,23 +1,27 @@ | ||
package net.mullvad.mullvadvpn.lib.common.test | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.test.TestCoroutineDispatcher | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
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 | ||
|
||
class TestCoroutineRule(val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class TestCoroutineRule(val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()) : | ||
TestWatcher() { | ||
|
||
override fun starting(description: Description?) { | ||
override fun starting(description: Description) { | ||
super.starting(description) | ||
Dispatchers.setMain(testDispatcher) | ||
} | ||
|
||
override fun finished(description: Description?) { | ||
override fun finished(description: Description) { | ||
super.finished(description) | ||
Dispatchers.resetMain() | ||
testDispatcher.cleanupTestCoroutines() | ||
// Replacement for cleanupTestCoroutines() | ||
testDispatcher.scheduler.runCurrent() | ||
} | ||
} |