From b4a8e4b3145879ff1b0b86bc3a59a23cb541df7e Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Wed, 7 Dec 2022 12:03:47 +0800 Subject: [PATCH] Reduce flaky of whenCanDisplayLocalUi_displayed Bug: 246877208 Test: Unit test Change-Id: I0b2554521b55fcfacc24e59a81ddc08b2eb9d70c --- .../spa/app/appinfo/AppLocalePreferenceTest.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppLocalePreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppLocalePreferenceTest.kt index b4545d46361..82c9ee94ffc 100644 --- a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppLocalePreferenceTest.kt +++ b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppLocalePreferenceTest.kt @@ -22,11 +22,9 @@ import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule -import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.performClick import androidx.test.core.app.ApplicationProvider @@ -47,7 +45,6 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor -import org.mockito.ArgumentMatchers import org.mockito.Mock import org.mockito.Mockito.any import org.mockito.Mockito.doNothing @@ -80,9 +77,8 @@ class AppLocalePreferenceTest { .strictness(Strictness.LENIENT) .startMocking() whenever(context.packageManager).thenReturn(packageManager) - whenever(AppLocaleUtil.canDisplayLocaleUi(any(), ArgumentMatchers.eq(APP), any())) - .thenReturn(true) - whenever(AppLocaleDetails.getSummary(any(), ArgumentMatchers.eq(APP))).thenReturn(SUMMARY) + whenever(AppLocaleUtil.canDisplayLocaleUi(any(), eq(APP), any())).thenReturn(true) + whenever(AppLocaleDetails.getSummary(any(), eq(APP))).thenReturn(SUMMARY) } @After @@ -92,8 +88,7 @@ class AppLocalePreferenceTest { @Test fun whenCanNotDisplayLocalUi_notDisplayed() { - whenever(AppLocaleUtil.canDisplayLocaleUi(any(), ArgumentMatchers.eq(APP), any())) - .thenReturn(false) + whenever(AppLocaleUtil.canDisplayLocaleUi(any(), eq(APP), any())).thenReturn(false) setContent() @@ -104,8 +99,9 @@ class AppLocalePreferenceTest { fun whenCanDisplayLocalUi_displayed() { setContent() - composeTestRule.onNodeWithText(context.getString(R.string.app_locale_preference_title)) - .assertIsDisplayed() + composeTestRule.waitUntilExists( + hasText(context.getString(R.string.app_locale_preference_title)) + ) composeTestRule.waitUntilExists(hasText(SUMMARY)) }