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 kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.test.TestCoroutineDispatcher | |
import kotlinx.coroutines.test.TestCoroutineScope | |
import kotlinx.coroutines.test.resetMain | |
import kotlinx.coroutines.test.setMain | |
import org.junit.jupiter.api.extension.AfterAllCallback | |
import org.junit.jupiter.api.extension.AfterEachCallback | |
import org.junit.jupiter.api.extension.BeforeAllCallback | |
import org.junit.jupiter.api.extension.ExtendWith | |
import org.junit.jupiter.api.extension.ExtensionContext |
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
@Qualifier | |
annotation class MainCoroutineScope | |
@Module | |
object CoroutineScopeModule { | |
@Provides | |
@MainCoroutineScope | |
fun provideMainCoroutineScope(): CoroutineScope = CoroutineScope(Job() + Dispatchers.Main) | |
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
@Module | |
object CoroutineScopeModule { | |
@Provides | |
fun provideDefaultCoroutineScope(): DefaultCoroutineScope = DefaultCoroutineScope() | |
@Provides | |
fun provideIOCoroutineScope(): IOCoroutineScope = IOCoroutineScope() | |
@Provides |
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
@Suppress("UNCHECKED_CAST") | |
class MutableLiveData2<T>(value: T) : LiveData<T>(value) { | |
override fun getValue(): T = super.getValue() as T | |
public override fun setValue(value: T) = super.setValue(value) | |
public override fun postValue(value: T) = super.postValue(value) | |
} |
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
class CoroutineTestRule : TestRule, | |
TestPolymorphicCoroutineScope by TestPolymorphicCoroutineScope() { | |
val dispatcher = coroutineContext[ContinuationInterceptor] as TestCoroutineDispatcher | |
override fun apply( | |
base: Statement, description: Description? | |
) = object : Statement() { | |
override fun evaluate() { | |
@Throws(Throwable::class) |
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
@ExperimentalCoroutinesApi | |
interface TestPolymorphicCoroutineScope : TestCoroutineScope, | |
DefaultCoroutineScope, | |
IOCoroutineScope, | |
MainCoroutineScope, | |
MainImmediateCoroutineScope, | |
UnconfinedCoroutineScope | |
@ExperimentalCoroutinesApi | |
private class TestPolymorphicCoroutineScopeImpl( |
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
val scope = MainCoroutineScope() | |
val progressIndicator = ProgressIndicator(scope) |
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
@Module | |
object CoroutineScopeModule { | |
@Provides | |
fun provideMainCoroutineScope(): MainCoroutineScope = MainCoroutineScope() | |
} |
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
public fun MainCoroutineScope( | |
job: Job = SupervisorJob() | |
): MainCoroutineScope = object : MainCoroutineScope { | |
override val coroutineContext = job + Dispatchers.Main | |
} | |
public fun MainCoroutineScope( | |
context: CoroutineContext | |
): MainCoroutineScope = object : MainCoroutineScope { | |
override val coroutineContext = context + Dispatchers.Main |
NewerOlder