Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee2e34ae authored by Jernej Virag's avatar Jernej Virag
Browse files

Fix dispatchers in tests using settings

SettingsObservers can run their updates async and it's important that
tests provide test dispatcher to Fake*Settings classes so the jobs get
executed when runCurrent is issued.

Bug: 355267965
Bug: 351766769
Flag: TEST_ONLY test fix
Test: enabled registerContentProviderAsync on cuttlefish and ran tests
Change-Id: I6446fb90672cc077a3fff660202ef6388d46c1f0
parent 44488a44
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.systemui.util.settings.FakeGlobalSettings
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
@@ -60,7 +61,8 @@ import org.mockito.Mockito.`when` as whenever
@RunWith(AndroidJUnit4::class)
@RunWithLooper
class FooterActionsViewModelTest : SysuiTestCase() {
    private val testScope = TestScope()
    private val testDispatcher = StandardTestDispatcher()
    private val testScope = TestScope(testDispatcher)
    private lateinit var utils: FooterActionsTestUtils

    private val themedContext = ContextThemeWrapper(context, R.style.Theme_SystemUI_QuickSettings)
@@ -127,7 +129,7 @@ class FooterActionsViewModelTest : SysuiTestCase() {
    fun userSwitcher() = runTest {
        val picture: Drawable = mock()
        val userInfoController = FakeUserInfoController(FakeInfo(picture = picture))
        val settings = FakeGlobalSettings()
        val settings = FakeGlobalSettings(testDispatcher)
        val userId = 42
        val userSwitcherControllerWrapper =
            MockUserSwitcherControllerWrapper(currentUserName = "foo")
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class AirplaneModeRepositoryImplTest : SysuiTestCase() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)

        settings = FakeGlobalSettings()
        settings = FakeGlobalSettings(testContext)

        whenever(telephonyManager.emergencyCallbackMode).thenReturn(false)
        whenever(subscriptionManager.activeSubscriptionIdList).thenReturn(intArrayOf())