Prepare tests for impending robolectric merge

Some ShadowUserManager function moved into the basic shadow in
robolectric proper and has been removed from the Settings
ShadowUserManager.

Test: make -j56 RunSettingsRoboTests
Change-Id: I38647dae5d16bc79bc7925ca139c9362a2035393
This commit is contained in:
James Lemieux
2018-11-20 14:26:31 -08:00
parent f611fe8689
commit 3a55de44c5
31 changed files with 125 additions and 198 deletions

View File

@@ -94,8 +94,7 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
void finishIfAccountMissing() { void finishIfAccountMissing() {
final Context context = getContext(); final Context context = getContext();
final UserManager um = context.getSystemService(UserManager.class); final UserManager um = context.getSystemService(UserManager.class);
final AccountManager accountManager = (AccountManager) context.getSystemService( final AccountManager accountManager = context.getSystemService(AccountManager.class);
AccountManager.class);
for (UserHandle userHandle : um.getUserProfiles()) { for (UserHandle userHandle : um.getUserProfiles()) {
for (Account account : accountManager.getAccountsAsUser(userHandle.getIdentifier())) { for (Account account : accountManager.getAccountsAsUser(userHandle.getIdentifier())) {
if (account.equals(mAccount)) { if (account.equals(mAccount)) {

View File

@@ -128,7 +128,7 @@ public class ImeiInfoDialogController {
private SubscriptionInfo getSubscriptionInfo(Context context, int slotId) { private SubscriptionInfo getSubscriptionInfo(Context context, int slotId) {
final List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(context) final List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(context)
.getActiveSubscriptionInfoList(); .getActiveSubscriptionInfoList();
if (subscriptionInfoList == null) { if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return null; return null;
} }

View File

@@ -131,7 +131,7 @@ public class DeviceInfoSlice implements CustomSliceable {
SubscriptionInfo getFirstSubscriptionInfo() { SubscriptionInfo getFirstSubscriptionInfo() {
final List<SubscriptionInfo> subscriptionInfoList = final List<SubscriptionInfo> subscriptionInfoList =
mSubscriptionManager.getActiveSubscriptionInfoList(); mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList == null) { if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return null; return null;
} }
return subscriptionInfoList.get(0); return subscriptionInfoList.get(0);

View File

@@ -166,11 +166,11 @@ public class AccessibilityHearingAidPreferenceControllerTest {
mPreferenceController.setPreference(mHearingAidPreference); mPreferenceController.setPreference(mHearingAidPreference);
//not call registerReceiver() //not call registerReceiver()
mPreferenceController.onResume(); mPreferenceController.onResume();
verify(mContext, never()).registerReceiver((BroadcastReceiver) any(), (IntentFilter) any()); verify(mContext, never()).registerReceiver(any(), any());
//not call unregisterReceiver() //not call unregisterReceiver()
mPreferenceController.onPause(); mPreferenceController.onPause();
verify(mContext, never()).unregisterReceiver((BroadcastReceiver) any()); verify(mContext, never()).unregisterReceiver(any());
} }
private void setupBluetoothEnvironment() { private void setupBluetoothEnvironment() {
@@ -185,9 +185,9 @@ public class AccessibilityHearingAidPreferenceControllerTest {
private void setupHearingAidEnvironment() { private void setupHearingAidEnvironment() {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS); mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
mShadowBluetoothAdapter.enable(); mBluetoothAdapter.enable();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME); when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);

View File

@@ -166,11 +166,11 @@ public class AccountDetailDashboardFragmentTest {
public void onResume_accountMissing_shouldFinish() { public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager = Shadow.extract( ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class)); mContext.getSystemService(UserManager.class));
ShadowAccountManager acctMgr = Shadow.extract( ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class)); mContext.getSystemService(AccountManager.class));
userManager.addProfile(new UserInfo(1, null, 0)); userManager.addUserProfile(new UserHandle(1));
acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test")); accountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
mFragment.finishIfAccountMissing(); mFragment.finishIfAccountMissing();
verify(mFragment).finish(); verify(mFragment).finish();
@@ -180,11 +180,11 @@ public class AccountDetailDashboardFragmentTest {
public void onResume_accountPresentOneProfile_shouldNotFinish() { public void onResume_accountPresentOneProfile_shouldNotFinish() {
ShadowUserManager userManager = Shadow.extract( ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class)); mContext.getSystemService(UserManager.class));
ShadowAccountManager acctMgr = Shadow.extract( ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class)); mContext.getSystemService(AccountManager.class));
userManager.addProfile(new UserInfo(1, null, 0)); userManager.addUserProfile(new UserHandle(1));
acctMgr.addAccountForUser(1, mFragment.mAccount); accountManager.addAccountForUser(1, mFragment.mAccount);
mFragment.finishIfAccountMissing(); mFragment.finishIfAccountMissing();
verify(mFragment, never()).finish(); verify(mFragment, never()).finish();
@@ -194,13 +194,13 @@ public class AccountDetailDashboardFragmentTest {
public void onResume_accountPresentTwoProfiles_shouldNotFinish() { public void onResume_accountPresentTwoProfiles_shouldNotFinish() {
ShadowUserManager userManager = Shadow.extract( ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class)); mContext.getSystemService(UserManager.class));
ShadowAccountManager acctMgr = Shadow.extract( ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class)); mContext.getSystemService(AccountManager.class));
userManager.addProfile(new UserInfo(1, null, 0)); userManager.addUserProfile(new UserHandle(1));
userManager.addProfile(new UserInfo(2, null, 0)); userManager.addUserProfile(new UserHandle(2));
acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test")); accountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
acctMgr.addAccountForUser(2, mFragment.mAccount); accountManager.addAccountForUser(2, mFragment.mAccount);
mFragment.finishIfAccountMissing(); mFragment.finishIfAccountMissing();
verify(mFragment, never()).finish(); verify(mFragment, never()).finish();

View File

@@ -141,8 +141,7 @@ public class AvatarViewMixinTest {
@Test @Test
public void callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar() { public void callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar() {
final ShadowContentResolver shadowContentResolver = Shadow.extract( final ContentResolver contentResolver = mContext.getContentResolver();
mContext.getContentResolver());
final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority( final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(
DUMMY_AUTHORITY).build(); DUMMY_AUTHORITY).build();
final ContentProvider mockContentProvider = mock(ContentProvider.class); final ContentProvider mockContentProvider = mock(ContentProvider.class);
@@ -156,8 +155,7 @@ public class AvatarViewMixinTest {
doReturn(bundle).when(mockContentProvider).call(anyString(), anyString(), doReturn(bundle).when(mockContentProvider).call(anyString(), anyString(),
any(Bundle.class)); any(Bundle.class));
final Bundle expectBundle = shadowContentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR, contentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR, null /* arg */, null /* extras */);
null /* arg */, null /* extras */);
final Object object = bundle.getParcelable("account_avatar"); final Object object = bundle.getParcelable("account_avatar");
assertThat(object instanceof Bitmap).isTrue(); assertThat(object instanceof Bitmap).isTrue();

View File

@@ -37,7 +37,6 @@ import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;

View File

@@ -23,7 +23,6 @@ import static org.robolectric.RuntimeEnvironment.application;
import android.app.Activity; import android.app.Activity;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Intent; import android.content.Intent;
import android.content.pm.UserInfo;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@@ -36,8 +35,6 @@ import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.Shadows; import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController; import org.robolectric.android.controller.ActivityController;
@@ -49,20 +46,14 @@ import org.robolectric.shadows.ShadowKeyguardManager;
@Config(shadows = {ShadowLockPatternUtils.class, ShadowUserManager.class}) @Config(shadows = {ShadowLockPatternUtils.class, ShadowUserManager.class})
public class FingerprintSuggestionActivityTest { public class FingerprintSuggestionActivityTest {
@Mock
private UserInfo mUserInfo;
private ActivityController<FingerprintSuggestionActivity> mController; private ActivityController<FingerprintSuggestionActivity> mController;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(); FakeFeatureFactory.setupForTest();
final Intent intent = new Intent(); final Intent intent = new Intent();
mController = Robolectric.buildActivity(FingerprintSuggestionActivity.class, intent); mController = Robolectric.buildActivity(FingerprintSuggestionActivity.class, intent);
ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
} }
@Test @Test

View File

@@ -23,7 +23,6 @@ import static org.robolectric.RuntimeEnvironment.application;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@@ -43,8 +42,6 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.Shadows; import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController; import org.robolectric.android.controller.ActivityController;
@@ -62,15 +59,10 @@ import org.robolectric.shadows.ShadowKeyguardManager;
}) })
public class SetupFingerprintEnrollIntroductionTest { public class SetupFingerprintEnrollIntroductionTest {
@Mock
private UserInfo mUserInfo;
private ActivityController<SetupFingerprintEnrollIntroduction> mController; private ActivityController<SetupFingerprintEnrollIntroduction> mController;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this);
Shadows.shadowOf(application.getPackageManager()) Shadows.shadowOf(application.getPackageManager())
.setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true); .setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);
@@ -78,8 +70,6 @@ public class SetupFingerprintEnrollIntroductionTest {
final Intent intent = new Intent(); final Intent intent = new Intent();
mController = Robolectric.buildActivity(SetupFingerprintEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(SetupFingerprintEnrollIntroduction.class, intent);
ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
} }
@After @After

View File

@@ -15,7 +15,7 @@
*/ */
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -64,7 +64,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
private Context mContext; private Context mContext;
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater; private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> mCachedDevices; private Collection<CachedBluetoothDevice> mCachedDevices;
private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager;
private BluetoothDevicePreference mPreference; private BluetoothDevicePreference mPreference;
private ShadowBluetoothAdapter mShadowBluetoothAdapter; private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager; private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@@ -73,14 +73,13 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mShadowAudioManager = ShadowAudioManager.getShadow(); mContext = RuntimeEnvironment.application;
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true); mShadowBluetoothAdapter.setEnabled(true);
mContext = RuntimeEnvironment.application;
mShadowCachedBluetoothDeviceManager = Shadow.extract( mShadowCachedBluetoothDeviceManager = Shadow.extract(
Utils.getLocalBtManager(mContext).getCachedDeviceManager()); Utils.getLocalBtManager(mContext).getCachedDeviceManager());
mCachedDevices = mCachedDevices = new ArrayList<>();
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices); mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
doReturn(mContext).when(mDashboardFragment).getContext(); doReturn(mContext).when(mDashboardFragment).getContext();
@@ -96,7 +95,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_hfpDeviceConnected_inCall_addPreference() { public void onAudioModeChanged_hfpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -109,7 +108,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_hfpDeviceConnected_notInCall_removePreference() { public void onAudioModeChanged_hfpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -122,7 +121,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_a2dpDeviceConnected_inCall_removePreference() { public void onAudioModeChanged_a2dpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -135,7 +134,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_addPreference() { public void onAudioModeChanged_a2dpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -148,7 +147,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() { public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -161,7 +160,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() { public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -174,7 +173,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() { public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -187,7 +186,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() { public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -201,7 +200,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_addPreference() public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_addPreference()
{ {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
@@ -214,7 +213,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_addPreference() { public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);

View File

@@ -18,8 +18,8 @@ package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -72,8 +72,8 @@ public class BluetoothDeviceRenamePreferenceControllerTest {
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mPreference = new Preference(mContext); mPreference = new Preference(mContext);
mPreference.setKey(PREF_KEY); mPreference.setKey(PREF_KEY);
mBluetoothAdapter = ShadowBluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mController = spy(new BluetoothDeviceRenamePreferenceController(mContext, PREF_KEY)); mController = spy(new BluetoothDeviceRenamePreferenceController(mContext, PREF_KEY));
mController.setFragment(mFragment); mController.setFragment(mFragment);

View File

@@ -66,7 +66,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
private Context mContext; private Context mContext;
private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater; private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> mCachedDevices; private Collection<CachedBluetoothDevice> mCachedDevices;
private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager;
private ShadowBluetoothAdapter mShadowBluetoothAdapter; private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager; private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@@ -74,15 +74,14 @@ public class ConnectedBluetoothDeviceUpdaterTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mShadowAudioManager = ShadowAudioManager.getShadow(); mContext = RuntimeEnvironment.application;
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true); mShadowBluetoothAdapter.setEnabled(true);
mContext = RuntimeEnvironment.application;
mShadowCachedBluetoothDeviceManager = Shadow.extract( mShadowCachedBluetoothDeviceManager = Shadow.extract(
Utils.getLocalBtManager(mContext).getCachedDeviceManager()); Utils.getLocalBtManager(mContext).getCachedDeviceManager());
doReturn(mContext).when(mDashboardFragment).getContext(); doReturn(mContext).when(mDashboardFragment).getContext();
mCachedDevices = mCachedDevices = new ArrayList<>();
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices); mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
@@ -95,7 +94,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() { public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -108,7 +107,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() { public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -121,7 +120,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() { public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -134,7 +133,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() { public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -147,7 +146,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() { public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -160,7 +159,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() { public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -173,7 +172,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() { public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -186,7 +185,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() { public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -200,7 +199,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_removePreference() public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_removePreference()
{ {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
@@ -214,7 +213,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_removePreference public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_removePreference
() { () {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);

View File

@@ -23,6 +23,7 @@ import static org.mockito.Mockito.spy;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.nfc.NfcAdapter;
import android.provider.Settings; import android.provider.Settings;
import com.android.settings.R; import com.android.settings.R;
@@ -60,7 +61,7 @@ public class AdvancedConnectedDeviceControllerTest {
mContentResolver = mContext.getContentResolver(); mContentResolver = mContext.getContentResolver();
mNfcController = new NfcPreferenceController(mContext, mNfcController = new NfcPreferenceController(mContext,
NfcPreferenceController.KEY_TOGGLE_NFC); NfcPreferenceController.KEY_TOGGLE_NFC);
mShadowNfcAdapter = Shadows.shadowOf(ShadowNfcAdapter.getNfcAdapter(mContext)); mShadowNfcAdapter = Shadows.shadowOf(NfcAdapter.getNfcAdapter(mContext));
} }
@Test @Test
@@ -68,8 +69,7 @@ public class AdvancedConnectedDeviceControllerTest {
AdvancedConnectedDeviceController controller = AdvancedConnectedDeviceController controller =
new AdvancedConnectedDeviceController(mContext, KEY); new AdvancedConnectedDeviceController(mContext, KEY);
assertThat(controller.getAvailabilityStatus()).isEqualTo( assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
AVAILABLE);
} }
@Test @Test

View File

@@ -56,10 +56,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = { @Config(shadows = {ShadowAudioManager.class, ShadowBluetoothUtils.class})
ShadowAudioManager.class,
ShadowBluetoothUtils.class}
)
public class AvailableMediaDeviceGroupControllerTest { public class AvailableMediaDeviceGroupControllerTest {
private static final String PREFERENCE_KEY_1 = "pref_key_1"; private static final String PREFERENCE_KEY_1 = "pref_key_1";
@@ -84,7 +81,7 @@ public class AvailableMediaDeviceGroupControllerTest {
private Preference mPreference; private Preference mPreference;
private AvailableMediaDeviceGroupController mAvailableMediaDeviceGroupController; private AvailableMediaDeviceGroupController mAvailableMediaDeviceGroupController;
private LocalBluetoothManager mLocalBluetoothManager; private LocalBluetoothManager mLocalBluetoothManager;
private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager;
@Before @Before
public void setUp() { public void setUp() {
@@ -101,7 +98,7 @@ public class AvailableMediaDeviceGroupControllerTest {
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager; ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext); mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
mShadowAudioManager = ShadowAudioManager.getShadow(); mAudioManager = mContext.getSystemService(AudioManager.class);
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager(); doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
mAvailableMediaDeviceGroupController = new AvailableMediaDeviceGroupController(mContext); mAvailableMediaDeviceGroupController = new AvailableMediaDeviceGroupController(mContext);
@@ -184,7 +181,7 @@ public class AvailableMediaDeviceGroupControllerTest {
@Test @Test
public void setTitle_inCallState_showCallStateTitle() { public void setTitle_inCallState_showCallStateTitle() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAvailableMediaDeviceGroupController.onAudioModeChanged(); mAvailableMediaDeviceGroupController.onAudioModeChanged();
assertThat(mPreferenceGroup.getTitle()).isEqualTo( assertThat(mPreferenceGroup.getTitle()).isEqualTo(
@@ -193,7 +190,7 @@ public class AvailableMediaDeviceGroupControllerTest {
@Test @Test
public void setTitle_notInCallState_showMediaStateTitle() { public void setTitle_notInCallState_showMediaStateTitle() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAvailableMediaDeviceGroupController.onAudioModeChanged(); mAvailableMediaDeviceGroupController.onAudioModeChanged();
assertThat(mPreferenceGroup.getTitle()).isEqualTo( assertThat(mPreferenceGroup.getTitle()).isEqualTo(

View File

@@ -365,6 +365,8 @@ public class DashboardFeatureProviderImplTest {
@Test @Test
public void openTileIntent_profileSelectionDialog_shouldShow() { public void openTileIntent_profileSelectionDialog_shouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>(); final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0)); handles.add(new UserHandle(0));
@@ -379,6 +381,8 @@ public class DashboardFeatureProviderImplTest {
@Test @Test
public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() { public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL); mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>(); final ArrayList<UserHandle> handles = new ArrayList<>();
@@ -394,6 +398,8 @@ public class DashboardFeatureProviderImplTest {
@Test @Test
public void openTileIntent_profileSelectionDialog_shouldNotShow() { public void openTileIntent_profileSelectionDialog_shouldNotShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY); mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>(); final ArrayList<UserHandle> handles = new ArrayList<>();

View File

@@ -16,7 +16,6 @@
package com.android.settings.development; package com.android.settings.development;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -34,7 +33,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
public final class CbrsDataSwitchPreferenceControllerTest { public final class CbrsDataSwitchPreferenceControllerTest {

View File

@@ -41,6 +41,7 @@ import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -82,6 +83,7 @@ public class DevelopmentTilePreferenceControllerTest {
} }
@Test @Test
@Ignore("b/119829673")
public void display_hasTileService_shouldDisplay() { public void display_hasTileService_shouldDisplay() {
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE) final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE)
.setPackage(mContext.getPackageName()); .setPackage(mContext.getPackageName());

View File

@@ -155,6 +155,7 @@ public class ActionDisabledByAdminDialogHelperTest {
dpmShadow.setShortSupportMessageForUser(component, 123, "some message"); dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
dpmShadow.setIsAdminActiveAsUser(true); dpmShadow.setIsAdminActiveAsUser(true);
userManagerShadow.addProfile(new UserInfo(123, null, 0)); userManagerShadow.addProfile(new UserInfo(123, null, 0));
userManagerShadow.addUserProfile(new UserHandle(123));
ShadowProcess.setMyUid(Process.SYSTEM_UID); ShadowProcess.setMyUid(Process.SYSTEM_UID);
mHelper.setAdminSupportDetails(mActivity, view, admin); mHelper.setAdminSupportDetails(mActivity, view, admin);

View File

@@ -19,8 +19,8 @@ package com.android.settings.fuelgauge.batterytip;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@@ -45,9 +45,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -85,9 +83,8 @@ public class AnomalyCleanupJobServiceTest {
public void scheduleCleanUp() { public void scheduleCleanUp() {
AnomalyCleanupJobService.scheduleCleanUp(mContext); AnomalyCleanupJobService.scheduleCleanUp(mContext);
ShadowJobScheduler shadowJobScheduler = JobScheduler jobScheduler = mContext.getSystemService(JobScheduler.class);
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class)); List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size()); assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0); JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_clean_up); assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_clean_up);

View File

@@ -45,8 +45,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -82,9 +80,8 @@ public class AnomalyConfigJobServiceTest {
public void testScheduleConfigUpdate() { public void testScheduleConfigUpdate() {
AnomalyConfigJobService.scheduleConfigUpdate(mContext); AnomalyConfigJobService.scheduleConfigUpdate(mContext);
ShadowJobScheduler shadowJobScheduler = JobScheduler jobScheduler = mContext.getSystemService(JobScheduler.class);
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class)); List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size()); assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0); JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_config_update); assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_config_update);

View File

@@ -22,12 +22,12 @@ import static android.os.StatsDimensionsValue.TUPLE_VALUE_TYPE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
@@ -67,10 +67,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.android.controller.ServiceController; import org.robolectric.android.controller.ServiceController;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -129,9 +127,8 @@ public class AnomalyDetectionJobServiceTest {
public void scheduleCleanUp() { public void scheduleCleanUp() {
AnomalyDetectionJobService.scheduleAnomalyDetection(application, new Intent()); AnomalyDetectionJobService.scheduleAnomalyDetection(application, new Intent());
ShadowJobScheduler shadowJobScheduler = JobScheduler jobScheduler = application.getSystemService(JobScheduler.class);
Shadows.shadowOf(application.getSystemService(JobScheduler.class)); List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
assertThat(pendingJobs).hasSize(1); assertThat(pendingJobs).hasSize(1);
JobInfo pendingJob = pendingJobs.get(0); JobInfo pendingJob = pendingJobs.get(0);

View File

@@ -79,8 +79,8 @@ public class Enhanced4gLtePreferenceControllerTest {
mPreference = new RestrictedSwitchPreference(mContext); mPreference = new RestrictedSwitchPreference(mContext);
mController = new Enhanced4gLtePreferenceController(mContext, "roaming"); mController = new Enhanced4gLtePreferenceController(mContext, "roaming");
mController.mImsManager = mImsManager;
mController.init(SUB_ID); mController.init(SUB_ID);
mController.mImsManager = mImsManager;
mPreference.setKey(mController.getPreferenceKey()); mPreference.setKey(mController.getPreferenceKey());
} }

View File

@@ -38,6 +38,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
@@ -107,8 +108,8 @@ public class AudioOutputSwitchPreferenceControllerTest {
private Context mContext; private Context mContext;
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
private ListPreference mPreference; private ListPreference mPreference;
private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager; private ShadowAudioManager mShadowAudioManager;
private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager; private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter; private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
@@ -126,8 +127,8 @@ public class AudioOutputSwitchPreferenceControllerTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow(); mShadowAudioManager = ShadowAudioManager.getShadow();
mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager; ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext); mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -168,7 +169,6 @@ public class AudioOutputSwitchPreferenceControllerTest {
@After @After
public void tearDown() { public void tearDown() {
mShadowAudioManager.reset();
ShadowBluetoothUtils.reset(); ShadowBluetoothUtils.reset();
} }

View File

@@ -99,8 +99,8 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
private Context mContext; private Context mContext;
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
private ListPreference mPreference; private ListPreference mPreference;
private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager; private ShadowAudioManager mShadowAudioManager;
private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager; private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter; private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
@@ -117,8 +117,8 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow(); mShadowAudioManager = ShadowAudioManager.getShadow();
mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager; ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext); mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -163,7 +163,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
@After @After
public void tearDown() { public void tearDown() {
mShadowAudioManager.reset();
ShadowBluetoothUtils.reset(); ShadowBluetoothUtils.reset();
} }
@@ -173,7 +172,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() { public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1); when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice); mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
@@ -188,7 +187,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() { public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(mBluetoothDevice); mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -203,7 +202,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() { public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(null); mController.setActiveBluetoothDevice(null);
@@ -217,7 +216,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_inNormalMode_shouldNotSetActiveDeviceToHeadsetProfile() { public void setActiveBluetoothDevice_inNormalMode_shouldNotSetActiveDeviceToHeadsetProfile() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(mBluetoothDevice); mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -245,7 +244,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_oneHeadsetsAvailableAndActivated_shouldSetDeviceName() { public void updateState_oneHeadsetsAvailableAndActivated_shouldSetDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO); mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -266,7 +265,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_moreThanOneHfpBtDevicesAreAvailable_shouldSetActivatedDeviceName() { public void updateState_moreThanOneHfpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO); mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
List<BluetoothDevice> connectedDevices = new ArrayList<>(2); List<BluetoothDevice> connectedDevices = new ArrayList<>(2);
connectedDevices.add(mBluetoothDevice); connectedDevices.add(mBluetoothDevice);
@@ -288,7 +287,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_withAvailableDevicesWiredHeadsetActivated_shouldSetDefaultSummary() { public void updateState_withAvailableDevicesWiredHeadsetActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices); when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
@@ -308,7 +307,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_noAvailableHeadsetBtDevices_shouldSetDefaultSummary() { public void updateState_noAvailableHeadsetBtDevices_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
List<BluetoothDevice> emptyDeviceList = new ArrayList<>(); List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
when(mHeadsetProfile.getConnectedDevices()).thenReturn(emptyDeviceList); when(mHeadsetProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
@@ -326,7 +325,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() { public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice); mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -350,7 +349,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() { public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice); mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -378,7 +377,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() { public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -411,7 +410,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() { public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -443,7 +442,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() { public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);

View File

@@ -100,8 +100,8 @@ public class MediaOutputPreferenceControllerTest {
private Context mContext; private Context mContext;
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
private ListPreference mPreference; private ListPreference mPreference;
private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager; private ShadowAudioManager mShadowAudioManager;
private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager; private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter; private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
@@ -118,8 +118,8 @@ public class MediaOutputPreferenceControllerTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mShadowAudioManager = ShadowAudioManager.getShadow(); mShadowAudioManager = ShadowAudioManager.getShadow();
mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager; ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext); mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -164,7 +164,6 @@ public class MediaOutputPreferenceControllerTest {
@After @After
public void tearDown() { public void tearDown() {
mShadowAudioManager.reset();
ShadowBluetoothUtils.reset(); ShadowBluetoothUtils.reset();
} }
@@ -174,7 +173,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() { public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1); when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice); mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
@@ -189,7 +188,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() { public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(mBluetoothDevice); mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -204,7 +203,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() { public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(null); mController.setActiveBluetoothDevice(null);
@@ -218,7 +217,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void setActiveBluetoothDevice_duringACall_shouldNotSetActiveDeviceToA2dpProfile() { public void setActiveBluetoothDevice_duringACall_shouldNotSetActiveDeviceToA2dpProfile() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(mBluetoothDevice); mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -246,7 +245,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_duringACall_shouldSetDefaultSummary() { public void updateState_duringACall_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -262,7 +261,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_noAvailableA2dpBtDevices_shouldDisableAndSetDefaultSummary() { public void updateState_noAvailableA2dpBtDevices_shouldDisableAndSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
List<BluetoothDevice> emptyDeviceList = new ArrayList<>(); List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
when(mA2dpProfile.getConnectedDevices()).thenReturn(emptyDeviceList); when(mA2dpProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
@@ -296,7 +295,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_oneA2dpBtDeviceAreAvailable_shouldSetActivatedDeviceName() { public void updateState_oneA2dpBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP); mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -316,7 +315,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_moreThanOneA2DpBtDevicesAreAvailable_shouldSetActivatedDeviceName() { public void updateState_moreThanOneA2DpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP); mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -337,7 +336,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() { public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null); when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
@@ -359,7 +358,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_a2dpDevicesAvailableCurrentDeviceActivated_shouldSetDefaultSummary() { public void updateState_a2dpDevicesAvailableCurrentDeviceActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices); when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
@@ -379,7 +378,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() { public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice); mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -403,7 +402,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() { public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice); mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -431,7 +430,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() { public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -464,7 +463,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() { public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);
@@ -496,7 +495,7 @@ public class MediaOutputPreferenceControllerTest {
*/ */
@Test @Test
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() { public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID); mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear(); mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice); mProfileConnectedDevices.add(mBluetoothDevice);

View File

@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Implements(AccountManager.class) @Implements(AccountManager.class)
public class ShadowAccountManager{ public class ShadowAccountManager {
private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>(); private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>(); private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();

View File

@@ -101,11 +101,6 @@ public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManag
} }
} }
@Resetter
public void reset() {
mDeviceCallbacks.clear();
}
public void setBluetoothScoOn(boolean bluetoothScoOn) { public void setBluetoothScoOn(boolean bluetoothScoOn) {
mBluetoothScoOn = bluetoothScoOn; mBluetoothScoOn = bluetoothScoOn;
} }

View File

@@ -21,12 +21,10 @@ import android.content.pm.UserInfo;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.os.UserManager.EnforcingUser; import android.os.UserManager.EnforcingUser;
import android.util.SparseArray;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements; import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.shadow.api.Shadow; import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList; import java.util.ArrayList;
@@ -40,7 +38,6 @@ import java.util.Set;
@Implements(value = UserManager.class) @Implements(value = UserManager.class)
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager { public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
private final List<String> mRestrictions = new ArrayList<>(); private final List<String> mRestrictions = new ArrayList<>();
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>(); private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
private final List<UserInfo> mUserProfileInfos = new ArrayList<>(); private final List<UserInfo> mUserProfileInfos = new ArrayList<>();
@@ -49,15 +46,6 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
private int[] profileIdsForUser = new int[0]; private int[] profileIdsForUser = new int[0];
private boolean mUserSwitchEnabled; private boolean mUserSwitchEnabled;
public void setUserInfo(int userHandle, UserInfo userInfo) {
mUserInfos.put(userHandle, userInfo);
}
@Implementation
protected UserInfo getUserInfo(int userHandle) {
return mUserInfos.get(userHandle);
}
public void addProfile(UserInfo userInfo) { public void addProfile(UserInfo userInfo) {
mUserProfileInfos.add(userInfo); mUserProfileInfos.add(userInfo);
} }
@@ -76,16 +64,6 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
return ids; return ids;
} }
@Implementation
public List<UserHandle> getUserProfiles() {
int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
List<UserHandle> result = new ArrayList<>(userIds.length);
for (int userId : userIds) {
result.add(UserHandle.of(userId));
}
return result;
}
@Implementation @Implementation
protected int getCredentialOwnerProfile(@UserIdInt int userHandle) { protected int getCredentialOwnerProfile(@UserIdInt int userHandle) {
return userHandle; return userHandle;

View File

@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.pm.UserInfo;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -32,7 +31,6 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -40,7 +38,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class}) @Config(shadows = {ShadowUserManager.class})
@@ -49,7 +46,6 @@ public class AddUserWhenLockedPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)
private UserInfo mUserInfo;
private Context mContext; private Context mContext;
private ShadowUserManager mUserManager; private ShadowUserManager mUserManager;
@@ -65,8 +61,7 @@ public class AddUserWhenLockedPreferenceControllerTest {
@Test @Test
public void displayPref_NotAdmin_shouldNotDisplay() { public void displayPref_NotAdmin_shouldNotDisplay() {
mUserManager.setUserInfo(0, mUserInfo); mUserManager.setIsAdminUser(false);
when(mUserInfo.isAdmin()).thenReturn(false);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class); final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
when(preference.getKey()).thenReturn(mController.getPreferenceKey()); when(preference.getKey()).thenReturn(mController.getPreferenceKey());
when(mScreen.findPreference(preference.getKey())).thenReturn(preference); when(mScreen.findPreference(preference.getKey())).thenReturn(preference);

View File

@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -40,9 +39,7 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -50,18 +47,14 @@ import org.mockito.Answers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.android.controller.ActivityController; import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class})
public class EditUserInfoControllerTest { public class EditUserInfoControllerTest {
@Mock @Mock
private Fragment mFragment; private Fragment mFragment;
@Mock @Mock
private LayoutInflater mInflater; private LayoutInflater mInflater;
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private UserInfo mUserInfo;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private View mDialogContent; private View mDialogContent;
@Mock @Mock
private EditText mUserName; private EditText mUserName;
@@ -70,7 +63,6 @@ public class EditUserInfoControllerTest {
@Mock @Mock
private Drawable mCurrentIcon; private Drawable mCurrentIcon;
private ShadowUserManager mUserManager;
private FragmentActivity mActivity; private FragmentActivity mActivity;
private TestEditUserInfoController mController; private TestEditUserInfoController mController;
@@ -92,8 +84,6 @@ public class EditUserInfoControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mUserManager = ShadowUserManager.getShadow();
mUserManager.setUserInfo(0, mUserInfo);
mActivity = spy(ActivityController.of(new FragmentActivity()).get()); mActivity = spy(ActivityController.of(new FragmentActivity()).get());
when(mFragment.getActivity()).thenReturn(mActivity); when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getLayoutInflater()).thenReturn(mInflater); when(mActivity.getLayoutInflater()).thenReturn(mInflater);

View File

@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -56,14 +57,14 @@ public class SavedAccessPointsPreferenceControllerTest {
private PreferenceCategory mPreferenceCategory; private PreferenceCategory mPreferenceCategory;
private Context mContext; private Context mContext;
private ShadowWifiManager mWifiManager; private WifiManager mWifiManager;
private SavedAccessPointsPreferenceController mController; private SavedAccessPointsPreferenceController mController;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mWifiManager = ShadowWifiManager.get(); mWifiManager = mContext.getSystemService(WifiManager.class);
mController = spy(new SavedAccessPointsPreferenceController(mContext, "test_key")); mController = spy(new SavedAccessPointsPreferenceController(mContext, "test_key"));
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))