Loading src/com/android/settings/widget/UpdatableListPreferenceDialogFragment.java +3 −2 Original line number Diff line number Diff line Loading @@ -84,8 +84,8 @@ public class UpdatableListPreferenceDialogFragment extends PreferenceDialogFragm @Override public void onDialogClosed(boolean positiveResult) { final ListPreference preference = getListPreference(); if (positiveResult && mClickedDialogEntryIndex >= 0) { final ListPreference preference = getListPreference(); final String value = mEntryValues[mClickedDialogEntryIndex].toString(); if (preference.callChangeListener(value)) { preference.setValue(value); Loading Loading @@ -144,7 +144,8 @@ public class UpdatableListPreferenceDialogFragment extends PreferenceDialogFragm return mMetricsCategory; } private ListPreference getListPreference() { @VisibleForTesting ListPreference getListPreference() { return (ListPreference) getPreference(); } Loading tests/robotests/src/com/android/settings/widget/UpdatableListPreferenceDialogFragmentTest.java +15 −4 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.settings.widget; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import android.content.Context; import android.widget.ArrayAdapter; Loading @@ -31,6 +33,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; Loading @@ -42,9 +45,10 @@ import java.util.ArrayList; @Config(shadows = ShadowBluetoothUtils.class) public class UpdatableListPreferenceDialogFragmentTest { private Context mContext; private UpdatableListPreferenceDialogFragment mUpdatableListPrefDlgFragment; private static final String KEY = "Test_Key"; @Mock private UpdatableListPreferenceDialogFragment mUpdatableListPrefDlgFragment; private Context mContext; private ArrayAdapter mAdapter; private ArrayList<CharSequence> mEntries; Loading @@ -53,8 +57,8 @@ public class UpdatableListPreferenceDialogFragmentTest { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mUpdatableListPrefDlgFragment = UpdatableListPreferenceDialogFragment .newInstance(KEY, MetricsProto.MetricsEvent.DIALOG_SWITCH_A2DP_DEVICES); mUpdatableListPrefDlgFragment = spy(UpdatableListPreferenceDialogFragment .newInstance(KEY, MetricsProto.MetricsEvent.DIALOG_SWITCH_A2DP_DEVICES)); mEntries = spy(new ArrayList<>()); mUpdatableListPrefDlgFragment.setEntries(mEntries); mUpdatableListPrefDlgFragment. Loading Loading @@ -87,4 +91,11 @@ public class UpdatableListPreferenceDialogFragmentTest { assertThat(mUpdatableListPrefDlgFragment.getAdapter().getCount()).isEqualTo(2); } @Test public void onDialogClosed_emptyPreference() { mUpdatableListPrefDlgFragment.onDialogClosed(false); verify(mUpdatableListPrefDlgFragment, never()).getListPreference(); } } No newline at end of file Loading
src/com/android/settings/widget/UpdatableListPreferenceDialogFragment.java +3 −2 Original line number Diff line number Diff line Loading @@ -84,8 +84,8 @@ public class UpdatableListPreferenceDialogFragment extends PreferenceDialogFragm @Override public void onDialogClosed(boolean positiveResult) { final ListPreference preference = getListPreference(); if (positiveResult && mClickedDialogEntryIndex >= 0) { final ListPreference preference = getListPreference(); final String value = mEntryValues[mClickedDialogEntryIndex].toString(); if (preference.callChangeListener(value)) { preference.setValue(value); Loading Loading @@ -144,7 +144,8 @@ public class UpdatableListPreferenceDialogFragment extends PreferenceDialogFragm return mMetricsCategory; } private ListPreference getListPreference() { @VisibleForTesting ListPreference getListPreference() { return (ListPreference) getPreference(); } Loading
tests/robotests/src/com/android/settings/widget/UpdatableListPreferenceDialogFragmentTest.java +15 −4 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.settings.widget; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import android.content.Context; import android.widget.ArrayAdapter; Loading @@ -31,6 +33,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; Loading @@ -42,9 +45,10 @@ import java.util.ArrayList; @Config(shadows = ShadowBluetoothUtils.class) public class UpdatableListPreferenceDialogFragmentTest { private Context mContext; private UpdatableListPreferenceDialogFragment mUpdatableListPrefDlgFragment; private static final String KEY = "Test_Key"; @Mock private UpdatableListPreferenceDialogFragment mUpdatableListPrefDlgFragment; private Context mContext; private ArrayAdapter mAdapter; private ArrayList<CharSequence> mEntries; Loading @@ -53,8 +57,8 @@ public class UpdatableListPreferenceDialogFragmentTest { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mUpdatableListPrefDlgFragment = UpdatableListPreferenceDialogFragment .newInstance(KEY, MetricsProto.MetricsEvent.DIALOG_SWITCH_A2DP_DEVICES); mUpdatableListPrefDlgFragment = spy(UpdatableListPreferenceDialogFragment .newInstance(KEY, MetricsProto.MetricsEvent.DIALOG_SWITCH_A2DP_DEVICES)); mEntries = spy(new ArrayList<>()); mUpdatableListPrefDlgFragment.setEntries(mEntries); mUpdatableListPrefDlgFragment. Loading Loading @@ -87,4 +91,11 @@ public class UpdatableListPreferenceDialogFragmentTest { assertThat(mUpdatableListPrefDlgFragment.getAdapter().getCount()).isEqualTo(2); } @Test public void onDialogClosed_emptyPreference() { mUpdatableListPrefDlgFragment.onDialogClosed(false); verify(mUpdatableListPrefDlgFragment, never()).getListPreference(); } } No newline at end of file