OSDN Git Service

Refactor nfc preference controller
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / nfc / AndroidBeamPreferenceControllerTest.java
index cb18b5a..8232afe 100644 (file)
@@ -41,6 +41,9 @@ import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.util.ReflectionHelpers;
 
+import java.util.ArrayList;
+import java.util.List;
+
 @RunWith(SettingsRobolectricTestRunner.class)
 public class AndroidBeamPreferenceControllerTest {
 
@@ -69,7 +72,8 @@ public class AndroidBeamPreferenceControllerTest {
                 UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(false);
         when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
 
-        mAndroidBeamController = new AndroidBeamPreferenceController(mContext);
+        mAndroidBeamController = new AndroidBeamPreferenceController(mContext,
+                AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
         mAndroidBeamPreference = new RestrictedPreference(RuntimeEnvironment.application);
         when(mScreen.findPreference(mAndroidBeamController.getPreferenceKey())).thenReturn(
                 mAndroidBeamPreference);
@@ -132,4 +136,24 @@ public class AndroidBeamPreferenceControllerTest {
         mAndroidBeamController.onResume();
         assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
     }
+
+    @Test
+    public void updateNonIndexableKeys_available_shouldNotUpdate() {
+        when(mNfcAdapter.isEnabled()).thenReturn(true);
+        final List<String> keys = new ArrayList<>();
+
+        mAndroidBeamController.updateNonIndexableKeys(keys);
+
+        assertThat(keys).isEmpty();
+    }
+
+    @Test
+    public void updateNonIndexableKeys_notAvailable_shouldUpdate() {
+        ReflectionHelpers.setField(mAndroidBeamController, "mNfcAdapter", null);
+        final List<String> keys = new ArrayList<>();
+
+        mAndroidBeamController.updateNonIndexableKeys(keys);
+
+        assertThat(keys).hasSize(1);
+    }
 }