Skip to content

Commit

Permalink
remove deprecated coroutine test apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezike committed Apr 14, 2024
1 parent 0dadbc7 commit f091dc9
Showing 1 changed file with 5 additions and 12 deletions.
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()
}
}

0 comments on commit f091dc9

Please sign in to comment.