Search in sources :

Example 56 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by omnirom.

the class LockUnificationPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
    when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] { FAKE_PROFILE_USER_ID });
    final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
    when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext)).thenReturn(mLockPatternUtils);
}
Also used : FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Before(org.junit.Before)

Example 57 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by omnirom.

the class WifiTetherSettingsTest method startFragment_notAdminUser_shouldRemoveAllPreferences.

@Test
@Config(shadows = ShadowFragment.class)
public void startFragment_notAdminUser_shouldRemoveAllPreferences() {
    final WifiTetherSettings settings = spy(new WifiTetherSettings());
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(settings.getActivity()).thenReturn(activity);
    when(settings.getContext()).thenReturn(mContext);
    final Resources.Theme theme = mContext.getTheme();
    when(activity.getTheme()).thenReturn(theme);
    when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
    doNothing().when(settings).onCreatePreferences(any(Bundle.class), nullable(String.class));
    final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
    ReflectionHelpers.setField(settings, "mDashboardFeatureProvider", fakeFeatureFactory.dashboardFeatureProvider);
    final TextView emptyTextView = mock(TextView.class);
    ReflectionHelpers.setField(settings, "mEmptyTextView", emptyTextView);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    doReturn(screen).when(settings).getPreferenceScreen();
    settings.onCreate(Bundle.EMPTY);
    settings.onStart();
    verify(screen).removeAll();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle) TextView(android.widget.TextView) Resources(android.content.res.Resources) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 58 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by omnirom.

the class RedactNotificationPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
    when(featureFactory.securityFeatureProvider.getLockPatternUtils(mMockContext)).thenReturn(mLockPatternUtils);
    when(mMockContext.getContentResolver()).thenReturn(mContext.getContentResolver());
    when(mMockContext.getSystemService(UserManager.class)).thenReturn(mUm);
    when(mMockContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDpm);
    when(mMockContext.getSystemService(KeyguardManager.class)).thenReturn(mKm);
    when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] { 0 });
    mController = new RedactNotificationPreferenceController(mMockContext, RedactNotificationPreferenceController.KEY_LOCKSCREEN_REDACT);
    mPreference = new RestrictedSwitchPreference(mContext);
    mPreference.setKey(mController.getPreferenceKey());
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
    assertThat(mController.mProfileUserId).isEqualTo(0);
    when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] { 0, 10 });
    mWorkController = new RedactNotificationPreferenceController(mMockContext, RedactNotificationPreferenceController.KEY_LOCKSCREEN_WORK_PROFILE_REDACT);
    mWorkPreference = new RestrictedSwitchPreference(mContext);
    mWorkPreference.setKey(mWorkController.getPreferenceKey());
    when(mScreen.findPreference(mWorkController.getPreferenceKey())).thenReturn(mWorkPreference);
    assertThat(mWorkController.mProfileUserId).isEqualTo(10);
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Before(org.junit.Before)

Aggregations

FakeFeatureFactory (com.android.settings.testutils.FakeFeatureFactory)58 Test (org.junit.Test)35 Before (org.junit.Before)28 Context (android.content.Context)26 Config (org.robolectric.annotation.Config)22 TestConfig (com.android.settings.TestConfig)17 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Activity (android.app.Activity)10 PackageManager (android.content.pm.PackageManager)10 Preference (android.support.v7.preference.Preference)10 ContentResolver (android.content.ContentResolver)7 AppOpsManager (android.app.AppOpsManager)5 Fragment (android.app.Fragment)5 LoaderManager (android.app.LoaderManager)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 Drawable (android.graphics.drawable.Drawable)5 BatteryStats (android.os.BatteryStats)5 UserHandle (android.os.UserHandle)5 RecyclerView (android.support.v7.widget.RecyclerView)5