From 12e05b8c5950b93a347f0f451f9eb480e35cbc59 Mon Sep 17 00:00:00 2001 From: Ale Nijamkin Date: Fri, 28 Apr 2023 16:22:52 +0000 Subject: [PATCH] Fixes broken Settings test. In ag/22187500, we added the requirement for a wallpaper picker app to be installed in order to treat the lock screen shortcuts feature as enabled (in addition to the feature flag). That broke this test. To fix, we're adding a mocked result to the PackageManager to pretend like the wallpaper picker application is installed. Change-Id: I8654375e3fa33df0984c48fcf91dd8f6c18e984f Fix: 280017187 Test: the test is back to passing. --- ...rivialPrivacyPreferenceControllerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java index 8bb3ff69001..a82e1f1c5ae 100644 --- a/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java @@ -18,6 +18,7 @@ package com.android.settings.display; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; @@ -27,6 +28,10 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.database.Cursor; import android.database.MatrixCursor; import android.provider.Settings; @@ -64,12 +69,16 @@ public class ControlsTrivialPrivacyPreferenceControllerTest { @Mock private PreferenceScreen mPreferenceScreen; + @Mock + private PackageManager mPackageManager; + @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = spy(ApplicationProvider.getApplicationContext()); mContentResolver = spy(mContext.getContentResolver()); when(mContext.getContentResolver()).thenReturn(mContentResolver); + when(mContext.getPackageManager()).thenReturn(mPackageManager); setCustomizableLockScreenQuickAffordancesEnabled(false); @@ -199,5 +208,19 @@ public class ControlsTrivialPrivacyPreferenceControllerTest { }); return cursor; }); + + if (isEnabled) { + final ApplicationInfo applicationInfo = new ApplicationInfo(); + applicationInfo.packageName = "package"; + + final ActivityInfo activityInfo = new ActivityInfo(); + activityInfo.applicationInfo = applicationInfo; + activityInfo.name = "activity"; + + final ResolveInfo resolveInfo = new ResolveInfo(); + resolveInfo.activityInfo = activityInfo; + + when(mPackageManager.resolveActivity(any(), any())).thenReturn(resolveInfo); + } } }