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());
}
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();
}
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);
}
Aggregations