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);
private UserManager mUserManager;
@Mock(answer = RETURNS_DEEP_STUBS)
private Fragment mFragment;
+ @Mock
+ private Preference mPreference;
private Context mContext;
private AutoSyncDataPreferenceController mController;
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
private UserManager mUserManager;
@Mock(answer = RETURNS_DEEP_STUBS)
private Fragment mFragment;
+ @Mock
+ private Preference mPreference;
private Context mContext;
private AutoSyncPersonalDataPreferenceController mController;
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
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);
@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);
@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);
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;
}
@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));
@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));
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;
@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));
@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);
@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);
@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);
@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);
@Override
public String getPreferenceKey() {
- return null;
+ return "testKey";
}
@Override
protected String getVideoPrefKey() {
- return null;
+ return "videoKey";
}
@Override
@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);
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);
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);
@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);