Loading packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java +21 −17 Original line number Diff line number Diff line Loading @@ -59,12 +59,13 @@ public class FooterPreference extends Preference { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); TextView title = holder.itemView.findViewById(android.R.id.title); if (!TextUtils.isEmpty(mContentDescription)) { if (title != null && !TextUtils.isEmpty(mContentDescription)) { title.setContentDescription(mContentDescription); } TextView learnMore = holder.itemView.findViewById(R.id.settingslib_learn_more); if (learnMore != null && mLearnMoreListener != null) { if (learnMore != null) { if (mLearnMoreListener != null) { learnMore.setVisibility(View.VISIBLE); if (TextUtils.isEmpty(mLearnMoreText)) { mLearnMoreText = learnMore.getText(); Loading @@ -82,10 +83,13 @@ public class FooterPreference extends Preference { } else { learnMore.setVisibility(View.GONE); } } View icon = holder.itemView.findViewById(R.id.icon_frame); if (icon != null) { icon.setVisibility(mIconVisibility); } } @Override public void setSummary(CharSequence summary) { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/FooterPreferenceTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.settingslib.widget; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.view.LayoutInflater; import android.view.View; Loading Loading @@ -87,4 +90,52 @@ public class FooterPreferenceTest { assertThat(mFooterPreference.mIconVisibility).isEqualTo(View.GONE); } @Test public void onBindViewHolder_whenTitleIsNull_shouldNotRaiseNpe() { PreferenceViewHolder viewHolder = spy(PreferenceViewHolder.createInstanceForTests( LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null))); when(viewHolder.findViewById(R.id.title)).thenReturn(null); Throwable actualThrowable = null; try { mFooterPreference.onBindViewHolder(viewHolder); } catch (Throwable throwable) { actualThrowable = throwable; } assertThat(actualThrowable).isNull(); } @Test public void onBindViewHolder_whenLearnMoreIsNull_shouldNotRaiseNpe() { PreferenceViewHolder viewHolder = spy(PreferenceViewHolder.createInstanceForTests( LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null))); when(viewHolder.findViewById(R.id.settingslib_learn_more)).thenReturn(null); Throwable actualThrowable = null; try { mFooterPreference.onBindViewHolder(viewHolder); } catch (Throwable throwable) { actualThrowable = throwable; } assertThat(actualThrowable).isNull(); } @Test public void onBindViewHolder_whenIconFrameIsNull_shouldNotRaiseNpe() { PreferenceViewHolder viewHolder = spy(PreferenceViewHolder.createInstanceForTests( LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null))); when(viewHolder.findViewById(R.id.icon_frame)).thenReturn(null); Throwable actualThrowable = null; try { mFooterPreference.onBindViewHolder(viewHolder); } catch (Throwable throwable) { actualThrowable = throwable; } assertThat(actualThrowable).isNull(); } } Loading
packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java +21 −17 Original line number Diff line number Diff line Loading @@ -59,12 +59,13 @@ public class FooterPreference extends Preference { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); TextView title = holder.itemView.findViewById(android.R.id.title); if (!TextUtils.isEmpty(mContentDescription)) { if (title != null && !TextUtils.isEmpty(mContentDescription)) { title.setContentDescription(mContentDescription); } TextView learnMore = holder.itemView.findViewById(R.id.settingslib_learn_more); if (learnMore != null && mLearnMoreListener != null) { if (learnMore != null) { if (mLearnMoreListener != null) { learnMore.setVisibility(View.VISIBLE); if (TextUtils.isEmpty(mLearnMoreText)) { mLearnMoreText = learnMore.getText(); Loading @@ -82,10 +83,13 @@ public class FooterPreference extends Preference { } else { learnMore.setVisibility(View.GONE); } } View icon = holder.itemView.findViewById(R.id.icon_frame); if (icon != null) { icon.setVisibility(mIconVisibility); } } @Override public void setSummary(CharSequence summary) { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/FooterPreferenceTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.settingslib.widget; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.view.LayoutInflater; import android.view.View; Loading Loading @@ -87,4 +90,52 @@ public class FooterPreferenceTest { assertThat(mFooterPreference.mIconVisibility).isEqualTo(View.GONE); } @Test public void onBindViewHolder_whenTitleIsNull_shouldNotRaiseNpe() { PreferenceViewHolder viewHolder = spy(PreferenceViewHolder.createInstanceForTests( LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null))); when(viewHolder.findViewById(R.id.title)).thenReturn(null); Throwable actualThrowable = null; try { mFooterPreference.onBindViewHolder(viewHolder); } catch (Throwable throwable) { actualThrowable = throwable; } assertThat(actualThrowable).isNull(); } @Test public void onBindViewHolder_whenLearnMoreIsNull_shouldNotRaiseNpe() { PreferenceViewHolder viewHolder = spy(PreferenceViewHolder.createInstanceForTests( LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null))); when(viewHolder.findViewById(R.id.settingslib_learn_more)).thenReturn(null); Throwable actualThrowable = null; try { mFooterPreference.onBindViewHolder(viewHolder); } catch (Throwable throwable) { actualThrowable = throwable; } assertThat(actualThrowable).isNull(); } @Test public void onBindViewHolder_whenIconFrameIsNull_shouldNotRaiseNpe() { PreferenceViewHolder viewHolder = spy(PreferenceViewHolder.createInstanceForTests( LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null))); when(viewHolder.findViewById(R.id.icon_frame)).thenReturn(null); Throwable actualThrowable = null; try { mFooterPreference.onBindViewHolder(viewHolder); } catch (Throwable throwable) { actualThrowable = throwable; } assertThat(actualThrowable).isNull(); } }