use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MobileNetworkListControllerTest method onSubscriptionsChanged_startWithThreeSubsAndRemoveOne_correctPreferenceRemoved.
@Test
public void onSubscriptionsChanged_startWithThreeSubsAndRemoveOne_correctPreferenceRemoved() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
final SubscriptionInfo sub3 = createMockSubscription(3, "sub3");
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2, sub3));
mController.displayPreference(mPreferenceScreen);
mController.onResume();
final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mPreferenceScreen, times(3)).addPreference(preferenceCaptor.capture());
// remove sub2, and check that the second pref was removed from the screen
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub3));
mController.onSubscriptionsChanged();
final ArgumentCaptor<Preference> removedPrefCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mPreferenceScreen).removePreference(removedPrefCaptor.capture());
assertThat(removedPrefCaptor.getValue().getTitle()).isEqualTo("sub2");
}
use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MobileNetworkListControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(Robolectric.setupActivity(Activity.class));
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
when(mPreferenceScreen.getContext()).thenReturn(mContext);
mAddMorePreference = new Preference(mContext);
when(mPreferenceScreen.findPreference(MobileNetworkListController.KEY_ADD_MORE)).thenReturn(mAddMorePreference);
mController = new MobileNetworkListController(mContext, mLifecycle);
}
use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MobileNetworkListControllerTest method onSubscriptionsChanged_twoSubscriptionsOneChangesName_preferenceUpdated.
@Test
public void onSubscriptionsChanged_twoSubscriptionsOneChangesName_preferenceUpdated() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
mController.displayPreference(mPreferenceScreen);
mController.onResume();
final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mPreferenceScreen, times(2)).addPreference(preferenceCaptor.capture());
when(sub2.getDisplayName()).thenReturn("new name");
mController.onSubscriptionsChanged();
assertThat(preferenceCaptor.getAllValues().get(1).getTitle()).isEqualTo("new name");
}
use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MobileNetworkPreferenceControllerTest method serviceStateChange_shouldUpdatePrefSummary.
@Test
public void serviceStateChange_shouldUpdatePrefSummary() {
final String testCarrierName = "test";
final Preference mPreference = mock(Preference.class);
mController = spy(new MobileNetworkPreferenceController(mContext));
mLifecycle.addObserver(mController);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
doReturn(true).when(mController).isAvailable();
// Display pref and go through lifecycle to set up listener.
mController.displayPreference(mScreen);
mLifecycle.handleLifecycleEvent(ON_START);
verify(mController).onStart();
verify(mTelephonyManager).listen(mController.mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
// Trigger listener update
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(testCarrierName);
mController.mPhoneStateListener.onServiceStateChanged(null);
// Carrier name should be set.
verify(mPreference).setSummary(testCarrierName);
}
use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NetworkScorerPickerPreferenceControllerTest method updateState_preferenceSetSummaryAsActiveScorerLabel.
@Test
public void updateState_preferenceSetSummaryAsActiveScorerLabel() {
ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE, TEST_SCORER_CLASS);
NetworkScorerAppData scorerAppData = new NetworkScorerAppData(0, scorer, TEST_SCORER_LABEL, null, /* enableUseOpenWifiActivity */
null);
when(mNetworkScorer.getAllValidScorers()).thenReturn(Collections.singletonList(scorerAppData));
when(mNetworkScorer.getActiveScorer()).thenReturn(scorerAppData);
Preference preference = mock(Preference.class);
mController.updateState(preference);
verify(preference).setSummary(TEST_SCORER_LABEL);
}
Aggregations