@@ -6,39 +6,30 @@ import io.mockk.unmockkAll
66import kotlinx.coroutines.CoroutineDispatcher
77import kotlinx.coroutines.ExperimentalCoroutinesApi
88import kotlinx.coroutines.test.StandardTestDispatcher
9- import kotlinx.coroutines.test.TestScope
109import kotlinx.coroutines.test.advanceUntilIdle
1110import kotlinx.coroutines.test.runTest
1211import org.junit.After
1312import org.junit.Assert.assertEquals
1413import org.junit.Assert.assertTrue
15- import org.junit.Before
1614import org.junit.Test
1715import org.ole.planet.myplanet.utils.DispatcherProvider
1816import kotlin.coroutines.ContinuationInterceptor
1917
2018@OptIn(ExperimentalCoroutinesApi ::class )
2119class SubmissionUploadExecutorTest {
22- private val testDispatcher = StandardTestDispatcher ()
23- private val testScope = TestScope (testDispatcher)
24- private val ioDispatcher = StandardTestDispatcher ()
25- private lateinit var mockDispatcherProvider: DispatcherProvider
26- private lateinit var executor: SubmissionUploadExecutor
27-
28- @Before
29- fun setUp () {
30- mockDispatcherProvider = mockk()
31- every { mockDispatcherProvider.io } returns ioDispatcher
32- executor = SubmissionUploadExecutor (testScope, mockDispatcherProvider)
33- }
34-
3520 @After
3621 fun tearDown () {
3722 unmockkAll()
3823 }
3924
4025 @Test
41- fun testExecute_invokesBlockOnCorrectDispatcher () = testScope.runTest {
26+ fun testExecute_invokesBlockOnCorrectDispatcher () = runTest {
27+ val ioDispatcher = StandardTestDispatcher (testScheduler)
28+ val mockDispatcherProvider = mockk<DispatcherProvider >()
29+ every { mockDispatcherProvider.io } returns ioDispatcher
30+
31+ val executor = SubmissionUploadExecutor (this , mockDispatcherProvider)
32+
4233 var invoked = false
4334 var capturedDispatcher: CoroutineDispatcher ? = null
4435
@@ -47,7 +38,7 @@ class SubmissionUploadExecutorTest {
4738 capturedDispatcher = coroutineContext[ContinuationInterceptor ] as CoroutineDispatcher
4839 }
4940
50- ioDispatcher.scheduler. advanceUntilIdle()
41+ advanceUntilIdle()
5142
5243 assertTrue(invoked)
5344 assertEquals(ioDispatcher, capturedDispatcher)
0 commit comments