Merge "Make tether preference controllers extend BasePreferenceController"

This commit is contained in:
TreeHugger Robot
2020-02-06 06:56:21 +00:00
committed by Android (Google) Code Review
9 changed files with 77 additions and 102 deletions

View File

@@ -16,11 +16,12 @@
package com.android.settings.network;
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -28,7 +29,6 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.ConnectivityManager;
import androidx.lifecycle.Lifecycle;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
@@ -55,7 +55,7 @@ public class BluetoothTetherPreferenceControllerTest {
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
mConnectivityManager);
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
mController = new BluetoothTetherPreferenceController(mContext, mock(Lifecycle.class));
mController = new BluetoothTetherPreferenceController(mContext, BLUETOOTH_TETHER_KEY);
}
@Test

View File

@@ -136,7 +136,8 @@ public class TetherEnablerTest {
@Test
public void onSwitchToggled_onlyStartsWifiTetherWhenNeeded() {
when(mSharedPreferences.getBoolean(TetherEnabler.WIFI_TETHER_KEY, true)).thenReturn(true);
when(mSharedPreferences.getBoolean(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, true))
.thenReturn(true);
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
mEnabler.onSwitchToggled(true);
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
@@ -150,7 +151,8 @@ public class TetherEnablerTest {
public void onSwitchToggled_shouldStartUSBTetherWhenSelected() {
SharedPreferences preference = mock(SharedPreferences.class);
ReflectionHelpers.setField(mEnabler, "mSharedPreferences", preference);
when(preference.getBoolean(TetherEnabler.WIFI_TETHER_KEY, true)).thenReturn(false);
when(preference.getBoolean(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, true))
.thenReturn(false);
when(preference.getBoolean(TetherEnabler.USB_TETHER_KEY, false)).thenReturn(true);
when(preference.getBoolean(TetherEnabler.BLUETOOTH_TETHER_KEY, true)).thenReturn(false);

View File

@@ -16,11 +16,12 @@
package com.android.settings.network;
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -28,7 +29,6 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.ConnectivityManager;
import androidx.lifecycle.Lifecycle;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
@@ -54,8 +54,8 @@ public class UsbTetherPreferenceControllerTest {
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
mConnectivityManager);
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[] {""});
mController = new UsbTetherPreferenceController(mContext, mock(Lifecycle.class));
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
mController = new UsbTetherPreferenceController(mContext, USB_TETHER_KEY);
}
@Test
@@ -75,7 +75,7 @@ public class UsbTetherPreferenceControllerTest {
@Test
public void display_availableChangedCorrectly() {
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[] {""});
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
assertThat(mController.isAvailable()).isTrue();
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);

View File

@@ -16,7 +16,9 @@
package com.android.settings.network;
import static com.android.settings.network.WifiTetherDisablePreferenceController.PREF_KEY;
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
import static com.android.settings.network.TetherEnabler.WIFI_TETHER_DISABLE_KEY;
import static com.google.common.truth.Truth.assertThat;
@@ -30,7 +32,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
@@ -68,10 +69,10 @@ public class WifiTetherDisablePreferenceControllerTest {
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
when(mContext.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
.thenReturn(mSharedPreferences);
mController = new WifiTetherDisablePreferenceController(mContext, mock(Lifecycle.class));
mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
ReflectionHelpers.setField(mController, "mPreference", mPreference);
when(mPreferenceScreen.findPreference(PREF_KEY)).thenReturn(mPreference);
when(mPreferenceScreen.findPreference(WIFI_TETHER_DISABLE_KEY)).thenReturn(mPreference);
}
@Test
@@ -103,30 +104,22 @@ public class WifiTetherDisablePreferenceControllerTest {
@Test
public void switch_shouldListenToUsbAndBluetooth() {
when(mSharedPreferences.getBoolean(
BluetoothTetherPreferenceController.PREF_KEY, false)).thenReturn(true);
mController.onSharedPreferenceChanged(mSharedPreferences,
BluetoothTetherPreferenceController.PREF_KEY);
when(mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)).thenReturn(true);
mController.onSharedPreferenceChanged(mSharedPreferences, BLUETOOTH_TETHER_KEY);
verify(mPreference).setVisible(eq(true));
when(mSharedPreferences.getBoolean(
UsbTetherPreferenceController.PREF_KEY, false)).thenReturn(true);
mController.onSharedPreferenceChanged(mSharedPreferences,
UsbTetherPreferenceController.PREF_KEY);
when(mSharedPreferences.getBoolean(USB_TETHER_KEY, false)).thenReturn(true);
mController.onSharedPreferenceChanged(mSharedPreferences, USB_TETHER_KEY);
assertThat(mController.shouldShow()).isTrue();
when(mSharedPreferences.getBoolean(
UsbTetherPreferenceController.PREF_KEY, false)).thenReturn(false);
mController.onSharedPreferenceChanged(mSharedPreferences,
UsbTetherPreferenceController.PREF_KEY);
when(mSharedPreferences.getBoolean(USB_TETHER_KEY, false)).thenReturn(false);
mController.onSharedPreferenceChanged(mSharedPreferences, USB_TETHER_KEY);
assertThat(mController.shouldShow()).isTrue();
when(mSharedPreferences.getBoolean(
BluetoothTetherPreferenceController.PREF_KEY, false)).thenReturn(false);
when(mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)).thenReturn(false);
when(mSharedPreferences.edit()).thenReturn(mock(SharedPreferences.Editor.class));
when(mPreference.isChecked()).thenReturn(true);
mController.onSharedPreferenceChanged(mSharedPreferences,
BluetoothTetherPreferenceController.PREF_KEY);
mController.onSharedPreferenceChanged(mSharedPreferences, BLUETOOTH_TETHER_KEY);
verify(mPreference).setChecked(eq(false));
verify(mPreference).setVisible(eq(false));
}