Modify test cases according to change in remove preference behavior.
Bug: 35365702 Test: make RunSettingsRoboTests Change-Id: I541f4bd946116c766a90da955c11933a5499fa93
This commit is contained in:
@@ -69,6 +69,10 @@ public class AddUserWhenLockedPreferenceControllerTest {
|
|||||||
public void displayPref_NotAdmin_shouldNotDisplay() {
|
public void displayPref_NotAdmin_shouldNotDisplay() {
|
||||||
when(mUserManager.getUserInfo(anyInt())).thenReturn(mUserInfo);
|
when(mUserManager.getUserInfo(anyInt())).thenReturn(mUserInfo);
|
||||||
when(mUserInfo.isAdmin()).thenReturn(false);
|
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);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -56,6 +56,8 @@ public class AutoSyncDataPreferenceControllerTest {
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
private Fragment mFragment;
|
private Fragment mFragment;
|
||||||
|
@Mock
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AutoSyncDataPreferenceController mController;
|
private AutoSyncDataPreferenceController mController;
|
||||||
@@ -70,6 +72,9 @@ public class AutoSyncDataPreferenceControllerTest {
|
|||||||
mController = new AutoSyncDataPreferenceController(mContext, mFragment);
|
mController = new AutoSyncDataPreferenceController(mContext, mFragment);
|
||||||
mConfirmSyncFragment = new AutoSyncDataPreferenceController.ConfirmAutoSyncChangeFragment();
|
mConfirmSyncFragment = new AutoSyncDataPreferenceController.ConfirmAutoSyncChangeFragment();
|
||||||
mConfirmSyncFragment.setTargetFragment(mFragment, 0);
|
mConfirmSyncFragment.setTargetFragment(mFragment, 0);
|
||||||
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(mPreference);
|
||||||
|
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -52,6 +52,8 @@ public class AutoSyncPersonalDataPreferenceControllerTest {
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
private Fragment mFragment;
|
private Fragment mFragment;
|
||||||
|
@Mock
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AutoSyncPersonalDataPreferenceController mController;
|
private AutoSyncPersonalDataPreferenceController mController;
|
||||||
@@ -63,6 +65,9 @@ public class AutoSyncPersonalDataPreferenceControllerTest {
|
|||||||
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
|
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
|
||||||
mContext = shadowContext.getApplicationContext();
|
mContext = shadowContext.getApplicationContext();
|
||||||
mController = new AutoSyncPersonalDataPreferenceController(mContext, mFragment);
|
mController = new AutoSyncPersonalDataPreferenceController(mContext, mFragment);
|
||||||
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(mPreference);
|
||||||
|
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -99,6 +99,10 @@ public class EmergencyInfoPreferenceControllerTest {
|
|||||||
when(mContext.getPackageManager().queryIntentActivities(
|
when(mContext.getPackageManager().queryIntentActivities(
|
||||||
any(Intent.class), anyInt()))
|
any(Intent.class), anyInt()))
|
||||||
.thenReturn(null);
|
.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);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -80,6 +80,8 @@ public class BugReportInPowerPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
|
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
|
||||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
||||||
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(mPreference);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -68,6 +68,9 @@ public class BugReportPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
|
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
|
||||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
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);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@ import org.robolectric.annotation.Config;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -88,7 +89,12 @@ public class ManageStoragePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mScreen).removePreference(any(Preference.class));
|
verify(mScreen).removePreference(any(Preference.class));
|
||||||
|
@@ -71,9 +71,12 @@ public class SerialNumberPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplay_noSerial_shouldHidePreference() {
|
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);
|
mController = new SerialNumberPreferenceController(mContext, null);
|
||||||
|
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mScreen).removePreference(any(Preference.class));
|
verify(mScreen).removePreference(any(Preference.class));
|
||||||
|
@@ -34,6 +34,7 @@ import org.robolectric.annotation.Config;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -80,6 +81,11 @@ public class SystemUpdatePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPrefs_nothingAvailable_shouldNotDisplay() {
|
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);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mScreen).removePreference(any(Preference.class));
|
verify(mScreen).removePreference(any(Preference.class));
|
||||||
@@ -87,6 +93,11 @@ public class SystemUpdatePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPrefs_oneAvailable_shouldDisplayOne() {
|
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(
|
when(mContext.getResources().getBoolean(
|
||||||
R.bool.config_additional_system_update_setting_enable))
|
R.bool.config_additional_system_update_setting_enable))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
@@ -73,8 +73,10 @@ public class GesturePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void display_configIsFalse_shouldNotDisplay() {
|
public void display_configIsFalse_shouldNotDisplay() {
|
||||||
mController.mIsPrefAvailable = false;
|
mController.mIsPrefAvailable = false;
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
final Preference preference = mock(Preference.class);
|
||||||
.thenReturn(mock(Preference.class));
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(preference);
|
||||||
|
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ public class GesturePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onStart_shouldStartVideoPreference() {
|
public void onStart_shouldStartVideoPreference() {
|
||||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
|
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||||
mController.mIsPrefAvailable = true;
|
mController.mIsPrefAvailable = true;
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
@@ -96,7 +98,7 @@ public class GesturePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onStop_shouldStopVideoPreference() {
|
public void onStop_shouldStopVideoPreference() {
|
||||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
|
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||||
mController.mIsPrefAvailable = true;
|
mController.mIsPrefAvailable = true;
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
@@ -163,12 +165,12 @@ public class GesturePreferenceControllerTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return null;
|
return "testKey";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getVideoPrefKey() {
|
protected String getVideoPrefKey() {
|
||||||
return null;
|
return "videoKey";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -84,7 +84,13 @@ public class TtsPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_notAvailable_shouldRemoveCategory() {
|
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);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -50,6 +50,9 @@ public class AppLocationPermissionPreferenceControllerTest {
|
|||||||
Settings.System.putInt(mContext.getContentResolver(),
|
Settings.System.putInt(mContext.getContentResolver(),
|
||||||
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
|
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
|
||||||
0);
|
0);
|
||||||
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(mPreference);
|
||||||
|
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -73,8 +73,10 @@ public class PulseNotificationPreferenceControllerTest {
|
|||||||
when(mContext.getResources().
|
when(mContext.getResources().
|
||||||
getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed))
|
getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
final Preference preference = mock(Preference.class);
|
||||||
.thenReturn(mock(Preference.class));
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(preference);
|
||||||
|
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
@@ -75,8 +75,10 @@ public class VibrateWhenRingPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void display_notVoiceCapable_shouldNotDisplay() {
|
public void display_notVoiceCapable_shouldNotDisplay() {
|
||||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
final Preference preference = mock(Preference.class);
|
||||||
.thenReturn(mock(Preference.class));
|
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||||
|
when(mScreen.getPreference(0)).thenReturn(preference);
|
||||||
|
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user