Revert "Revert "Replace dynamic summary text for SettingPref""

This reverts commit 8061aaef62.
Test: make RunSettingsRoboTests
Fixes: 36101902
Change-Id: Ide74780153fc7f36d897f559c7a3c138190e3320
This commit is contained in:
Matthew Fritze
2017-05-23 21:02:57 +00:00
parent 8061aaef62
commit c1e9f8787f
5 changed files with 83 additions and 4 deletions

View File

@@ -0,0 +1,67 @@
package com.android.settings.notification;
import android.content.res.Resources;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.DropDownPreference;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingPrefTest {
@Test
public void update_setsDropDownSummaryText() {
Context context = RuntimeEnvironment.application;
String testSetting = "test_setting";
int[] values = new int[] {1,2,3};
String[] entries = new String[] {"one", "two", "three"};
SettingPref settingPref =
spy(new SettingPref(SettingPref.TYPE_GLOBAL, "key", testSetting, 0, values) {
@Override
protected String getCaption(Resources res, int value) {
return "temp";
}
});
DropDownPreference dropdownPref = spy(new DropDownPreference(context));
dropdownPref.setEntries(entries);
settingPref.mDropDown = dropdownPref;
Settings.Global.putInt(context.getContentResolver(), testSetting, values[2]);
settingPref.update(context);
assertThat(settingPref.mDropDown.getSummary()).isEqualTo(entries[2]);
}
@Test
public void update_setsDropDownSummaryText_noMatch_noError() {
Context context = RuntimeEnvironment.application;
String testSetting = "test_setting";
int[] values = new int[] {1,2,3};
String[] entries = new String[] {"one", "two", "three"};
SettingPref settingPref =
spy(new SettingPref(SettingPref.TYPE_GLOBAL, "key", testSetting, 0, values) {
@Override
protected String getCaption(Resources res, int value) {
return "temp";
}
});
DropDownPreference dropdownPref = spy(new DropDownPreference(context));
dropdownPref.setEntries(entries);
settingPref.mDropDown = dropdownPref;
Settings.Global.putInt(context.getContentResolver(), testSetting, -1);
settingPref.update(context);
assertThat(settingPref.mDropDown.getSummary()).isNull();
}
}