Fix borken test on Bluetooth and connected package

Bug: 187239965
Test: make RunSettingsRoboTests -j56
Change-Id: Ic0d60a6cd46b1211efb2021f079c0b0a6534b383
This commit is contained in:
Hugh Chen
2021-05-05 14:31:01 +08:00
parent 9246f6f8b0
commit db53d1c6f8
8 changed files with 47 additions and 1 deletions

View File

@@ -61,9 +61,10 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
long mCurrentFunctions; long mCurrentFunctions;
@VisibleForTesting @VisibleForTesting
boolean mIsStartTethering = false; boolean mIsStartTethering = false;
@VisibleForTesting
Handler mHandler;
private UsbConnectionBroadcastReceiver mUsbReceiver; private UsbConnectionBroadcastReceiver mUsbReceiver;
private Handler mHandler;
private boolean mIsConnected = false; private boolean mIsConnected = false;
@VisibleForTesting @VisibleForTesting

View File

@@ -26,7 +26,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.AudioManager; import android.media.AudioManager;
import android.util.Pair;
import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -62,6 +64,8 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
private CachedBluetoothDevice mCachedBluetoothDevice; private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock @Mock
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
@Mock
private Drawable mDrawable;
private Context mContext; private Context mContext;
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater; private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -83,10 +87,12 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
Utils.getLocalBtManager(mContext).getCachedDeviceManager()); Utils.getLocalBtManager(mContext).getCachedDeviceManager());
mCachedDevices = new ArrayList<>(); mCachedDevices = new ArrayList<>();
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices); mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
doReturn(mContext).when(mDashboardFragment).getContext(); doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
mBluetoothDeviceUpdater = spy(new AvailableMediaBluetoothDeviceUpdater(mContext, mBluetoothDeviceUpdater = spy(new AvailableMediaBluetoothDeviceUpdater(mContext,
mDashboardFragment, mDevicePreferenceCallback)); mDashboardFragment, mDevicePreferenceCallback));

View File

@@ -27,6 +27,8 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -78,6 +80,8 @@ public class BluetoothDeviceUpdaterTest {
private LocalBluetoothManager mLocalManager; private LocalBluetoothManager mLocalManager;
@Mock @Mock
private CachedBluetoothDeviceManager mCachedDeviceManager; private CachedBluetoothDeviceManager mCachedDeviceManager;
@Mock
private Drawable mDrawable;
private Context mContext; private Context mContext;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater; private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -89,6 +93,7 @@ public class BluetoothDeviceUpdaterTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mCachedDevices.add(mCachedBluetoothDevice); mCachedDevices.add(mCachedBluetoothDevice);
@@ -99,6 +104,7 @@ public class BluetoothDeviceUpdaterTest {
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mSubBluetoothDevice.getAddress()).thenReturn(SUB_MAC_ADDRESS); when(mSubBluetoothDevice.getAddress()).thenReturn(SUB_MAC_ADDRESS);
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
false, BluetoothDevicePreference.SortType.TYPE_DEFAULT); false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);

View File

@@ -35,6 +35,8 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceGroup;
@@ -70,6 +72,9 @@ public class BluetoothPairingDetailTest {
private PreferenceGroup mPreferenceGroup; private PreferenceGroup mPreferenceGroup;
@Mock @Mock
private CachedBluetoothDevice mCachedBluetoothDevice; private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private Drawable mDrawable;
private BluetoothPairingDetail mFragment; private BluetoothPairingDetail mFragment;
private Context mContext; private Context mContext;
private BluetoothProgressCategory mAvailableDevicesCategory; private BluetoothProgressCategory mAvailableDevicesCategory;
@@ -82,11 +87,13 @@ public class BluetoothPairingDetailTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mFragment = spy(new BluetoothPairingDetail()); mFragment = spy(new BluetoothPairingDetail());
doReturn(mContext).when(mFragment).getContext(); doReturn(mContext).when(mFragment).getContext();
doReturn(mResource).when(mFragment).getResources(); doReturn(mResource).when(mFragment).getResources();
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
mAvailableDevicesCategory = spy(new BluetoothProgressCategory(mContext)); mAvailableDevicesCategory = spy(new BluetoothProgressCategory(mContext));
mFooterPreference = new FooterPreference(mContext); mFooterPreference = new FooterPreference(mContext);

View File

@@ -28,7 +28,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.AudioManager; import android.media.AudioManager;
import android.util.Pair;
import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -65,6 +67,8 @@ public class ConnectedBluetoothDeviceUpdaterTest {
private CachedBluetoothDevice mCachedBluetoothDevice; private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock @Mock
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
@Mock
private Drawable mDrawable;
private Context mContext; private Context mContext;
private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater; private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -77,6 +81,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mAudioManager = mContext.getSystemService(AudioManager.class); mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
@@ -88,6 +93,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices); mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext, mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext,
mDashboardFragment, mDevicePreferenceCallback)); mDashboardFragment, mDevicePreferenceCallback));

View File

@@ -28,6 +28,8 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -69,6 +71,8 @@ public class SavedBluetoothDeviceUpdaterTest {
private CachedBluetoothDeviceManager mDeviceManager; private CachedBluetoothDeviceManager mDeviceManager;
@Mock @Mock
private LocalBluetoothManager mBluetoothManager; private LocalBluetoothManager mBluetoothManager;
@Mock
private Drawable mDrawable;
private Context mContext; private Context mContext;
private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater; private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -78,11 +82,13 @@ public class SavedBluetoothDeviceUpdaterTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
doReturn(mContext).when(mDashboardFragment).getContext(); doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mContext, mDashboardFragment, mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mContext, mDashboardFragment,
mDevicePreferenceCallback)); mDevicePreferenceCallback));

View File

@@ -29,6 +29,8 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
@@ -100,6 +102,8 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
private BluetoothDevice mBluetoothDevice4; private BluetoothDevice mBluetoothDevice4;
@Mock @Mock
private BluetoothDevice mBluetoothDevice5; private BluetoothDevice mBluetoothDevice5;
@Mock
private Drawable mDrawable;
private Context mContext; private Context mContext;
private PreviouslyConnectedDevicePreferenceController mPreConnectedDeviceController; private PreviouslyConnectedDevicePreferenceController mPreConnectedDeviceController;
@@ -109,6 +113,7 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
doReturn(mContext).when(mDashboardFragment).getContext(); doReturn(mContext).when(mDashboardFragment).getContext();
doReturn(mPackageManager).when(mContext).getPackageManager(); doReturn(mPackageManager).when(mContext).getPackageManager();
@@ -120,14 +125,19 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
when(mCachedDevice1.getDevice()).thenReturn(mBluetoothDevice1); when(mCachedDevice1.getDevice()).thenReturn(mBluetoothDevice1);
when(mCachedDevice1.getAddress()).thenReturn(FAKE_ADDRESS_1); when(mCachedDevice1.getAddress()).thenReturn(FAKE_ADDRESS_1);
when(mCachedDevice1.getDrawableWithDescription()).thenReturn(pairs);
when(mCachedDevice2.getDevice()).thenReturn(mBluetoothDevice2); when(mCachedDevice2.getDevice()).thenReturn(mBluetoothDevice2);
when(mCachedDevice2.getAddress()).thenReturn(FAKE_ADDRESS_2); when(mCachedDevice2.getAddress()).thenReturn(FAKE_ADDRESS_2);
when(mCachedDevice2.getDrawableWithDescription()).thenReturn(pairs);
when(mCachedDevice3.getDevice()).thenReturn(mBluetoothDevice3); when(mCachedDevice3.getDevice()).thenReturn(mBluetoothDevice3);
when(mCachedDevice3.getAddress()).thenReturn(FAKE_ADDRESS_3); when(mCachedDevice3.getAddress()).thenReturn(FAKE_ADDRESS_3);
when(mCachedDevice3.getDrawableWithDescription()).thenReturn(pairs);
when(mCachedDevice4.getDevice()).thenReturn(mBluetoothDevice4); when(mCachedDevice4.getDevice()).thenReturn(mBluetoothDevice4);
when(mCachedDevice4.getAddress()).thenReturn(FAKE_ADDRESS_4); when(mCachedDevice4.getAddress()).thenReturn(FAKE_ADDRESS_4);
when(mCachedDevice4.getDrawableWithDescription()).thenReturn(pairs);
when(mCachedDevice5.getDevice()).thenReturn(mBluetoothDevice5); when(mCachedDevice5.getDevice()).thenReturn(mBluetoothDevice5);
when(mCachedDevice5.getAddress()).thenReturn(FAKE_ADDRESS_5); when(mCachedDevice5.getAddress()).thenReturn(FAKE_ADDRESS_5);
when(mCachedDevice5.getDrawableWithDescription()).thenReturn(pairs);
final List<BluetoothDevice> mMostRecentlyConnectedDevices = new ArrayList<>(); final List<BluetoothDevice> mMostRecentlyConnectedDevices = new ArrayList<>();
mMostRecentlyConnectedDevices.add(mBluetoothDevice1); mMostRecentlyConnectedDevices.add(mBluetoothDevice1);

View File

@@ -33,6 +33,7 @@ import static org.mockito.Mockito.when;
import android.hardware.usb.UsbManager; import android.hardware.usb.UsbManager;
import android.net.TetheringManager; import android.net.TetheringManager;
import android.os.Handler;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -53,6 +54,8 @@ public class UsbDefaultFragmentTest {
private UsbBackend mUsbBackend; private UsbBackend mUsbBackend;
@Mock @Mock
private TetheringManager mTetheringManager; private TetheringManager mTetheringManager;
@Mock
private Handler mHandler;
private UsbDefaultFragment mFragment; private UsbDefaultFragment mFragment;
@@ -62,6 +65,7 @@ public class UsbDefaultFragmentTest {
mFragment = new TestFragment(); mFragment = new TestFragment();
mFragment.mUsbBackend = mUsbBackend; mFragment.mUsbBackend = mUsbBackend;
mFragment.mTetheringManager = mTetheringManager; mFragment.mTetheringManager = mTetheringManager;
mFragment.mHandler = mHandler;
} }
@Test @Test