import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
+import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.AppItem;
}
@Test
+ @Config(shadows = ShadowFragment.class)
public void onCreate_appUid_shouldGetAppLabelFromAppInfo() throws NameNotFoundException {
mFragment = spy(new AppDataUsage());
final FragmentActivity activity = spy(Robolectric.setupActivity(FragmentActivity.class));
doReturn(activity).when(mFragment).getActivity();
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
- FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
+ FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
final String packageName = "testPackage";
final int uid = (Process.FIRST_APPLICATION_UID + Process.LAST_APPLICATION_UID) / 2;
- doReturn(new String[] {packageName}).when(mPackageManager).getPackagesForUid(uid);
+ doReturn(new String[]{packageName}).when(mPackageManager).getPackagesForUid(uid);
final String label = "testLabel";
final AppItem appItem = new AppItem(uid);
appItem.uids.put(uid, true);
final ApplicationInfo info = spy(new ApplicationInfo());
doReturn(label).when(info).loadLabel(mPackageManager);
when(mPackageManager.getApplicationInfoAsUser(
- eq(packageName), anyInt() /* flags */, anyInt() /* userId */)).thenReturn(info);
+ eq(packageName), anyInt() /* flags */, anyInt() /* userId */)).thenReturn(info);
final Bundle args = new Bundle();
args.putParcelable(AppDataUsage.ARG_APP_ITEM, appItem);
args.putInt(AppInfoBase.ARG_PACKAGE_UID, uid);
}
@Test
+ @Config(shadows = ShadowFragment.class)
public void onCreate_notAppUid_shouldGetAppLabelFromUidDetailProvider() {
mFragment = spy(new AppDataUsage());
ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
- FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
+ FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
doReturn(Robolectric.setupActivity(FragmentActivity.class)).when(mFragment).getActivity();
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
final UidDetailProvider uidDetailProvider = mock(UidDetailProvider.class);
final UidDetail uidDetail = new UidDetail();
uidDetail.label = label;
when(uidDetailProvider.getUidDetail(eq(uid), anyBoolean() /* blocking */)).
- thenReturn(uidDetail);
+ thenReturn(uidDetail);
final AppItem appItem = new AppItem(uid);
appItem.uids.put(uid, true);
final Bundle args = new Bundle();
mFragment = spy(new AppDataUsage());
when(mFragment.getPreferenceManager())
- .thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
+ .thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
ReflectionHelpers.setField(mFragment, "mAppItem", mock(AppItem.class));
@Test
public void bindAppHeader_workApp_shouldSetWorkAppUid()
- throws PackageManager.NameNotFoundException {
+ throws PackageManager.NameNotFoundException {
final int fakeUserId = 100;
mFragment = spy(new AppDataUsage());
when(mHeaderController.setHasAppInfoLink(anyBoolean())).thenReturn(mHeaderController);
when(mFragment.getPreferenceManager())
- .thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
+ .thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
final long foregroundBytes = 5678L;
final List<NetworkCycleDataForUid> appUsage = new ArrayList<>();
appUsage.add(new NetworkCycleDataForUid.Builder()
- .setBackgroundUsage(backgroundBytes).setForegroundUsage(foregroundBytes).build());
+ .setBackgroundUsage(backgroundBytes).setForegroundUsage(foregroundBytes).build());
ReflectionHelpers.setField(mFragment, "mUsageData", appUsage);
final Preference backgroundPref = mock(Preference.class);
ReflectionHelpers.setField(mFragment, "mBackgroundUsage", backgroundPref);
verify(cycle).setVisible(true);
verify(totalPref).setSummary(
- DataUsageUtils.formatDataUsage(context, backgroundBytes + foregroundBytes));
+ DataUsageUtils.formatDataUsage(context, backgroundBytes + foregroundBytes));
verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
verify(foregroundPref).setSummary(DataUsageUtils.formatDataUsage(context, foregroundBytes));
}
ReflectionHelpers.setField(mFragment, "mContext", context);
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
ReflectionHelpers.setField(mFragment, "mTemplate",
- NetworkTemplate.buildTemplateWifiWildcard());
+ NetworkTemplate.buildTemplateWifiWildcard());
final long end = System.currentTimeMillis();
final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
- mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
+ mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
final List<Integer> uids = loader.getUids();
assertThat(uids).hasSize(1);
ReflectionHelpers.setField(mFragment, "mContext", context);
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
ReflectionHelpers.setField(mFragment, "mTemplate",
- NetworkTemplate.buildTemplateWifiWildcard());
+ NetworkTemplate.buildTemplateWifiWildcard());
final long end = System.currentTimeMillis();
final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
- mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
+ mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
final List<Integer> uids = loader.getUids();
assertThat(uids).hasSize(3);
ReflectionHelpers.setField(mFragment, "mCycles", testCycles);
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
ReflectionHelpers.setField(mFragment, "mTemplate",
- NetworkTemplate.buildTemplateWifiWildcard());
+ NetworkTemplate.buildTemplateWifiWildcard());
final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
- mFragment.mUidDataCallbacks.onCreateLoader(0 /* id */, Bundle.EMPTY /* args */);
+ mFragment.mUidDataCallbacks.onCreateLoader(0 /* id */, Bundle.EMPTY /* args */);
final ArrayList<Long> cycles = loader.getCycles();
assertThat(cycles).hasSize(2);
}
@Test
- @Config(shadows = {ShadowDataUsageUtils.class, ShadowSubscriptionManager.class})
+ @Config(shadows = {ShadowDataUsageUtils.class, ShadowSubscriptionManager.class,
+ ShadowFragment.class})
public void onCreate_noNetworkTemplateAndInvalidDataSubscription_shouldUseWifiTemplate() {
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
ShadowDataUsageUtils.HAS_SIM = false;
ShadowSubscriptionManager.setDefaultDataSubscriptionId(
- SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mFragment = spy(new AppDataUsage());
doReturn(Robolectric.setupActivity(FragmentActivity.class)).when(mFragment).getActivity();
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
doReturn(new UidDetail()).when(uidDetailProvider).getUidDetail(anyInt(), anyBoolean());
ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
- FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
+ FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
final Bundle args = new Bundle();
args.putInt(AppInfoBase.ARG_PACKAGE_UID, 123123);
mFragment.setArguments(args);
mFragment.onCreate(Bundle.EMPTY);
assertThat(mFragment.mTemplate.getMatchRule())
- .isEqualTo(NetworkTemplate.MATCH_WIFI_WILDCARD);
+ .isEqualTo(NetworkTemplate.MATCH_WIFI_WILDCARD);
}
}