Merge "Allow appending static preferences to RadioButtonPickerFragment"

This commit is contained in:
TreeHugger Robot
2018-12-06 23:57:39 +00:00
committed by Android (Google) Code Review
9 changed files with 163 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.core;
import static com.android.settings.core.PreferenceXmlParserUtils
.METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_APPEND;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEYWORDS;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SEARCHABLE;
@@ -315,6 +316,32 @@ public class PreferenceXmlParserUtilsTest {
}
}
@Test
@Config(qualifiers = "mcc999")
public void extractMetadata_requestAppendProperty_shouldDefaultToFalse()
throws Exception {
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
R.xml.display_settings,
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN | MetadataFlag.FLAG_NEED_PREF_APPEND);
for (Bundle bundle : metadata) {
assertThat(bundle.getBoolean(METADATA_APPEND)).isFalse();
}
}
@Test
@Config(qualifiers = "mcc999")
public void extractMetadata_requestAppendProperty_shouldReturnCorrectValue()
throws Exception {
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
R.xml.battery_saver_schedule_settings,
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN | MetadataFlag.FLAG_NEED_PREF_APPEND);
for (Bundle bundle : metadata) {
assertThat(bundle.getBoolean(METADATA_APPEND)).isTrue();
}
}
/**
* @param resId the ID for the XML preference
* @return an XML resource parser that points to the start tag

View File

@@ -209,6 +209,7 @@ public class ColorModePreferenceFragmentTest {
@Test
public void onCreatePreferences_useNewTitle_shouldAddColorModePreferences() {
when(mFragment.getContext()).thenReturn(RuntimeEnvironment.application);
doNothing().when(mFragment).addPreferencesFromResource(anyInt());
doNothing().when(mFragment).updateCandidates();

View File

@@ -18,6 +18,7 @@ package com.android.settings.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -37,7 +38,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@@ -98,6 +101,26 @@ public class RadioButtonPickerFragmentTest {
assertThat(mFragment.setDefaultKeyCalled).isTrue();
}
@Test
public void staticPreferencesPrepended_addedFirst() {
mFragment.mAppendStaticPreferences = false;
mFragment.updateCandidates();
InOrder inOrder = Mockito.inOrder(mFragment);
inOrder.verify(mFragment).addStaticPreferences(any());
inOrder.verify(mFragment).getRadioButtonPreferenceCustomLayoutResId();
}
@Test
public void staticPreferencesAppended_addedLast() {
mFragment.mAppendStaticPreferences = true;
mFragment.updateCandidates();
InOrder inOrder = Mockito.inOrder(mFragment);
inOrder.verify(mFragment).mayCheckOnlyRadioButton();
inOrder.verify(mFragment).addStaticPreferences(any());
}
@Test
public void shouldHaveNoCustomPreferenceLayout() {
assertThat(mFragment.getRadioButtonPreferenceCustomLayoutResId()).isEqualTo(0);