diff options
author | Wesley.CW Wang <wesleycwwang@google.com> | 2018-09-25 16:09:36 +0800 |
---|---|---|
committer | Wesley.CW Wang <wesleycwwang@google.com> | 2018-10-04 16:15:35 +0800 |
commit | 368f7fdcf53c1646e41ed746061be2b99b106d81 (patch) | |
tree | b1c1617caf85aa24f1991a534b1d334006c59e24 /tests | |
parent | e7772e0bb866a8ae72cdef69f097ffa8164ebeb7 (diff) | |
download | EmergencyInfo-368f7fdcf53c1646e41ed746061be2b99b106d81.tar.gz |
Remove unused file and test case
- Remove AutoCompleteEditTextPreference & NameAutoCompletePreference.
- Remove unused test case.
Test: make RunEmergencyInfoRoboTests
Bug: 111967295
Change-Id: I675c6bd283856f084df90c6f4213fbf20382d6aa
Diffstat (limited to 'tests')
3 files changed, 0 insertions, 223 deletions
diff --git a/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java b/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java deleted file mode 100644 index 29769cfc..00000000 --- a/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.emergency.preferences; - -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.nullable; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.content.SharedPreferences; -import androidx.preference.PreferenceGroup; -import androidx.preference.PreferenceManager; -import androidx.preference.PreferenceScreen; -import android.text.Editable; -import android.view.View; -import android.widget.AutoCompleteTextView; - -import com.android.emergency.PreferenceKeys; - -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; -import org.robolectric.util.ReflectionHelpers; - -/** Unit tests for {@link NameAutoCompletePreference}. */ -@RunWith(RobolectricTestRunner.class) -public class NameAutoCompletePreferenceTest { - @Mock private PreferenceManager mPreferenceManager; - @Mock private SharedPreferences mSharedPreferences; - @Mock private NameAutoCompletePreference.SuggestionProvider mAutoCompleteSuggestionProvider; - private NameAutoCompletePreference mPreference; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - - when(mPreferenceManager.getSharedPreferences()).thenReturn(mSharedPreferences); - - Context context = RuntimeEnvironment.application; - - mPreference = - spy(new NameAutoCompletePreference(context, null, mAutoCompleteSuggestionProvider)); - - PreferenceGroup prefRoot = spy(new PreferenceScreen(context, null)); - when(prefRoot.getPreferenceManager()).thenReturn(mPreferenceManager); - prefRoot.addPreference(mPreference); - } - - @Test - public void testProperties() { - assertThat(mPreference).isNotNull(); - assertThat(mPreference.isEnabled()).isTrue(); - assertThat(mPreference.isPersistent()).isTrue(); - assertThat(mPreference.isSelectable()).isTrue(); - assertThat(mPreference.isNotSet()).isTrue(); - } - - @Test - public void testReloadFromPreference() throws Throwable { - mPreference.setKey(PreferenceKeys.KEY_NAME); - - String name = "John"; - when(mSharedPreferences.getString(eq(mPreference.getKey()), nullable(String.class))) - .thenReturn(name); - - mPreference.reloadFromPreference(); - assertThat(mPreference.getText()).isEqualTo(name); - assertThat(mPreference.isNotSet()).isFalse(); - } - - @Test - public void testSetText() throws Throwable { - final String name = "John"; - mPreference.setText(name); - assertThat(mPreference.getText()).isEqualTo(name); - assertThat(mPreference.getSummary()).isEqualTo(name); - } - - @Test - public void testGetAutoCompleteTextView() { - AutoCompleteTextView autoCompleteTextView = mPreference.getAutoCompleteTextView(); - assertThat(autoCompleteTextView).isNotNull(); - } - - @Test - public void testCreateAutocompleteSuggestions_noNameToSuggest() { - when(mAutoCompleteSuggestionProvider.hasNameToSuggest()).thenReturn(false); - assertThat(mPreference.createAutocompleteSuggestions()).isEqualTo(new String[] {}); - } - - @Test - public void testCreateAutocompleteSuggestions_nameToSuggest() { - final String name = "Jane"; - when(mAutoCompleteSuggestionProvider.hasNameToSuggest()).thenReturn(true); - when(mAutoCompleteSuggestionProvider.getNameSuggestion()).thenReturn(name); - assertThat(mPreference.createAutocompleteSuggestions()).isEqualTo(new String[] {name}); - } - - @Test - public void testBindDialog_shouldFocusOnEditText() { - final AutoCompleteTextView editText = mock(AutoCompleteTextView.class); - final Editable text = mock(Editable.class); - when(editText.getText()).thenReturn(text); - when(text.length()).thenReturn(0); - ReflectionHelpers.setField(mPreference, "mAutoCompleteTextView", editText); - - mPreference.onBindDialogView(mock(View.class)); - - verify(editText).requestFocus(); - } -} diff --git a/tests/unit/src/com/android/emergency/edit/EditInfoActivityTest.java b/tests/unit/src/com/android/emergency/edit/EditInfoActivityTest.java index d266cc33..adbf6479 100644 --- a/tests/unit/src/com/android/emergency/edit/EditInfoActivityTest.java +++ b/tests/unit/src/com/android/emergency/edit/EditInfoActivityTest.java @@ -43,7 +43,6 @@ import com.android.emergency.R; import com.android.emergency.preferences.EmergencyContactsPreference; import com.android.emergency.preferences.EmergencyEditTextPreference; import com.android.emergency.preferences.EmergencyListPreference; -import com.android.emergency.preferences.NameAutoCompletePreference; import com.android.emergency.util.PreferenceUtils; import java.util.ArrayList; @@ -102,8 +101,6 @@ public final class EditInfoActivityTest { @Test public void testClearAllPreferences() { PreferenceManager.getDefaultSharedPreferences(mTargetContext).edit().putString( - PreferenceKeys.KEY_NAME, "John").commit(); - PreferenceManager.getDefaultSharedPreferences(mTargetContext).edit().putString( PreferenceKeys.KEY_ADDRESS, "Home").commit(); PreferenceManager.getDefaultSharedPreferences(mTargetContext).edit().putString( PreferenceKeys.KEY_BLOOD_TYPE, "A+").commit(); @@ -134,9 +131,6 @@ public final class EditInfoActivityTest { EditInfoActivity activity = startEditInfoActivity(); EditInfoFragment fragment = (EditInfoFragment) activity.getFragment(); - final NameAutoCompletePreference namePreference = - (NameAutoCompletePreference) fragment.getMedicalInfoPreference( - PreferenceKeys.KEY_NAME); final EmergencyEditTextPreference addressPreference = (EmergencyEditTextPreference) fragment.getMedicalInfoPreference( PreferenceKeys.KEY_ADDRESS); @@ -159,7 +153,6 @@ public final class EditInfoActivityTest { (EmergencyContactsPreference) fragment.findPreference( PreferenceKeys.KEY_EMERGENCY_CONTACTS); - String unknownName = activity.getResources().getString(R.string.unknown_name); String unknownAddress = activity.getResources().getString(R.string.unknown_address); String unknownBloodType = activity.getResources().getString(R.string.unknown_blood_type); String unknownAllergies = activity.getResources().getString(R.string.unknown_allergies); @@ -168,7 +161,6 @@ public final class EditInfoActivityTest { activity.getResources().getString(R.string.unknown_medical_conditions); String unknownOrganDonor = activity.getResources().getString(R.string.unknown_organ_donor); - assertThat(namePreference.getSummary()).isNotEqualTo(unknownName); assertThat(addressPreference.getSummary()).isNotEqualTo(unknownAddress); assertThat(bloodTypePreference.getSummary()).isNotEqualTo(unknownBloodType); assertThat(allergiesPreference.getSummary()).isNotEqualTo(unknownAllergies); @@ -199,7 +191,6 @@ public final class EditInfoActivityTest { // After the clear all the preferences dialog is confirmed, the preferences values are // reloaded, and the existing object references are updated in-place. - assertThat(namePreference.getSummary()).isNull(); assertThat(addressPreference.getSummary()).isNull(); assertThat(bloodTypePreference.getSummary().toString()).isEqualTo(unknownBloodType); assertThat(allergiesPreference.getSummary()).isNull(); diff --git a/tests/unit/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java b/tests/unit/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java deleted file mode 100644 index c4422be2..00000000 --- a/tests/unit/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.emergency.preferences; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static com.google.common.truth.Truth.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.any; -import static org.hamcrest.Matchers.not; - -import android.app.Instrumentation; -import android.content.Context; -import android.content.Intent; -import android.os.Looper; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; -import android.view.View; - -import com.android.emergency.PreferenceKeys; -import com.android.emergency.R; -import com.android.emergency.edit.EditMedicalInfoActivity; -import com.android.emergency.edit.EditMedicalInfoFragment; - -import org.hamcrest.Matcher; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** Unit tests for {@link NameAutoCompletePreference}. */ -@RunWith(AndroidJUnit4.class) -public final class NameAutoCompletePreferenceTest { - private NameAutoCompletePreference mNameAutoCompletePreference; - - @BeforeClass - public static void oneTimeSetup() { - if (Looper.myLooper() == null) { - Looper.prepare(); - } - } - - @Before - public void setUp() { - Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); - - final Intent editActivityIntent = new Intent( - instrumentation.getTargetContext(), EditMedicalInfoActivity.class); - EditMedicalInfoActivity activity = - (EditMedicalInfoActivity) instrumentation.startActivitySync(editActivityIntent); - EditMedicalInfoFragment fragment = activity.getFragment(); - - mNameAutoCompletePreference = - (NameAutoCompletePreference) fragment.findPreference(PreferenceKeys.KEY_NAME); - } - - @Test - public void testDialogShow() { - onView(withText(R.string.name)).perform(click()); - - onView(withText(android.R.string.ok)) - .check(matches(isDisplayed())); - onView(withText(android.R.string.cancel)) - .check(matches(isDisplayed())); - } -} |