Rewrite EmergencyListPreferenceTest as unit/robolectric tests. am: 5290685a0e
am: 0836812f36

Change-Id: I9c7722a7dc12950a52e58332939cc0575794e5b4
diff --git a/tests/instrumentation/Android.mk b/tests/instrumentation/Android.mk
deleted file mode 100644
index cce8e7c..0000000
--- a/tests/instrumentation/Android.mk
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2016 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.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    truth-prebuilt \
-    legacy-android-test \
-    junit \
-    emergencyinfo-test-common
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := EmergencyInfoTests
-LOCAL_COMPATIBILITY_SUITE := device-tests
-LOCAL_CERTIFICATE := platform
-
-LOCAL_INSTRUMENTATION_FOR := EmergencyInfo
-
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_PACKAGE)
diff --git a/tests/instrumentation/AndroidManifest.xml b/tests/instrumentation/AndroidManifest.xml
deleted file mode 100644
index 78017a0..0000000
--- a/tests/instrumentation/AndroidManifest.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.emergency.tests"
-    android:sharedUserId="com.android.emergency.uid">
-    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
-    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
-    <uses-permission android:name="android.permission.READ_CONTACTS" />
-    <uses-permission android:name="android.permission.WAKE_LOCK" />
-
-    <application>
-        <uses-library android:name="android.test.runner" />
-    </application>
-
-    <instrumentation android:name="android.test.InstrumentationTestRunner"
-        android:targetPackage="com.android.emergency"
-        android:label="Tests for EmergencyInfo">
-    </instrumentation>
-</manifest>
diff --git a/tests/instrumentation/AndroidTest.xml b/tests/instrumentation/AndroidTest.xml
deleted file mode 100644
index 11d26f8..0000000
--- a/tests/instrumentation/AndroidTest.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-<configuration description="Run Tests for EmergencyInfo.">
-    <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
-        <option name="test-file-name" value="EmergencyInfoTests.apk" />
-    </target_preparer>
-
-    <option name="test-suite-tag" value="apct" />
-    <option name="test-tag" value="EmergencyInfoTests" />
-    <test class="com.android.tradefed.testtype.InstrumentationTest" >
-        <option name="package" value="com.android.emergency.tests" />
-        <option name="runner" value="android.test.InstrumentationTestRunner" />
-    </test>
-</configuration>
diff --git a/tests/instrumentation/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java b/tests/instrumentation/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java
deleted file mode 100644
index cc970f0..0000000
--- a/tests/instrumentation/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2016 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 android.preference.PreferenceManager;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.text.SpannableString;
-import android.text.TextUtils;
-import android.text.style.TtsSpan;
-
-import com.android.emergency.PreferenceKeys;
-import com.android.emergency.R;
-import com.android.emergency.edit.EditMedicalInfoActivity;
-import com.android.emergency.edit.EditMedicalInfoFragment;
-
-/**
- * Tests for {@link EmergencyListPreference}.
- */
-@LargeTest
-public class EmergencyListPreferenceTest
-        extends ActivityInstrumentationTestCase2<EditMedicalInfoActivity> {
-    private EmergencyListPreference mOrganDonorPreference;
-    private EmergencyListPreference mBloodTypeListPreference;
-    private EditMedicalInfoFragment mEditInfoFragment;
-
-    public EmergencyListPreferenceTest() {
-        super(EditMedicalInfoActivity.class);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mEditInfoFragment = getActivity().getFragment();
-        mOrganDonorPreference = (EmergencyListPreference)
-                mEditInfoFragment.findPreference(PreferenceKeys.KEY_ORGAN_DONOR);
-        mBloodTypeListPreference = (EmergencyListPreference)
-                mEditInfoFragment.findPreference(PreferenceKeys.KEY_BLOOD_TYPE);
-        try {
-            runTestOnUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    mOrganDonorPreference.setValue("");
-                    mBloodTypeListPreference.setValue("");
-                }
-            });
-        } catch (Throwable throwable) {
-            fail("Should not throw exception: " + throwable.getMessage());
-        }
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().clear().commit();
-        super.tearDown();
-    }
-
-    public void testSummary_organDonor() {
-        String summary = (String) mOrganDonorPreference.getSummary();
-        String summaryExp =
-                getActivity().getResources().getString(R.string.unknown_organ_donor);
-        assertThat(summary).isEqualTo(summaryExp);
-    }
-
-    public void testSummary_bloodType() {
-        String summary = mBloodTypeListPreference.getSummary().toString();
-        CharSequence summaryExp =
-                getActivity().getResources().getString(R.string.unknown_blood_type);
-        assertThat(summary).isEqualTo(summaryExp);
-    }
-
-    public void testTitle_organDonor() {
-        String title = (String) mOrganDonorPreference.getTitle();
-        String titleExp =
-                getActivity().getResources().getString(R.string.organ_donor);
-        assertThat(title).isEqualTo(titleExp);
-    }
-
-    public void testTitle_bloodType() {
-        String title = (String) mBloodTypeListPreference.getTitle();
-        String titleExp =
-                getActivity().getResources().getString(R.string.blood_type);
-        assertThat(title).isEqualTo(titleExp);
-    }
-
-    public void testProperties_organDonor() {
-        assertThat(mOrganDonorPreference).isNotNull();
-        assertThat(mOrganDonorPreference.getKey()).isEqualTo(PreferenceKeys.KEY_ORGAN_DONOR);
-        assertThat(mOrganDonorPreference.isEnabled()).isTrue();
-        assertThat(mOrganDonorPreference.isPersistent()).isTrue();
-        assertThat(mOrganDonorPreference.isSelectable()).isTrue();
-        assertThat(mOrganDonorPreference.isNotSet()).isTrue();
-        assertThat(mOrganDonorPreference.getValue()).isEqualTo("");
-        assertThat(mOrganDonorPreference.getEntries().length).isEqualTo(
-            mOrganDonorPreference.getEntryValues().length);
-        assertNull(mOrganDonorPreference.getContentDescriptions());
-    }
-
-    public void testProperties_bloodType() {
-        assertThat(mBloodTypeListPreference).isNotNull();
-        assertThat(mBloodTypeListPreference.getKey()).isEqualTo(PreferenceKeys.KEY_BLOOD_TYPE);
-        assertThat(mBloodTypeListPreference.isEnabled()).isTrue();
-        assertThat(mBloodTypeListPreference.isPersistent()).isTrue();
-        assertThat(mBloodTypeListPreference.isSelectable()).isTrue();
-        assertThat(mBloodTypeListPreference.isNotSet()).isTrue();
-        assertThat(mBloodTypeListPreference.getValue()).isEqualTo("");
-        assertThat(mBloodTypeListPreference.getEntries().length).isEqualTo(
-                mBloodTypeListPreference.getEntryValues().length);
-        assertThat(mBloodTypeListPreference.getContentDescriptions().length).isEqualTo(
-                mBloodTypeListPreference.getEntries().length);
-    }
-
-    public void testReloadFromPreference() throws Throwable {
-        mEditInfoFragment.getPreferenceManager().getSharedPreferences()
-                .edit()
-                .putString(mOrganDonorPreference.getKey(),
-                        (String) mOrganDonorPreference.getEntryValues()[0])
-                .commit();
-        runTestOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mOrganDonorPreference.reloadFromPreference();
-            }
-        });
-        assertThat(mOrganDonorPreference.getValue()).isEqualTo(
-                mOrganDonorPreference.getEntryValues()[0]);
-        assertThat(mOrganDonorPreference.isNotSet()).isFalse();
-    }
-
-    public void testSetValue() throws Throwable {
-        for (int i = 0; i < mOrganDonorPreference.getEntryValues().length; i++) {
-            final int index = i;
-            runTestOnUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    mOrganDonorPreference.setValue((String)
-                            mOrganDonorPreference.getEntryValues()[index]);
-                }
-            });
-
-            assertThat(mOrganDonorPreference.getValue()).isEqualTo(
-                    mOrganDonorPreference.getEntryValues()[index]);
-            if (!TextUtils.isEmpty(mOrganDonorPreference.getEntryValues()[index])) {
-                assertThat(mOrganDonorPreference.getSummary()).isEqualTo(
-                        mOrganDonorPreference.getEntries()[index]);
-            } else {
-                assertThat(mOrganDonorPreference.getSummary()).isEqualTo(
-                        getActivity().getResources().getString(R.string.unknown_organ_donor));
-            }
-        }
-    }
-
-    public void testContentDescriptions() {
-        for (int i = 0; i < mBloodTypeListPreference.getEntries().length; i++) {
-            SpannableString entry = ((SpannableString) mBloodTypeListPreference.getEntries()[i]);
-            TtsSpan[] span = entry.getSpans(0,
-                    mBloodTypeListPreference.getContentDescriptions().length, TtsSpan.class);
-            assertThat(span.length).isEqualTo(1);
-            assertThat(mBloodTypeListPreference.getContentDescriptions()[i]).isEqualTo(
-                    span[0].getArgs().get(TtsSpan.ARG_TEXT));
-        }
-    }
-}
diff --git a/tests/robolectric/src/com/android/emergency/preferences/EmergencyEditTextPreferenceTest.java b/tests/robolectric/src/com/android/emergency/preferences/EmergencyEditTextPreferenceTest.java
index 56f99f2..57d4642 100644
--- a/tests/robolectric/src/com/android/emergency/preferences/EmergencyEditTextPreferenceTest.java
+++ b/tests/robolectric/src/com/android/emergency/preferences/EmergencyEditTextPreferenceTest.java
@@ -29,7 +29,6 @@
 import android.test.suitebuilder.annotation.SmallTest;
 
 import com.android.emergency.PreferenceKeys;
-import com.android.emergency.R;
 import com.android.emergency.TestConfig;
 
 import org.junit.Before;
diff --git a/tests/robolectric/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java b/tests/robolectric/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java
new file mode 100644
index 0000000..94b631d
--- /dev/null
+++ b/tests/robolectric/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceGroup;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
+
+import com.android.emergency.PreferenceKeys;
+import com.android.emergency.R;
+import com.android.emergency.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+/** Unit tests for {@link EmergencyListPreference}. */
+@SmallTest
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class EmergencyListPreferenceTest {
+    @Mock private PreferenceManager mPreferenceManager;
+    @Mock private SharedPreferences mSharedPreferences;
+    private EmergencyListPreference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        when(mPreferenceManager.getSharedPreferences()).thenReturn(mSharedPreferences);
+
+        Context context = RuntimeEnvironment.application;
+
+        mPreference = spy(
+                new EmergencyListPreference(RuntimeEnvironment.application, null /* attrs */));
+
+        PreferenceGroup prefRoot = spy(new PreferenceScreen(context, null /* attrs */));
+        when(prefRoot.getPreferenceManager()).thenReturn(mPreferenceManager);
+        prefRoot.addPreference(mPreference);
+    }
+
+    @Test
+    public void testReloadFromPreference() {
+        CharSequence[] organDonorValues =
+                RuntimeEnvironment.application.getResources().getStringArray(
+                        R.array.organ_donor_entries);
+        when(mSharedPreferences.getString(eq(PreferenceKeys.KEY_ORGAN_DONOR), anyString()))
+                .thenReturn((String) organDonorValues[0]);
+
+        mPreference.setKey(PreferenceKeys.KEY_ORGAN_DONOR);
+        mPreference.setEntryValues(organDonorValues);
+
+        mPreference.reloadFromPreference();
+        assertThat(mPreference.getValue()).isEqualTo(mPreference.getEntryValues()[0]);
+        assertThat(mPreference.isNotSet()).isFalse();
+    }
+
+    @Test
+    public void testSetValue() {
+        CharSequence[] organDonorEntries =
+                RuntimeEnvironment.application.getResources().getStringArray(
+                        R.array.organ_donor_entries);
+        CharSequence[] organDonorValues =
+                RuntimeEnvironment.application.getResources().getStringArray(
+                        R.array.organ_donor_values);
+        mPreference.setKey(PreferenceKeys.KEY_ORGAN_DONOR);
+        mPreference.setEntries(organDonorEntries);
+        mPreference.setEntryValues(organDonorValues);
+        when(mSharedPreferences.getString(eq(PreferenceKeys.KEY_ORGAN_DONOR), anyString()))
+                .thenAnswer(new CyclingStringArrayAnswer(organDonorValues));
+
+        for (int i = 0; i < mPreference.getEntryValues().length; i++) {
+            mPreference.setValue((String) mPreference.getEntryValues()[i]);
+
+            assertThat(mPreference.getValue()).isEqualTo(mPreference.getEntryValues()[i]);
+            if (!TextUtils.isEmpty(mPreference.getEntryValues()[i])) {
+                assertThat(mPreference.getSummary()).isEqualTo(mPreference.getEntries()[i]);
+            } else {
+                assertThat(mPreference.getSummary()).isEqualTo(
+                        RuntimeEnvironment.application.getResources().getString(
+                                R.string.unknown_organ_donor));
+            }
+        }
+    }
+
+    /** An Answer that cycles through a list of string values in its answer. */
+    private static class CyclingStringArrayAnswer implements Answer<String> {
+        private CharSequence[] mValues;
+        private int mIndex;
+
+        public CyclingStringArrayAnswer(CharSequence[] values) {
+            mValues = values;
+            mIndex = 0;
+        }
+
+        @Override
+        public String answer(InvocationOnMock invocation) {
+            String value = (String) mValues[mIndex % mValues.length];
+            mIndex++;
+            return value;
+        }
+    }
+}
diff --git a/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java b/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java
index ffe0b9f..aec3ced 100644
--- a/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java
+++ b/tests/robolectric/src/com/android/emergency/preferences/NameAutoCompletePreferenceTest.java
@@ -30,7 +30,6 @@
 import android.widget.AutoCompleteTextView;
 
 import com.android.emergency.PreferenceKeys;
-import com.android.emergency.R;
 import com.android.emergency.TestConfig;
 
 import org.junit.Before;
diff --git a/tests/unit/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java b/tests/unit/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java
new file mode 100644
index 0000000..bd35342
--- /dev/null
+++ b/tests/unit/src/com/android/emergency/preferences/EmergencyListPreferenceTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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 android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.preference.PreferenceManager;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.text.SpannableString;
+import android.text.style.TtsSpan;
+
+import com.android.emergency.PreferenceKeys;
+import com.android.emergency.R;
+import com.android.emergency.edit.EditInfoActivity;
+import com.android.emergency.edit.EditInfoFragment;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/** Unit tests for {@link EmergencyListPreference}. */
+@RunWith(AndroidJUnit4.class)
+public final class EmergencyListPreferenceTest {
+    private Instrumentation mInstrumentation;
+    private Context mTargetContext;
+
+    @Before
+    public void setUp() {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mTargetContext = mInstrumentation.getTargetContext();
+        PreferenceManager.getDefaultSharedPreferences(mTargetContext).edit().clear().commit();
+    }
+
+    @After
+    public void tearDown() {
+        PreferenceManager.getDefaultSharedPreferences(mTargetContext).edit().clear().commit();
+    }
+
+    @Test
+    public void testSummary_organDonor() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_ORGAN_DONOR);
+        String summary = (String) preference.getSummary();
+        String summaryExp =
+                mTargetContext.getResources().getString(R.string.unknown_organ_donor);
+        assertThat(summary).isEqualTo(summaryExp);
+    }
+
+    @Test
+    public void testSummary_bloodType() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_BLOOD_TYPE);
+        String summary = preference.getSummary().toString();
+        CharSequence summaryExp =
+                mTargetContext.getResources().getString(R.string.unknown_blood_type);
+        assertThat(summary).isEqualTo(summaryExp);
+    }
+
+    @Test
+    public void testTitle_organDonor() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_ORGAN_DONOR);
+        String title = (String) preference.getTitle();
+        String titleExp = mTargetContext.getResources().getString(R.string.organ_donor);
+        assertThat(title).isEqualTo(titleExp);
+    }
+
+    @Test
+    public void testTitle_bloodType() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_BLOOD_TYPE);
+        String title = preference.getTitle().toString();
+        CharSequence titleExp = mTargetContext.getResources().getString(R.string.blood_type);
+        assertThat(title).isEqualTo(titleExp);
+    }
+
+    @Test
+    public void testProperties_organDonor() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_ORGAN_DONOR);
+        assertThat(preference).isNotNull();
+        assertThat(preference.getKey()).isEqualTo(PreferenceKeys.KEY_ORGAN_DONOR);
+        assertThat(preference.isPersistent()).isTrue();
+        assertThat(preference.isNotSet()).isTrue();
+        assertThat(preference.getValue()).isEqualTo("");
+        assertThat(preference.getEntries().length).isEqualTo(preference.getEntryValues().length);
+        assertThat(preference.getContentDescriptions()).isNull();
+    }
+
+    @Test
+    public void testProperties_bloodType() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_BLOOD_TYPE);
+        assertThat(preference).isNotNull();
+        assertThat(preference.getKey()).isEqualTo(PreferenceKeys.KEY_BLOOD_TYPE);
+        assertThat(preference.isPersistent()).isTrue();
+        assertThat(preference.isNotSet()).isTrue();
+        assertThat(preference.getValue()).isEqualTo("");
+        assertThat(preference.getEntries().length).isEqualTo(preference.getEntryValues().length);
+        assertThat(preference.getContentDescriptions().length).isEqualTo(
+                preference.getEntries().length);
+    }
+
+    @Test
+    public void testContentDescriptions() {
+        EditInfoActivity activity = startEditInfoActivity();
+        EditInfoFragment fragment = (EditInfoFragment) activity.getFragment();
+        EmergencyListPreference preference =
+                getEmergencyListPreference(fragment, PreferenceKeys.KEY_BLOOD_TYPE);
+        for (int i = 0; i < preference.getEntries().length; i++) {
+            SpannableString entry = ((SpannableString) preference.getEntries()[i]);
+            TtsSpan[] span = entry.getSpans(0,
+                    preference.getContentDescriptions().length, TtsSpan.class);
+            assertThat(span.length).isEqualTo(1);
+            assertThat(preference.getContentDescriptions()[i]).isEqualTo(
+                    span[0].getArgs().get(TtsSpan.ARG_TEXT));
+        }
+    }
+
+    private EditInfoActivity startEditInfoActivity() {
+        final Intent editActivityIntent = new Intent(mTargetContext, EditInfoActivity.class);
+        return (EditInfoActivity) mInstrumentation.startActivitySync(editActivityIntent);
+    }
+
+    private EmergencyListPreference getEmergencyListPreference(
+            EditInfoFragment fragment, String key) {
+        return (EmergencyListPreference) fragment.getMedicalInfoPreference(key);
+    }
+}