From 79e09aa494acdd89a074412e0683740c26462328 Mon Sep 17 00:00:00 2001 From: Sagar <85388413+Sagar0-0@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:47:12 +0530 Subject: [PATCH] Fix deprecated code in MainCoroutineRule.kt --- .../shoppinglisttestingyt/MainCoroutineRule.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt b/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt index f98629d..38a4f5e 100644 --- a/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt +++ b/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt @@ -3,26 +3,24 @@ package com.androiddevs.shoppinglisttestingyt import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.TestCoroutineDispatcher -import kotlinx.coroutines.test.TestCoroutineScope +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 -@ExperimentalCoroutinesApi -class MainCoroutineRule( - private val dispatcher: CoroutineDispatcher = TestCoroutineDispatcher() -) : TestWatcher(), TestCoroutineScope by TestCoroutineScope(dispatcher) { +@OptIn(ExperimentalCoroutinesApi::class) +class MainCoroutineRule constructor( + private val dispatcher: CoroutineDispatcher = UnconfinedTestDispatcher() +) : TestWatcher() { - override fun starting(description: Description?) { + override fun starting(description: Description) { super.starting(description) Dispatchers.setMain(dispatcher) } - override fun finished(description: Description?) { + override fun finished(description: Description) { super.finished(description) - cleanupTestCoroutines() Dispatchers.resetMain() } -} \ No newline at end of file +}