Merge "Add callback when tethering fails" into pi-dev am: 1682085feb

am: 7fcde4490c

Change-Id: Ie1e512ffa61b138769b25bf0c54bc459940f91fc
This commit is contained in:
Lei Yu
2018-03-24 07:56:32 +00:00
committed by android-build-merger
2 changed files with 37 additions and 1 deletions

View File

@@ -22,6 +22,8 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkPolicyManager;
import android.net.wifi.WifiManager;
import android.provider.Settings;
@@ -40,9 +42,14 @@ import org.robolectric.RuntimeEnvironment;
public class WifiTetherSwitchBarControllerTest {
@Mock
private WifiManager mWifiManager;
@Mock
private ConnectivityManager mConnectivityManager;
@Mock
private NetworkPolicyManager mNetworkPolicyManager;
private Context mContext;
private SwitchBar mSwitchBar;
private WifiTetherSwitchBarController mController;
@Before
public void setUp() {
@@ -51,6 +58,13 @@ public class WifiTetherSwitchBarControllerTest {
mContext = spy(RuntimeEnvironment.application);
mSwitchBar = new SwitchBar(mContext);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
mConnectivityManager);
when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
mNetworkPolicyManager);
mController = new WifiTetherSwitchBarController(mContext,
new SwitchBarController(mSwitchBar));
}
@Test
@@ -63,4 +77,15 @@ public class WifiTetherSwitchBarControllerTest {
assertThat(mSwitchBar.isEnabled()).isFalse();
}
@Test
public void testStartTether_fail_resetSwitchBar() {
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
mController.startTether();
mController.mOnStartTetheringCallback.onTetheringFailed();
assertThat(mSwitchBar.isChecked()).isFalse();
assertThat(mSwitchBar.isEnabled()).isTrue();
}
}