commit 2f4d2e2a7ba4460268bd8612f0ee7a7a7e80e448
parent d1c0d07f49513b52e23584e10bad0c45ed15e42a
Author: mcarare <48995920+mcarare@users.noreply.github.com>
Date: Wed, 15 Oct 2025 16:16:44 +0000
Bug 1993740 - Remove MainCoroutineRule from RunWhenReadyQueueTest. r=android-reviewers,giorga
Differential Revision: https://phabricator.services.mozilla.com/D268713
Diffstat:
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/mobile/android/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/RunWhenReadyQueueTest.kt b/mobile/android/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/RunWhenReadyQueueTest.kt
@@ -4,12 +4,10 @@
package mozilla.components.support.utils
+import kotlinx.coroutines.test.runTest
import mozilla.components.support.test.mock
-import mozilla.components.support.test.rule.MainCoroutineRule
-import mozilla.components.support.test.rule.runTestOnMain
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
-import org.junit.Rule
import org.junit.Test
import org.mockito.Mockito.inOrder
import org.mockito.Mockito.never
@@ -17,49 +15,48 @@ import org.mockito.Mockito.verify
class RunWhenReadyQueueTest {
- @get:Rule
- val coroutinesTestRule = MainCoroutineRule()
- private val scope = coroutinesTestRule.scope
-
@Test
- fun `task should not run until ready is called`() = runTestOnMain {
+ fun `task should not run until ready is called`() = runTest {
val task = mock<() -> Unit>()
- val queue = RunWhenReadyQueue(scope)
+ val queue = RunWhenReadyQueue(this)
verify(task, never()).invoke()
assertFalse(queue.isReady())
queue.runIfReadyOrQueue(task)
queue.ready()
+ testScheduler.advanceUntilIdle()
verify(task).invoke()
assertTrue(queue.isReady())
}
@Test
- fun `task should run if ready was called`() = runTestOnMain {
+ fun `task should run if ready was called`() = runTest {
val task = mock<() -> Unit>()
- val queue = RunWhenReadyQueue(scope)
+ val queue = RunWhenReadyQueue(this)
queue.ready()
verify(task, never()).invoke()
queue.runIfReadyOrQueue(task)
+ testScheduler.advanceUntilIdle()
verify(task).invoke()
}
@Test
- fun `tasks should run in the order they were queued`() = runTestOnMain {
+ fun `tasks should run in the order they were queued`() = runTest {
val task1 = mock<() -> Unit>()
val task2 = mock<() -> Unit>()
val task3 = mock<() -> Unit>()
- val queue = RunWhenReadyQueue(scope)
+ val queue = RunWhenReadyQueue(this)
queue.runIfReadyOrQueue(task1)
queue.runIfReadyOrQueue(task2)
queue.runIfReadyOrQueue(task3)
queue.ready()
+ testScheduler.advanceUntilIdle()
val inOrder = inOrder(task1, task2, task3)
inOrder.verify(task1).invoke()