use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RemoveAccountPreferenceControllerTest method confirmRemove_shouldRemoveAccount.
@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class })
public void confirmRemove_shouldRemoveAccount() throws AuthenticatorException, OperationCanceledException, IOException {
when(mFragment.isAdded()).thenReturn(true);
FragmentActivity activity = mock(FragmentActivity.class);
when(activity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
when(mFragment.getActivity()).thenReturn(activity);
Account account = new Account("Account11", "com.acct1");
UserHandle userHandle = new UserHandle(10);
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog = RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(mFragment, account, userHandle);
dialog.onCreate(new Bundle());
dialog.onClick(null, 0);
ArgumentCaptor<AccountManagerCallback<Bundle>> callbackCaptor = ArgumentCaptor.forClass(AccountManagerCallback.class);
verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class), callbackCaptor.capture(), nullable(Handler.class), eq(userHandle));
AccountManagerCallback<Bundle> callback = callbackCaptor.getValue();
assertThat(callback).isNotNull();
AccountManagerFuture<Bundle> future = mock(AccountManagerFuture.class);
Bundle resultBundle = new Bundle();
resultBundle.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
when(future.getResult()).thenReturn(resultBundle);
callback.run(future);
verify(activity).finish();
}
use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RemoveAccountPreferenceControllerTest method confirmRemove_activityGone_shouldSilentlyRemoveAccount.
@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class })
public void confirmRemove_activityGone_shouldSilentlyRemoveAccount() throws AuthenticatorException, OperationCanceledException, IOException {
final Account account = new Account("Account11", "com.acct1");
final UserHandle userHandle = new UserHandle(10);
final FragmentActivity activity = mock(FragmentActivity.class);
when(mFragment.isAdded()).thenReturn(true);
when(activity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
when(mFragment.getActivity()).thenReturn(activity).thenReturn(null);
final RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog = RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(mFragment, account, userHandle);
dialog.onCreate(new Bundle());
dialog.onClick(null, 0);
ArgumentCaptor<AccountManagerCallback<Bundle>> callbackCaptor = ArgumentCaptor.forClass(AccountManagerCallback.class);
verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class), callbackCaptor.capture(), nullable(Handler.class), eq(userHandle));
AccountManagerCallback<Bundle> callback = callbackCaptor.getValue();
assertThat(callback).isNotNull();
AccountManagerFuture<Bundle> future = mock(AccountManagerFuture.class);
Bundle resultBundle = new Bundle();
resultBundle.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
when(future.getResult()).thenReturn(resultBundle);
callback.run(future);
verify(activity, never()).finish();
}
use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent.
@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
final DashboardFeatureProviderImpl dashboardFeatureProvider = new DashboardFeatureProviderImpl(mContext);
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(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_TITLE, "summary");
mActivityInfo.metaData.putString("com.android.settings.intent.action", Intent.ACTION_ASSIST);
tile.userHandle = null;
mFragment.displayTile(tile);
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
final Preference preference = new Preference(mContext);
dashboardFeatureProvider.bindPreferenceToTile(activity, false, /* forceRoundedIcon */
MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, null, /* key */
Preference.DEFAULT_ORDER);
assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
preference.performClick();
final Intent intent = Shadows.shadowOf(activity).getNextStartedActivityForResult().intent;
assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class UtilsTest method setActionBarShadowAnimation_shouldSetElevationToZero.
@Test
public void setActionBarShadowAnimation_shouldSetElevationToZero() {
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
final ActionBar actionBar = activity.getActionBar();
Utils.setActionBarShadowAnimation(activity, activity.getLifecycle(), new ScrollView(mContext));
assertThat(actionBar.getElevation()).isEqualTo(0.f);
}
use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class HeaderPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
DashboardFragment fragment = mock(DashboardFragment.class);
when(fragment.getContext()).thenReturn(mContext);
FragmentActivity activity = mock(FragmentActivity.class);
when(activity.getApplicationContext()).thenReturn(mContext);
when(fragment.getActivity()).thenReturn(activity);
mController = spy(new HeaderPreferenceController(mContext, fragment));
when(mPreference.findViewById(anyInt())).thenReturn(mView);
}
Aggregations