use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by DirtyUnicorns.
the class DatabaseResultLoaderTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
FakeFeatureFactory.setupForTest(mMockContext);
FakeFeatureFactory factory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
when(factory.searchFeatureProvider.getSiteMapManager()).thenReturn(mSiteMapManager);
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
setUpDb();
}
use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by crdroidandroid.
the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent.
@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
FakeFeatureFactory.setupForTest(mActivity);
final FakeFeatureFactory featureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
final DashboardFeatureProviderImpl dashboardFeatureProvider = new DashboardFeatureProviderImpl(mActivity);
final PackageManager packageManager = mock(PackageManager.class);
ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
when(packageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(mock(ResolveInfo.class));
final Tile tile = new Tile();
tile.key = "key";
tile.metaData = new Bundle();
tile.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
tile.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
tile.metaData.putString("com.android.settings.intent.action", Intent.ACTION_ASSIST);
tile.intent = new Intent();
tile.userHandle = null;
mFragment.displayTile(tile);
final Activity activity = Robolectric.buildActivity(Activity.class).get();
final Preference preference = new Preference(mContext);
dashboardFeatureProvider.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, "key", Preference.DEFAULT_ORDER);
preference.performClick();
final Intent intent = shadowOf(activity).getNextStartedActivityForResult().intent;
assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by crdroidandroid.
the class DatabaseResultLoaderTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
FakeFeatureFactory.setupForTest(mMockContext);
FakeFeatureFactory factory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
when(factory.searchFeatureProvider.getSiteMapManager()).thenReturn(mSiteMapManager);
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
setUpDb();
}
use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by crdroidandroid.
the class InstalledAppResultLoaderTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest(mContext);
when(factory.searchFeatureProvider.getSiteMapManager()).thenReturn(mSiteMapManager);
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(mContext.getString(R.string.applications_settings)).thenReturn("app");
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt())).thenReturn(Arrays.asList(ApplicationTestUtils.buildInfo(0, /* uid */
"app1", FLAG_SYSTEM, 0), ApplicationTestUtils.buildInfo(0, /* uid */
"app2", FLAG_SYSTEM, 0), ApplicationTestUtils.buildInfo(0, /* uid */
"app3", FLAG_SYSTEM, 0), ApplicationTestUtils.buildInfo(0, /* uid */
"app4", 0, /* flags */
0), ApplicationTestUtils.buildInfo(0, /* uid */
"app", 0, /* flags */
0), ApplicationTestUtils.buildInfo(0, /* uid */
"appBuffer", 0, /* flags */
0)));
}
use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by SudaMod.
the class AdvancedPowerUsageDetailTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFragment = spy(new AdvancedPowerUsageDetail());
doReturn(mContext).when(mFragment).getContext();
doReturn(mActivity).when(mFragment).getActivity();
doReturn(SUMMARY).when(mFragment).getString(anyInt());
doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
doReturn(mBundle).when(mFragment).getArguments();
doReturn(mLoaderManager).when(mFragment).getLoaderManager();
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
doReturn(UID).when(mBatterySipper).getUid();
doReturn(APP_LABEL).when(mBatteryEntry).getLabel();
doReturn(BACKGROUND_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_BACKGROUND), anyLong(), anyInt());
doReturn(PROCSTATE_TOP_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_TOP), anyLong(), anyInt());
doReturn(mForegroundActivityTimer).when(mUid).getForegroundActivityTimer();
doReturn(FOREGROUND_ACTIVITY_TIME_US).when(mForegroundActivityTimer).getTotalTimeLocked(anyLong(), anyInt());
ReflectionHelpers.setField(mBatteryEntry, "sipper", mBatterySipper);
mBatteryEntry.iconId = ICON_ID;
mBatterySipper.uidObj = mUid;
mBatterySipper.drainType = BatterySipper.DrainType.APP;
mFragment.mHeaderPreference = mHeaderPreference;
mFragment.mState = mState;
mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
mAppEntry.info = mock(ApplicationInfo.class);
mTestActivity = spy(new SettingsActivity());
doReturn(mPackageManager).when(mTestActivity).getPackageManager();
doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
mBatteryUtils = spy(BatteryUtils.getInstance(mTestActivity));
doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
Answer<Void> callable = invocation -> {
mBundle = captor.getValue();
return null;
};
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class), nullable(UserHandle.class));
mForegroundPreference = new Preference(mContext);
mBackgroundPreference = new Preference(mContext);
mPowerUsagePreference = new Preference(mContext);
mFragment.mForegroundPreference = mForegroundPreference;
mFragment.mBackgroundPreference = mBackgroundPreference;
mFragment.mPowerUsagePreference = mPowerUsagePreference;
mFragment.mAnomalySummaryPreferenceController = mAnomalySummaryPreferenceController;
mAnomalies = new ArrayList<>();
mAnomalies.add(new Anomaly.Builder().setUid(UID).setType(Anomaly.AnomalyType.WAKE_LOCK).build());
}
Aggregations