Merge "Update mocking to correct target methods" am: efa884758b

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1644306

Change-Id: I2d68748adf0154af2a3b9017d4510041af5baf12
diff --git a/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java
index 8a68f38..eb29b7c 100644
--- a/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java
@@ -18,17 +18,16 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
-import static org.robolectric.shadow.api.Shadow.extract;
+import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.provider.Settings;
+import android.telephony.TelephonyManager;
 
 import androidx.preference.Preference;
 
-import com.android.settings.testutils.shadow.ShadowConnectivityManager;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,27 +35,28 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowConnectivityManager.class)
 public class AutoTimeZonePreferenceControllerTest {
 
     @Mock
     private UpdateTimeAndDateCallback mCallback;
-
+    @Mock
     private Context mContext;
     private AutoTimeZonePreferenceController mController;
     private Preference mPreference;
-    private ShadowConnectivityManager connectivityManager;
+    @Mock
+    private TelephonyManager mTelephonyManager;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application;
+        mContext = spy(RuntimeEnvironment.application);
+
         mPreference = new Preference(mContext);
-        connectivityManager = extract(mContext.getSystemService(ConnectivityManager.class));
-        connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, true);
+
+        when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
+        when(mTelephonyManager.isDataCapable()).thenReturn(true);
     }
 
     @Test
@@ -77,8 +77,7 @@
 
     @Test
     public void isWifiOnly_notAvailable() {
-        connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
-
+        when(mTelephonyManager.isDataCapable()).thenReturn(false);
         mController = new AutoTimeZonePreferenceController(
                 mContext, null /* callback */, false /* fromSUW */);
 
@@ -95,8 +94,7 @@
 
     @Test
     public void isWifiOnly_notEnable() {
-        connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
-
+        when(mTelephonyManager.isDataCapable()).thenReturn(false);
         mController = new AutoTimeZonePreferenceController(
                 mContext, null /* callback */, false /* fromSUW */);
 
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java
index 79df221..87fdb22 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java
@@ -21,44 +21,42 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.robolectric.shadow.api.Shadow.extract;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.sysprop.TelephonyProperties;
-
-import com.android.settings.testutils.shadow.ShadowConnectivityManager;
+import android.telephony.TelephonyManager;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
 
 import java.util.Arrays;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowConnectivityManager.class)
 public class BasebandVersionPreferenceControllerTest {
-
+    @Mock
     private Context mContext;
     private BasebandVersionPreferenceController mController;
+    @Mock
+    private TelephonyManager mTelephonyManager;
 
     @Before
     public void setup() {
         MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application;
+        mContext = spy(RuntimeEnvironment.application);
         mController = new BasebandVersionPreferenceController(mContext, "key");
+        when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
     }
 
     @Test
     public void getAvailability_wifiOnly_unavailable() {
-        final ShadowConnectivityManager connectivityManager =
-                extract(mContext.getSystemService(ConnectivityManager.class));
-        connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
-
+        when(mTelephonyManager.isDataCapable()).thenReturn(false);
         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
     }
 
@@ -66,10 +64,7 @@
     public void getAvailability_hasMobile_available() {
         final String text = "test";
         TelephonyProperties.baseband_version(Arrays.asList(new String[]{text}));
-        ShadowConnectivityManager connectivityManager =
-                extract(mContext.getSystemService(ConnectivityManager.class));
-        connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, true);
-
+        when(mTelephonyManager.isDataCapable()).thenReturn(true);
         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
index ea90860..44611ce 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
@@ -74,7 +74,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
-        when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
+        when(mActivity.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
         when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
         when(mContext.getSystemService(NetworkStatsManager.class)).thenReturn(mNetworkStatsManager);
         ShadowEntityHeaderController.setUseMock(mock(EntityHeaderController.class));