Allow the LockPatterUtils to be null

In some tests it could inconsistently become a null, crashing with NPE, for the reason I can't understand (maybe there is a race condition somewhere between mocking and accessing the LockPatterUtils in such tests)
Let's accept it gracefully

Test: atest SettingsUnitTests
Bug: 382637173
Flag: EXEMPT bugfix
Change-Id: I35d5faa1a29307fc780207a816680a32b2796bc0
This commit is contained in:
Yuri Ufimtsev
2025-02-04 14:57:33 +00:00
parent c32021846e
commit 55b7b0613d
3 changed files with 50 additions and 5 deletions

View File

@@ -78,6 +78,7 @@ public class ScreenLockPreferenceDetailsUtilsTest {
private StorageManager mStorageManager;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private ScreenLockPreferenceDetailsUtils mScreenLockPreferenceDetailsUtils;
@@ -95,8 +96,8 @@ public class ScreenLockPreferenceDetailsUtilsTest {
doNothing().when(mContext).startActivity(any());
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext);
@@ -230,6 +231,15 @@ public class ScreenLockPreferenceDetailsUtilsTest {
assertNull(mScreenLockPreferenceDetailsUtils.getSummary(USER_ID));
}
@Test
public void getSummary_noLockPatternUtils_shouldReturnNull() {
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(null);
mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext);
assertNull(mScreenLockPreferenceDetailsUtils.getSummary(USER_ID));
}
@Test
public void isPasswordQualityManaged_withoutAdmin_shouldReturnFalse() {
final RestrictedLockUtils.EnforcedAdmin admin = null;
@@ -274,6 +284,15 @@ public class ScreenLockPreferenceDetailsUtilsTest {
assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse();
}
@Test
public void isLockPatternSecure_noLockPatterUtils_shouldReturnFalse() {
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(null);
mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext);
assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse();
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION)
public void shouldShowGearMenu_patternIsSecure_flagOn_shouldReturnFalse() {
@@ -341,6 +360,20 @@ public class ScreenLockPreferenceDetailsUtilsTest {
ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
}
@Test
public void getLaunchChooseLockGenericFragmentIntent_noLockPatternUtils_returnsIntent() {
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(null);
mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext);
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
final Intent intent = mScreenLockPreferenceDetailsUtils
.getLaunchChooseLockGenericFragmentIntent(SOURCE_METRICS_CATEGORY);
assertFragmentLaunchIntent(intent,
ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
}
private void whenConfigShowUnlockSetOrChangeIsEnabled(boolean enabled) {
final int resId = ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(), "bool",