Merge "Modify test cases according to change in remove preference behavior."
This commit is contained in:
committed by
Android (Google) Code Review
commit
c65e3a19a1
@@ -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);
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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));
|
||||
|
@@ -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));
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user