Reduce flaky of BackgroundInstalledAppsPageProviderTest
Bug: 355413226 Flag: EXEMPT test only Test: atest BackgroundInstalledAppsPageProviderTest Change-Id: Iede656b7cf34bac82718f0aff12ee28cbaa9d8f8
This commit is contained in:
@@ -37,45 +37,32 @@ import com.google.common.truth.Truth.assertThat
|
|||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
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.any
|
||||||
import org.mockito.kotlin.argumentCaptor
|
import org.mockito.kotlin.argumentCaptor
|
||||||
|
import org.mockito.kotlin.doReturn
|
||||||
import org.mockito.kotlin.eq
|
import org.mockito.kotlin.eq
|
||||||
|
import org.mockito.kotlin.mock
|
||||||
|
import org.mockito.kotlin.spy
|
||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class BackgroundInstalledAppsPageProviderTest {
|
class BackgroundInstalledAppsPageProviderTest {
|
||||||
@get:Rule
|
@get:Rule val composeTestRule = createComposeRule()
|
||||||
val composeTestRule = createComposeRule()
|
|
||||||
|
|
||||||
@get:Rule
|
private val mockPackageManager = mock<PackageManager>()
|
||||||
val mockito: MockitoRule = MockitoJUnit.rule()
|
|
||||||
|
|
||||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
private val context: Context =
|
||||||
|
spy(ApplicationProvider.getApplicationContext()) {
|
||||||
|
on { packageManager } doReturn mockPackageManager
|
||||||
|
}
|
||||||
|
|
||||||
@Mock
|
private val mockBackgroundInstallControlService = mock<IBackgroundInstallControlService>()
|
||||||
private lateinit var mockContext: Context
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var mockPackageManager: PackageManager
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var mockBackgroundInstallControlService: IBackgroundInstallControlService
|
|
||||||
|
|
||||||
private var packageInfoFlagsCaptor = argumentCaptor<PackageManager.PackageInfoFlags>()
|
|
||||||
|
|
||||||
private val fakeNavControllerWrapper = FakeNavControllerWrapper()
|
private val fakeNavControllerWrapper = FakeNavControllerWrapper()
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setup() {
|
|
||||||
whenever(mockContext.packageManager).thenReturn(mockPackageManager)
|
|
||||||
}
|
|
||||||
@Test
|
@Test
|
||||||
fun allAppListPageProvider_name() {
|
fun allAppListPageProvider_name() {
|
||||||
assertThat(BackgroundInstalledAppsPageProvider.name)
|
assertThat(BackgroundInstalledAppsPageProvider.name)
|
||||||
@@ -108,7 +95,7 @@ class BackgroundInstalledAppsPageProviderTest {
|
|||||||
|
|
||||||
setInjectEntry(false)
|
setInjectEntry(false)
|
||||||
|
|
||||||
composeTestRule.onNodeWithText("0 apps").assertIsDisplayed()
|
composeTestRule.waitUntilExists(hasText("0 apps"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -200,7 +187,8 @@ class BackgroundInstalledAppsPageProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun backgroundInstalledAppsWithGroupingListModel_transform() = runTest {
|
fun backgroundInstalledAppsWithGroupingListModel_transform() = runTest {
|
||||||
val listModel = BackgroundInstalledAppsWithGroupingListModel(mockContext)
|
val packageInfoFlagsCaptor = argumentCaptor<PackageManager.PackageInfoFlags>()
|
||||||
|
val listModel = BackgroundInstalledAppsWithGroupingListModel(context)
|
||||||
whenever(mockPackageManager.getPackageInfoAsUser(
|
whenever(mockPackageManager.getPackageInfoAsUser(
|
||||||
eq(TEST_PACKAGE_NAME),
|
eq(TEST_PACKAGE_NAME),
|
||||||
packageInfoFlagsCaptor.capture(),
|
packageInfoFlagsCaptor.capture(),
|
||||||
@@ -218,7 +206,7 @@ class BackgroundInstalledAppsPageProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun backgroundInstalledAppsWithGroupingListModel_filter() = runTest {
|
fun backgroundInstalledAppsWithGroupingListModel_filter() = runTest {
|
||||||
val listModel = BackgroundInstalledAppsWithGroupingListModel(mockContext)
|
val listModel = BackgroundInstalledAppsWithGroupingListModel(context)
|
||||||
listModel.setBackgroundInstallControlService(mockBackgroundInstallControlService)
|
listModel.setBackgroundInstallControlService(mockBackgroundInstallControlService)
|
||||||
whenever(mockBackgroundInstallControlService.getBackgroundInstalledPackages(
|
whenever(mockBackgroundInstallControlService.getBackgroundInstalledPackages(
|
||||||
PackageManager.MATCH_ALL.toLong(),
|
PackageManager.MATCH_ALL.toLong(),
|
||||||
|
Reference in New Issue
Block a user