Remove test-purpose constructor from AvailableMediaBluetoothDeviceUpdater
- replace mock object with ShadowCachedBluetoothDeviceManager to test CachedBluetoothDevice - rename cachedDevices to mCachedDevices Bug: 111848213 Test: make -j50 RunSettingsRoboTests Change-Id: I3028a6fe06c39c48e7cee33976bdfcab2c8b73c8
This commit is contained in:
@@ -23,9 +23,7 @@ import android.util.Log;
|
|||||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,15 +43,6 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
|||||||
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
AvailableMediaBluetoothDeviceUpdater(DashboardFragment fragment,
|
|
||||||
DevicePreferenceCallback devicePreferenceCallback,
|
|
||||||
LocalBluetoothManager localBluetoothManager) {
|
|
||||||
super(fragment, devicePreferenceCallback, localBluetoothManager);
|
|
||||||
mAudioManager = (AudioManager) fragment.getContext().
|
|
||||||
getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAudioModeChanged() {
|
public void onAudioModeChanged() {
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
|
@@ -33,10 +33,9 @@ import com.android.settings.dashboard.DashboardFragment;
|
|||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowCachedBluetoothDeviceManager;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
|
||||||
import com.android.settingslib.bluetooth.HeadsetProfile;
|
import com.android.settingslib.bluetooth.HeadsetProfile;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -52,7 +51,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowAudioManager.class, ShadowBluetoothAdapter.class})
|
@Config(shadows = {ShadowAudioManager.class, ShadowBluetoothAdapter.class,
|
||||||
|
ShadowCachedBluetoothDeviceManager.class})
|
||||||
public class AvailableMediaBluetoothDeviceUpdaterTest {
|
public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||||
@Mock
|
@Mock
|
||||||
private DashboardFragment mDashboardFragment;
|
private DashboardFragment mDashboardFragment;
|
||||||
@@ -62,21 +62,14 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||||
@Mock
|
@Mock
|
||||||
private BluetoothDevice mBluetoothDevice;
|
private BluetoothDevice mBluetoothDevice;
|
||||||
@Mock
|
|
||||||
private LocalBluetoothManager mLocalManager;
|
|
||||||
@Mock
|
|
||||||
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
|
|
||||||
@Mock
|
|
||||||
private HeadsetProfile mHeadsetProfile;
|
|
||||||
@Mock
|
|
||||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||||
private Collection<CachedBluetoothDevice> cachedDevices;
|
private Collection<CachedBluetoothDevice> mCachedDevices;
|
||||||
private ShadowAudioManager mShadowAudioManager;
|
private ShadowAudioManager mShadowAudioManager;
|
||||||
private BluetoothDevicePreference mPreference;
|
private BluetoothDevicePreference mPreference;
|
||||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||||
|
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -86,18 +79,17 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||||
mShadowBluetoothAdapter.setEnabled(true);
|
mShadowBluetoothAdapter.setEnabled(true);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
mShadowCachedBluetoothDeviceManager = Shadow.extract(
|
||||||
cachedDevices =
|
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
||||||
|
mCachedDevices =
|
||||||
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
|
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
|
||||||
|
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
||||||
|
|
||||||
|
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
|
||||||
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
|
|
||||||
when(mLocalManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
|
||||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater = spy(new AvailableMediaBluetoothDeviceUpdater(mDashboardFragment,
|
mBluetoothDeviceUpdater = spy(new AvailableMediaBluetoothDeviceUpdater(mContext,
|
||||||
mDevicePreferenceCallback, mLocalManager));
|
mDashboardFragment, mDevicePreferenceCallback));
|
||||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
|
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
|
||||||
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
||||||
@@ -110,7 +102,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
||||||
cachedDevices.add(mCachedBluetoothDevice);
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -123,7 +115,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
||||||
cachedDevices.add(mCachedBluetoothDevice);
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -136,7 +128,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
||||||
cachedDevices.add(mCachedBluetoothDevice);
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -149,7 +141,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
||||||
cachedDevices.add(mCachedBluetoothDevice);
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user