Search in sources :

Example 1 with ShadowTelephonyManager

use of org.robolectric.shadows.ShadowTelephonyManager in project android_packages_apps_Settings by omnirom.

the class DataUsagePreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    final TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
    final ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(telephonyManager);
    shadowTelephonyManager.setTelephonyManagerForSubscriptionId(SUB_ID, telephonyManager);
    shadowTelephonyManager.setTelephonyManagerForSubscriptionId(SubscriptionManager.INVALID_SUBSCRIPTION_ID, telephonyManager);
    doReturn(mNetworkStatsManager).when(mContext).getSystemService(NetworkStatsManager.class);
    mPreference = new SwitchPreference(mContext);
    mController = spy(new DataUsagePreferenceController(mContext, "data_usage"));
    mController.init(SUB_ID);
    mPreference.setKey(mController.getPreferenceKey());
}
Also used : ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) TelephonyManager(android.telephony.TelephonyManager) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) SwitchPreference(androidx.preference.SwitchPreference) Before(org.junit.Before)

Example 2 with ShadowTelephonyManager

use of org.robolectric.shadows.ShadowTelephonyManager in project android_packages_apps_Settings by omnirom.

the class DataUsageSummaryTest method setUp.

/**
 * This set up is contrived to get a passing test so that the build doesn't block without tests.
 * These tests should be updated as code gets refactored to improve testability.
 */
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    ShadowApplication shadowContext = ShadowApplication.getInstance();
    ShadowUserManager.getShadow().setIsAdminUser(true);
    shadowContext.setSystemService(Context.NETWORK_POLICY_SERVICE, mNetworkPolicyManager);
    mContext = RuntimeEnvironment.application;
    mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
    final ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(mTelephonyManager);
    shadowTelephonyManager.setTelephonyManagerForSubscriptionId(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mTelephonyManager);
    shadowTelephonyManager.setTelephonyManagerForSubscriptionId(1, mTelephonyManager);
    mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
    doReturn(mNetworkStatsManager).when(mActivity).getSystemService(NetworkStatsManager.class);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) TelephonyManager(android.telephony.TelephonyManager) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) ShadowApplication(org.robolectric.shadows.ShadowApplication) Before(org.junit.Before)

Example 3 with ShadowTelephonyManager

use of org.robolectric.shadows.ShadowTelephonyManager in project prebid-mobile-android by prebid.

the class AutoDetectedOpenRtbTest method setup.

@Before
public void setup() {
    mActivity = Robolectric.buildActivity(Activity.class).create().get();
    ShadowActivity shadowActivity = shadowOf(mActivity);
    shadowActivity.grantPermissions("android.permission.ACCESS_FINE_LOCATION");
    LocationManager locationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
    ShadowLocationManager shadowLocationManager = shadowOf(locationManager);
    Location location = new Location("");
    location.setLatitude(1);
    location.setLongitude(1);
    shadowLocationManager.setLastKnownLocation("gps", location);
    ShadowTelephonyManager shadowTelephonyManager = shadowOf((TelephonyManager) mActivity.getSystemService(Context.TELEPHONY_SERVICE));
    shadowTelephonyManager.setNetworkOperatorName("carrier");
    shadowTelephonyManager.setNetworkOperator("carrier");
    ManagersResolver.getInstance().prepare(mActivity);
    mParamBuilderArray = new ArrayList<>();
    mOriginalAdRequestInput = new AdRequestInput();
    mOriginalOpenRtbParams = new BidRequest();
}
Also used : ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) LocationManager(android.location.LocationManager) AdRequestInput(org.prebid.mobile.rendering.networking.parameters.AdRequestInput) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) ShadowActivity(org.robolectric.shadows.ShadowActivity) Activity(android.app.Activity) ShadowActivity(org.robolectric.shadows.ShadowActivity) Location(android.location.Location) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest) Before(org.junit.Before)

Example 4 with ShadowTelephonyManager

use of org.robolectric.shadows.ShadowTelephonyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ImeiInfoDialogControllerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    final ShadowSubscriptionManager ssm = Shadow.extract(mContext.getSystemService(SubscriptionManager.class));
    ssm.setActiveSubscriptionInfos(mSubscriptionInfo);
    when(mSubscriptionInfo.getSubscriptionId()).thenReturn(SUB_ID);
    final ShadowTelephonyManager stm = Shadow.extract(mContext.getSystemService(TelephonyManager.class));
    stm.setTelephonyManagerForSubscriptionId(SUB_ID, mTelephonyManager);
    when(mDialog.getContext()).thenReturn(mContext);
    mController = spy(new ImeiInfoDialogController(mDialog, SLOT_ID));
    when(mTelephonyManager.getCdmaPrlVersion()).thenReturn(PRL_VERSION);
    when(mTelephonyManager.getMeid(anyInt())).thenReturn(MEID_NUMBER);
    when(mTelephonyManager.getCdmaMin(anyInt())).thenReturn(MIN_NUMBER);
    when(mTelephonyManager.getDeviceSoftwareVersion(anyInt())).thenReturn(IMEI_SV_NUMBER);
    when(mTelephonyManager.getImei(anyInt())).thenReturn(IMEI_NUMBER);
}
Also used : ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) TelephonyManager(android.telephony.TelephonyManager) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) ShadowSubscriptionManager(org.robolectric.shadows.ShadowSubscriptionManager) ShadowSubscriptionManager(org.robolectric.shadows.ShadowSubscriptionManager) SubscriptionManager(android.telephony.SubscriptionManager) Before(org.junit.Before)

Example 5 with ShadowTelephonyManager

use of org.robolectric.shadows.ShadowTelephonyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsagePreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(Robolectric.setupActivity(Activity.class));
    final TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
    final ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(telephonyManager);
    shadowTelephonyManager.setTelephonyManagerForSubscriptionId(SUB_ID, telephonyManager);
    shadowTelephonyManager.setTelephonyManagerForSubscriptionId(SubscriptionManager.INVALID_SUBSCRIPTION_ID, telephonyManager);
    doReturn(mNetworkStatsManager).when(mContext).getSystemService(NetworkStatsManager.class);
    mPreference = new SwitchPreference(mContext);
    mController = new DataUsagePreferenceController(mContext, "data_usage");
    mController.init(SUB_ID);
    mPreference.setKey(mController.getPreferenceKey());
}
Also used : ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) TelephonyManager(android.telephony.TelephonyManager) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) SwitchPreference(androidx.preference.SwitchPreference) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)11 ShadowTelephonyManager (org.robolectric.shadows.ShadowTelephonyManager)11 TelephonyManager (android.telephony.TelephonyManager)10 SubscriptionManager (android.telephony.SubscriptionManager)4 ShadowSubscriptionManager (org.robolectric.shadows.ShadowSubscriptionManager)4 FragmentActivity (androidx.fragment.app.FragmentActivity)2 SwitchPreference (androidx.preference.SwitchPreference)2 ShadowApplication (org.robolectric.shadows.ShadowApplication)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 SubscriptionInfo (android.telephony.SubscriptionInfo)1 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)1 BidRequest (org.prebid.mobile.rendering.models.openrtb.BidRequest)1 AdRequestInput (org.prebid.mobile.rendering.networking.parameters.AdRequestInput)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1 ShadowLocationManager (org.robolectric.shadows.ShadowLocationManager)1