From 17b882a94d11ce69761b0a0158640b0276912c05 Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Mon, 4 May 2020 17:01:28 +0800 Subject: [PATCH] Fix broken test cases Since we added a new API in ag/11355641, we need to shadow this new new API. Fix: 130916962 Test: run robo test Change-Id: I2176253aae915d1a31043ebbf197d4dd1b1f2072 --- .../AccountPreferenceControllerTest.java | 26 ++++++++++--------- .../shadow/ShadowSettingsLibUtils.java | 6 +++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java index 65395a0b632..b22b1562be2 100644 --- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java @@ -49,6 +49,7 @@ import com.android.settings.SettingsPreferenceFragment; import com.android.settings.dashboard.profileselector.ProfileSelectFragment; import com.android.settings.testutils.shadow.ShadowAccountManager; import com.android.settings.testutils.shadow.ShadowContentResolver; +import com.android.settings.testutils.shadow.ShadowSettingsLibUtils; import com.android.settingslib.search.SearchIndexableRaw; import org.junit.After; @@ -67,7 +68,8 @@ import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) -@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) +@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class, + ShadowSettingsLibUtils.class}) public class AccountPreferenceControllerTest { @Mock(answer = RETURNS_DEEP_STUBS) @@ -95,7 +97,7 @@ public class AccountPreferenceControllerTest { when(mFragment.getPreferenceScreen()).thenReturn(mScreen); when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext); when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())) - .thenReturn(new AuthenticatorDescription[0]); + .thenReturn(new AuthenticatorDescription[0]); when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]); mController = new AccountPreferenceController(mContext, mFragment, null, mAccountHelper, ProfileSelectFragment.ProfileType.ALL); @@ -341,8 +343,8 @@ public class AccountPreferenceControllerTest { when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts); Account[] accountType1 = { - new Account("Account11", "com.acct1"), - new Account("Account12", "com.acct1") + new Account("Account11", "com.acct1"), + new Account("Account12", "com.acct1") }; when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))) .thenReturn(accountType1); @@ -535,8 +537,8 @@ public class AccountPreferenceControllerTest { when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts); Account[] accountType1 = { - new Account("Acct11", "com.acct1"), - new Account("Acct12", "com.acct1") + new Account("Acct11", "com.acct1"), + new Account("Acct12", "com.acct1") }; when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))) .thenReturn(accountType1); @@ -555,7 +557,7 @@ public class AccountPreferenceControllerTest { mController.onResume(); // remove an account - accountType1 = new Account[] {new Account("Acct11", "com.acct1")}; + accountType1 = new Account[]{new Account("Acct11", "com.acct1")}; when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))) .thenReturn(accountType1); @@ -577,19 +579,19 @@ public class AccountPreferenceControllerTest { Account[] accounts = {new Account("Acct1", "com.acct1")}; when(mAccountManager.getAccountsAsUser(1)).thenReturn(accounts); when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))) - .thenReturn(accounts); + .thenReturn(accounts); AuthenticatorDescription[] authDescs = { - new AuthenticatorDescription("com.acct1", "com.android.settings", - R.string.account_settings_title, 0 /* iconId */, 0 /* smallIconId */, - 0 /* prefId */, false /* customTokens */) + new AuthenticatorDescription("com.acct1", "com.android.settings", + R.string.account_settings_title, 0 /* iconId */, 0 /* smallIconId */, + 0 /* prefId */, false /* customTokens */) }; when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs); AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class); when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class)); when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))) - .thenReturn(preferenceGroup); + .thenReturn(preferenceGroup); // First time resume will build the UI with no account mController.onResume(); diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowSettingsLibUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowSettingsLibUtils.java index 2fce5ad80fb..8f4b7866699 100644 --- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowSettingsLibUtils.java +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowSettingsLibUtils.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.os.UserHandle; import com.android.settingslib.Utils; @@ -29,6 +30,11 @@ import org.robolectric.annotation.Implements; @Implements(Utils.class) public class ShadowSettingsLibUtils { + @Implementation + protected static Drawable getBadgedIcon(Context context, Drawable icon, UserHandle user) { + return new ColorDrawable(0); + } + @Implementation protected static Drawable getBadgedIcon(Context context, ApplicationInfo appInfo) { return new ColorDrawable(0);