Merge "Add configs to display/hide a few tiles in device info page"

This commit is contained in:
TreeHugger Robot
2019-01-29 01:29:35 +00:00
committed by Android (Google) Code Review
11 changed files with 100 additions and 76 deletions

View File

@@ -70,10 +70,12 @@ public class EmergencyInfoPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new EmergencyInfoPreferenceController(mContext);
mController = new EmergencyInfoPreferenceController(mContext, "test_key");
mPreference = new Preference(Robolectric.setupActivity(Activity.class));
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
when(mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info))
.thenReturn(true);
}
@After
@@ -104,6 +106,7 @@ public class EmergencyInfoPreferenceControllerTest {
mController.updateRawDataToIndex(data);
assertThat(mController.isAvailable()).isTrue();
assertThat(data).isNotEmpty();
}
@@ -152,7 +155,7 @@ public class EmergencyInfoPreferenceControllerTest {
final Activity activity = Robolectric.setupActivity(Activity.class);
final Preference preference = new Preference(activity);
preference.setKey("emergency_info");
mController = new EmergencyInfoPreferenceController(activity);
mController = new EmergencyInfoPreferenceController(activity, preference.getKey());
mController.handlePreferenceTreeClick(preference);

View File

@@ -29,36 +29,52 @@ import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
public class BrandedAccountPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private BrandedAccountPreferenceController mController;
private FakeFeatureFactory fakeFeatureFactory;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
fakeFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new BrandedAccountPreferenceController(mContext);
}
@Test
public void isAvailable_defaultOff() {
assertThat(mController.isAvailable()).isFalse();
public void isAvailable_configOn_noAccount_off() {
final BrandedAccountPreferenceController controller =
new BrandedAccountPreferenceController(mContext, "test_key");
assertThat(controller.isAvailable()).isFalse();
}
@Test
public void isAvailable_onWhenAccountIsAvailable() {
public void isAvailable_accountIsAvailable_on() {
when(fakeFeatureFactory.mAccountFeatureProvider.getAccounts(any(Context.class)))
.thenReturn(new Account[] {new Account("fake@account.foo", "fake.reallyfake")});
mController = new BrandedAccountPreferenceController(mContext);
assertThat(mController.isAvailable()).isTrue();
.thenReturn(new Account[]{new Account("fake@account.foo", "fake.reallyfake")});
final BrandedAccountPreferenceController controller =
new BrandedAccountPreferenceController(mContext, "test_key");
assertThat(controller.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_configOff_hasAccount_off() {
when(fakeFeatureFactory.mAccountFeatureProvider.getAccounts(any(Context.class)))
.thenReturn(new Account[]{new Account("fake@account.foo", "fake.reallyfake")});
final BrandedAccountPreferenceController controller =
new BrandedAccountPreferenceController(mContext, "test_key");
assertThat(controller.isAvailable()).isFalse();
}
}

View File

@@ -75,7 +75,7 @@ public class DeviceNamePreferenceControllerTest {
configuration.SSID = "test-ap";
when(mWifiManager.getWifiApConfiguration()).thenReturn(configuration);
mController = new DeviceNamePreferenceController(mContext);
mController = new DeviceNamePreferenceController(mContext, "test_key");
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
@@ -99,17 +99,17 @@ public class DeviceNamePreferenceControllerTest {
public void constructor_deviceNameLoadedIfSet() {
Settings.Global.putString(
mContext.getContentResolver(), Settings.Global.DEVICE_NAME, "Test");
mController = new DeviceNamePreferenceController(mContext);
mController = new DeviceNamePreferenceController(mContext, "test_key");
assertThat(mController.getSummary()).isEqualTo("Test");
}
@Test
public void isTextValid_nameUnder33CharactersIsValid() {
public void isTextValid_nameUnder33Characters_isValid() {
assertThat(mController.isTextValid("12345678901234567890123456789012")).isTrue();
}
@Test
public void isTextValid_nameTooLongIsInvalid() {
public void isTextValid_nameTooLong_isInvalid() {
assertThat(mController.isTextValid("123456789012345678901234567890123")).isFalse();
}