Revert switchBar if enable / disable subscription fails.
Bug: 123321718 Test: build manual test Change-Id: Ia7e8c762d91f81b67e0d0b11d36dfa78ec1e2d18
This commit is contained in:
committed by
Xiangyu/Malcolm Chen
parent
9e3b3d77a2
commit
046419a92a
@@ -18,6 +18,7 @@ package com.android.settings.network.telephony;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -71,6 +72,8 @@ public class MobileNetworkSwitchControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean()))
|
||||
.thenReturn(true);
|
||||
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
@@ -128,6 +131,19 @@ public class MobileNetworkSwitchControllerTest {
|
||||
verify(mSubscriptionManager).setSubscriptionEnabled(eq(mSubId), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledFailed() {
|
||||
when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean()))
|
||||
.thenReturn(false);
|
||||
when(mSubscriptionManager.isSubscriptionEnabled(mSubId)).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mSwitchBar.isShowing()).isTrue();
|
||||
assertThat(mSwitchBar.isChecked()).isTrue();
|
||||
mSwitchBar.setChecked(false);
|
||||
verify(mSubscriptionManager).setSubscriptionEnabled(eq(mSubId), eq(false));
|
||||
assertThat(mSwitchBar.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void switchChangeListener_fromDisabledToEnabled_setSubscriptionEnabledCalledCorrectly() {
|
||||
when(mSubscriptionManager.isSubscriptionEnabled(mSubId)).thenReturn(false);
|
||||
|
Reference in New Issue
Block a user