Search in sources :

Example 1 with ShadowLocationManager

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

the class BaseJSInterfaceTest method whenGetLocationAndLocationAvailable_ReturnLocationJson.

@Test
public void whenGetLocationAndLocationAvailable_ReturnLocationJson() throws JSONException {
    ShadowActivity shadowActivity = shadowOf(mTestActivity);
    shadowActivity.grantPermissions("android.permission.ACCESS_FINE_LOCATION");
    LocationManager locationManager = (LocationManager) mTestActivity.getSystemService(Context.LOCATION_SERVICE);
    ShadowLocationManager shadowLocationManager = shadowOf(locationManager);
    Location location = new Location("");
    location.setLatitude(1.0);
    location.setLongitude(2.0);
    location.setAccuracy(3F);
    location.setTime(System.currentTimeMillis() - 4000);
    shadowLocationManager.setLastKnownLocation("gps", location);
    ManagersResolver.getInstance().dispose();
    ManagersResolver.getInstance().prepare(mTestActivity);
    JSONObject locationJson = new JSONObject();
    locationJson.put(LOCATION_LAT, 1.0);
    locationJson.put(LOCATION_LON, 2.0);
    locationJson.put(LOCATION_TYPE, 1);
    locationJson.put(LOCATION_ACCURACY, 3F);
    locationJson.put(LOCATION_LASTFIX, (long) 4);
    assertEquals(locationJson.toString(), mSpyBaseJSInterface.getLocation());
}
Also used : ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) LocationManager(android.location.LocationManager) JSONObject(org.json.JSONObject) ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) ShadowActivity(org.robolectric.shadows.ShadowActivity) Location(android.location.Location) Test(org.junit.Test)

Example 2 with ShadowLocationManager

use of org.robolectric.shadows.ShadowLocationManager 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 3 with ShadowLocationManager

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

the class GeoLocationParameterBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    Activity robolectricActivity = Robolectric.buildActivity(Activity.class).create().get();
    ShadowActivity shadowActivity = shadowOf(robolectricActivity);
    shadowActivity.grantPermissions("android.permission.ACCESS_FINE_LOCATION");
    LocationManager locationManager = (LocationManager) robolectricActivity.getSystemService(Context.LOCATION_SERVICE);
    ShadowLocationManager shadowLocationManager = shadowOf(locationManager);
    Location location = new Location("");
    location.setLatitude(LATITUDE);
    location.setLongitude(LONGITUDE);
    shadowLocationManager.setLastKnownLocation("gps", location);
    ManagersResolver.getInstance().prepare(robolectricActivity);
}
Also used : ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) LocationManager(android.location.LocationManager) ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) ShadowActivity(org.robolectric.shadows.ShadowActivity) Activity(android.app.Activity) ShadowActivity(org.robolectric.shadows.ShadowActivity) Location(android.location.Location) Before(org.junit.Before)

Aggregations

Location (android.location.Location)3 LocationManager (android.location.LocationManager)3 ShadowActivity (org.robolectric.shadows.ShadowActivity)3 ShadowLocationManager (org.robolectric.shadows.ShadowLocationManager)3 Activity (android.app.Activity)2 Before (org.junit.Before)2 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1 BidRequest (org.prebid.mobile.rendering.models.openrtb.BidRequest)1 AdRequestInput (org.prebid.mobile.rendering.networking.parameters.AdRequestInput)1 ShadowTelephonyManager (org.robolectric.shadows.ShadowTelephonyManager)1