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

Commit 793253aa authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Reduce flaky of BackgroundInstalledAppsPageProviderTest" into main

parents 45aa574b 210529ef
Loading
Loading
Loading
Loading
+14 −26
Original line number Diff line number Diff line
@@ -37,45 +37,32 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.whenever

@RunWith(AndroidJUnit4::class)
class BackgroundInstalledAppsPageProviderTest {
    @get:Rule
    val composeTestRule = createComposeRule()
    @get:Rule val composeTestRule = createComposeRule()

    @get:Rule
    val mockito: MockitoRule = MockitoJUnit.rule()
    private val mockPackageManager = mock<PackageManager>()

    private val context: Context = ApplicationProvider.getApplicationContext()

    @Mock
    private lateinit var mockContext: Context

    @Mock
    private lateinit var mockPackageManager: PackageManager

    @Mock
    private lateinit var mockBackgroundInstallControlService: IBackgroundInstallControlService
    private val context: Context =
        spy(ApplicationProvider.getApplicationContext()) {
            on { packageManager } doReturn mockPackageManager
        }

    private var packageInfoFlagsCaptor = argumentCaptor<PackageManager.PackageInfoFlags>()
    private val mockBackgroundInstallControlService = mock<IBackgroundInstallControlService>()

    private val fakeNavControllerWrapper = FakeNavControllerWrapper()

    @Before
    fun setup() {
        whenever(mockContext.packageManager).thenReturn(mockPackageManager)
    }
    @Test
    fun allAppListPageProvider_name() {
        assertThat(BackgroundInstalledAppsPageProvider.name)
@@ -108,7 +95,7 @@ class BackgroundInstalledAppsPageProviderTest {

        setInjectEntry(false)

        composeTestRule.onNodeWithText("0 apps").assertIsDisplayed()
        composeTestRule.waitUntilExists(hasText("0 apps"))
    }

    @Test
@@ -200,7 +187,8 @@ class BackgroundInstalledAppsPageProviderTest {

    @Test
    fun backgroundInstalledAppsWithGroupingListModel_transform() = runTest {
        val listModel = BackgroundInstalledAppsWithGroupingListModel(mockContext)
        val packageInfoFlagsCaptor = argumentCaptor<PackageManager.PackageInfoFlags>()
        val listModel = BackgroundInstalledAppsWithGroupingListModel(context)
        whenever(mockPackageManager.getPackageInfoAsUser(
            eq(TEST_PACKAGE_NAME),
            packageInfoFlagsCaptor.capture(),
@@ -218,7 +206,7 @@ class BackgroundInstalledAppsPageProviderTest {

    @Test
    fun backgroundInstalledAppsWithGroupingListModel_filter() = runTest {
        val listModel = BackgroundInstalledAppsWithGroupingListModel(mockContext)
        val listModel = BackgroundInstalledAppsWithGroupingListModel(context)
        listModel.setBackgroundInstallControlService(mockBackgroundInstallControlService)
        whenever(mockBackgroundInstallControlService.getBackgroundInstalledPackages(
            PackageManager.MATCH_ALL.toLong(),