/**
* Add preference to collapsed list.
*/
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ @VisibleForTesting
void addToCollapsedList(Preference preference) {
// Insert preference based on it's order.
int insertionIndex = Collections.binarySearch(mCollapsedPrefs, preference);
updateExpandButtonSummary();
}
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ @VisibleForTesting
List<Preference> getCollapsedPrefs() {
return mCollapsedPrefs;
}
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ @VisibleForTesting
void updateExpandButtonSummary() {
final int size = mCollapsedPrefs.size();
if (size == 0) {
} else {
CharSequence summary = mCollapsedPrefs.get(0).getTitle();
for (int i = 1; i < size; i++) {
- summary = mContext.getString(R.string.join_many_items_middle, summary,
- mCollapsedPrefs.get(i).getTitle());
+ final CharSequence nextSummary = mCollapsedPrefs.get(i).getTitle();
+ if (!TextUtils.isEmpty(nextSummary)) {
+ summary = mContext.getString(R.string.join_many_items_middle, summary,
+ nextSummary);
+ }
}
mExpandButton.setSummary(summary);
}
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
- @Mock
- private FakeFeatureFactory mFakeFeatureFactory;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceFragment mPreferenceFragment;
@Mock
FakeFeatureFactory.setupForTest(mContext);
mScreen = mPreferenceFragment.getPreferenceScreen();
mAppContext = ShadowApplication.getInstance().getApplicationContext();
- mFakeFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
mMixin = new ProgressiveDisclosureMixin(mAppContext,
mPreferenceFragment, false /* keepExpanded */);
ReflectionHelpers.setField(mMixin, "mExpandButton", mExpandButton);
}
@Test
+ public void updateExpandSummary_doNotIncludeEmptyPrefTitle() {
+ final Preference pref1 = new Preference(mAppContext);
+ pref1.setTitle("1");
+ final Preference pref2 = new Preference(mAppContext);
+ pref2.setTitle(null);
+ final Preference pref3 = new Preference(mAppContext);
+ pref3.setTitle("3");
+ final Preference pref4 = new Preference(mAppContext);
+ pref4.setTitle("");
+
+ mMixin.addToCollapsedList(pref1);
+ mMixin.addToCollapsedList(pref2);
+ mMixin.addToCollapsedList(pref3);
+ mMixin.addToCollapsedList(pref4);
+
+ verify(mExpandButton).setSummary("1, 3");
+ }
+
+ @Test
public void updateExapndSummary_singlePref_expandSummarySameAsPrefTitle() {
final String TEST = "test";
final Preference pref = new Preference(mAppContext);