OSDN Git Service

Remove test-purpose constructor from SavedBluetoothDeviceUpdater
authortimhypeng <timhypeng@google.com>
Tue, 14 Aug 2018 10:45:18 +0000 (18:45 +0800)
committertim peng <timhypeng@google.com>
Thu, 16 Aug 2018 01:25:01 +0000 (01:25 +0000)
- replace mock object with ShadowBluetoothAdapter

Bug: 111848213
Test: make -j50 RunSettingsRoboTests
Change-Id: Iff69ed511b23846078925609bb603ae414956ea3

src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java

index 059a920..50de166 100644 (file)
 package com.android.settings.bluetooth;
 
 import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothProfile;
 import android.content.Context;
 import android.util.Log;
 
 import com.android.settings.connecteddevice.DevicePreferenceCallback;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
-import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
 
 /**
@@ -41,13 +38,6 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
         super(context, fragment, devicePreferenceCallback);
     }
 
-    @VisibleForTesting
-    SavedBluetoothDeviceUpdater(DashboardFragment fragment,
-            DevicePreferenceCallback devicePreferenceCallback,
-            LocalBluetoothManager localBluetoothManager) {
-        super(fragment, devicePreferenceCallback, localBluetoothManager);
-    }
-
     @Override
     public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
         final BluetoothDevice device = cachedDevice.getDevice();
index def8c4d..e25e4b2 100644 (file)
@@ -29,9 +29,8 @@ import android.content.Context;
 import com.android.settings.connecteddevice.DevicePreferenceCallback;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -39,8 +38,10 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {ShadowBluetoothAdapter.class})
 public class SavedBluetoothDeviceUpdaterTest {
 
     @Mock
@@ -51,10 +52,6 @@ public class SavedBluetoothDeviceUpdaterTest {
     private CachedBluetoothDevice mCachedBluetoothDevice;
     @Mock
     private BluetoothDevice mBluetoothDevice;
-    @Mock
-    private LocalBluetoothManager mLocalManager;
-    @Mock
-    private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
 
     private Context mContext;
     private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -67,11 +64,10 @@ public class SavedBluetoothDeviceUpdaterTest {
         mContext = RuntimeEnvironment.application;
         doReturn(mContext).when(mDashboardFragment).getContext();
         when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
-        when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
         when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
 
-        mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
-                mDevicePreferenceCallback, mLocalManager));
+        mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mContext, mDashboardFragment,
+                mDevicePreferenceCallback));
         mBluetoothDeviceUpdater.setPrefContext(mContext);
         mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
         doNothing().when(mBluetoothDeviceUpdater).addPreference(any());