Update mocking to correct target methods
The correct target context should use the mActivity in MobileNetworkSettingsTest, so that the mocking for telephony service could correctly applied. Both AutoTimeZonePreferenceControllerTest and BasebandVersionPreferenceControllerTest refer to the lib implemented shadow Connectivitymanager but that does not the correct reference after utils class being updated. Update the test logic inside to refer to correct method. The reference to ShadowConnectivityManager does not needed anymore so remove it from the test. Fix: 183068151 Fix: 183067742 Fix: 183068139 Test: make RunSettingsRoboTests ROBOTEST_FILTER=\ com.android.settings.network.telephony.MobileNetworkSettingsTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=\ com.android.settings.datetime.AutoTimeZonePreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings\ .deviceinfo.firmwareversion.BasebandVersionPreferenceControllerTest Change-Id: I15ecc6aab7d530d20cd23b06267cc184a2c62b40
This commit is contained in:
@@ -18,17 +18,16 @@ package com.android.settings.datetime;
|
||||
|
||||
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.Mock;
|
||||
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 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
|
||||
@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 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isWifiOnly_notEnable() {
|
||||
connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
|
||||
|
||||
when(mTelephonyManager.isDataCapable()).thenReturn(false);
|
||||
mController = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, false /* fromSUW */);
|
||||
|
||||
|
Reference in New Issue
Block a user