OSDN Git Service

Modify test cases according to change in remove preference behavior.
authorDoris Ling <dling@google.com>
Fri, 17 Feb 2017 00:35:26 +0000 (16:35 -0800)
committerDoris Ling <dling@google.com>
Fri, 17 Feb 2017 00:45:27 +0000 (16:45 -0800)
Bug: 35365702
Test: make RunSettingsRoboTests
Change-Id: I541f4bd946116c766a90da955c11933a5499fa93

14 files changed:
tests/robotests/src/com/android/settings/accounts/AddUserWhenLockedPreferenceControllerTest.java
tests/robotests/src/com/android/settings/accounts/AutoSyncDataPreferenceControllerTest.java
tests/robotests/src/com/android/settings/accounts/AutoSyncPersonalDataPreferenceControllerTest.java
tests/robotests/src/com/android/settings/accounts/EmergencyInfoPreferenceControllerTest.java
tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java
tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerTest.java
tests/robotests/src/com/android/settings/deviceinfo/ManageStoragePreferenceControllerTest.java
tests/robotests/src/com/android/settings/deviceinfo/SerialNumberPreferenceControllerTest.java
tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
tests/robotests/src/com/android/settings/gestures/GesturePreferenceControllerTest.java
tests/robotests/src/com/android/settings/language/TtsPreferenceControllerTest.java
tests/robotests/src/com/android/settings/location/AppLocationPermissionPreferenceControllerTest.java
tests/robotests/src/com/android/settings/notification/PulseNotificationPreferenceControllerTest.java
tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java

index f49bb5f..755212d 100644 (file)
@@ -69,6 +69,10 @@ public class AddUserWhenLockedPreferenceControllerTest {
     public void displayPref_NotAdmin_shouldNotDisplay() {
         when(mUserManager.getUserInfo(anyInt())).thenReturn(mUserInfo);
         when(mUserInfo.isAdmin()).thenReturn(false);
+        final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);
 
index 7fb6fd7..f7dd7a3 100644 (file)
@@ -56,6 +56,8 @@ public class AutoSyncDataPreferenceControllerTest {
     private UserManager mUserManager;
     @Mock(answer = RETURNS_DEEP_STUBS)
     private Fragment mFragment;
+    @Mock
+    private Preference mPreference;
 
     private Context mContext;
     private AutoSyncDataPreferenceController mController;
@@ -70,6 +72,9 @@ public class AutoSyncDataPreferenceControllerTest {
         mController = new AutoSyncDataPreferenceController(mContext, mFragment);
         mConfirmSyncFragment = new AutoSyncDataPreferenceController.ConfirmAutoSyncChangeFragment();
         mConfirmSyncFragment.setTargetFragment(mFragment, 0);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(mPreference);
+        when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
     }
 
     @Test
index 54ee658..6ac0eab 100644 (file)
@@ -52,6 +52,8 @@ public class AutoSyncPersonalDataPreferenceControllerTest {
     private UserManager mUserManager;
     @Mock(answer = RETURNS_DEEP_STUBS)
     private Fragment mFragment;
+    @Mock
+    private Preference mPreference;
 
     private Context mContext;
     private AutoSyncPersonalDataPreferenceController mController;
@@ -63,6 +65,9 @@ public class AutoSyncPersonalDataPreferenceControllerTest {
         shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
         mContext = shadowContext.getApplicationContext();
         mController = new AutoSyncPersonalDataPreferenceController(mContext, mFragment);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(mPreference);
+        when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
     }
 
     @Test
index d31c0f6..10bb283 100644 (file)
@@ -99,6 +99,10 @@ public class EmergencyInfoPreferenceControllerTest {
         when(mContext.getPackageManager().queryIntentActivities(
                 any(Intent.class), anyInt()))
                 .thenReturn(null);
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);
 
index 4ca6609..902fb15 100644 (file)
@@ -80,6 +80,8 @@ public class BugReportInPowerPreferenceControllerTest {
     @Test
     public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
         when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(mPreference);
 
         mController.displayPreference(mScreen);
 
index 377b467..35ca5f8 100644 (file)
@@ -68,6 +68,9 @@ public class BugReportPreferenceControllerTest {
     @Test
     public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
         when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(mPreference);
+        when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);
 
index 12b3218..14c6d72 100644 (file)
@@ -34,6 +34,7 @@ import org.robolectric.annotation.Config;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
 import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -88,7 +89,12 @@ public class ManageStoragePreferenceControllerTest {
     }
 
     @Test
-    public void displayPref_prefAvaiable_shouldNotDisplay() {
+    public void displayPref_prefNotAvaiable_shouldNotDisplay() {
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
+
         mController.displayPreference(mScreen);
 
         verify(mScreen).removePreference(any(Preference.class));
index 1b87e6c..bf9c412 100644 (file)
@@ -71,9 +71,12 @@ public class SerialNumberPreferenceControllerTest {
 
     @Test
     public void testDisplay_noSerial_shouldHidePreference() {
-        when(mScreen.findPreference(anyString())).thenReturn(mock(Preference.class));
-
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
         mController = new SerialNumberPreferenceController(mContext, null);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
+
         mController.displayPreference(mScreen);
 
         verify(mScreen).removePreference(any(Preference.class));
index 9ca218c..b35c60a 100644 (file)
@@ -34,6 +34,7 @@ import org.robolectric.annotation.Config;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
 import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -80,6 +81,11 @@ public class SystemUpdatePreferenceControllerTest {
 
     @Test
     public void displayPrefs_nothingAvailable_shouldNotDisplay() {
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
+
         mController.displayPreference(mScreen);
 
         verify(mScreen).removePreference(any(Preference.class));
@@ -87,6 +93,11 @@ public class SystemUpdatePreferenceControllerTest {
 
     @Test
     public void displayPrefs_oneAvailable_shouldDisplayOne() {
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
+
         when(mContext.getResources().getBoolean(
                 R.bool.config_additional_system_update_setting_enable))
                 .thenReturn(true);
index 01c1921..3dc6892 100644 (file)
@@ -73,8 +73,10 @@ public class GesturePreferenceControllerTest {
     @Test
     public void display_configIsFalse_shouldNotDisplay() {
         mController.mIsPrefAvailable = false;
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);
 
@@ -84,7 +86,7 @@ public class GesturePreferenceControllerTest {
     @Test
     public void onStart_shouldStartVideoPreference() {
         final VideoPreference videoPreference = mock(VideoPreference.class);
-        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
+        when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
         mController.mIsPrefAvailable = true;
 
         mController.displayPreference(mScreen);
@@ -96,7 +98,7 @@ public class GesturePreferenceControllerTest {
     @Test
     public void onStop_shouldStopVideoPreference() {
         final VideoPreference videoPreference = mock(VideoPreference.class);
-        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
+        when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
         mController.mIsPrefAvailable = true;
 
         mController.displayPreference(mScreen);
@@ -163,12 +165,12 @@ public class GesturePreferenceControllerTest {
 
         @Override
         public String getPreferenceKey() {
-            return null;
+            return "testKey";
         }
 
         @Override
         protected String getVideoPrefKey() {
-            return null;
+            return "videoKey";
         }
 
         @Override
index 0e41784..31a3f07 100644 (file)
@@ -84,7 +84,13 @@ public class TtsPreferenceControllerTest {
 
     @Test
     public void displayPreference_notAvailable_shouldRemoveCategory() {
-        when(mScreen.findPreference(anyString())).thenReturn(mock(Preference.class));
+        final Preference preference = mock(Preference.class);
+        final Preference category = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(2);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(mScreen.getPreference(1)).thenReturn(category);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
+        when(category.getKey()).thenReturn("voice_category");
 
         mController.displayPreference(mScreen);
 
index 8a035e5..c7f76df 100644 (file)
@@ -50,6 +50,9 @@ public class AppLocationPermissionPreferenceControllerTest {
         Settings.System.putInt(mContext.getContentResolver(),
                 android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
                 0);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(mPreference);
+        when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);
 
index 4eb33e9..f6c6bf2 100644 (file)
@@ -73,8 +73,10 @@ public class PulseNotificationPreferenceControllerTest {
         when(mContext.getResources().
                 getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed))
                 .thenReturn(false);
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);
 
index 3c3f212..3bc1ffa 100644 (file)
@@ -75,8 +75,10 @@ public class VibrateWhenRingPreferenceControllerTest {
     @Test
     public void display_notVoiceCapable_shouldNotDisplay() {
         when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
-        when(mScreen.findPreference(mController.getPreferenceKey()))
-                .thenReturn(mock(Preference.class));
+        final Preference preference = mock(Preference.class);
+        when(mScreen.getPreferenceCount()).thenReturn(1);
+        when(mScreen.getPreference(0)).thenReturn(preference);
+        when(preference.getKey()).thenReturn(mController.getPreferenceKey());
 
         mController.displayPreference(mScreen);