Search in sources :

Example 56 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity 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 57 with ShadowActivity

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

the class MraidCalendarEventTest method testCreateCalendarEvent.

@Test
public void testCreateCalendarEvent() {
    BaseJSInterface mockJs = mock(BaseJSInterface.class);
    MraidCalendarEvent event = new MraidCalendarEvent(mockJs);
    event.createCalendarEvent(mCalendarParameters);
    ShadowActivity shadowActivity = shadowOf(mTestActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertFalse("somecrap.calendar/event".equals(startedIntent.getType()));
    assertEquals("vnd.android.cursor.item/event", startedIntent.getType());
    assertFalse("fail.event.type".equals(startedIntent.getType()));
    assertEquals("", startedIntent.getExtras().get(CalendarContract.Events.TITLE));
    assertTrue(startedIntent.getExtras().get(CalendarContract.Events.DESCRIPTION).equals("mayanApocalypse/End of world"));
}
Also used : BaseJSInterface(org.prebid.mobile.rendering.views.webview.mraid.BaseJSInterface) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test)

Example 58 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity 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 59 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project android_packages_apps_Settings by crdroidandroid.

the class ChooseLockSettingsHelperTest method testLaunchConfirmationActivityWithExternalAndChallenge.

@Test
public void testLaunchConfirmationActivityWithExternalAndChallenge() {
    final int userId = UserHandle.myUserId();
    final int request = 100;
    final long challenge = 10000L;
    final Activity activity = Robolectric.setupActivity(Activity.class);
    ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
    helper.launchConfirmationActivityWithExternalAndChallenge(// request
    request, "title", "header", "description", // external
    true, challenge, userId);
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(new ComponentName("com.android.settings", ConfirmLockPattern.InternalActivity.class.getName()), startedIntent.getComponent());
    assertFalse(startedIntent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_RETURN_CREDENTIALS, false));
    assertTrue(startedIntent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false));
    assertEquals(challenge, startedIntent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0L));
    assertEquals(true, (startedIntent.getFlags() & Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0);
    assertEquals(true, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.ALLOW_FP_AUTHENTICATION, false));
    assertEquals(true, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, false));
    assertEquals(true, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.SHOW_CANCEL_BUTTON, false));
    assertEquals(true, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, false));
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) Activity(android.app.Activity) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 60 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project android_packages_apps_Settings by crdroidandroid.

the class FingerprintEnrollFindSensorTest method clickSkip_shouldReturnResultSkip.

@Test
public void clickSkip_shouldReturnResultSkip() {
    Button skipButton = mActivity.findViewById(R.id.skip_button);
    skipButton.performClick();
    ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
    assertThat(shadowActivity.getResultCode()).named("result code").isEqualTo(FingerprintEnrollBase.RESULT_SKIP);
}
Also used : Button(android.widget.Button) ShadowActivity(org.robolectric.shadows.ShadowActivity) Test(org.junit.Test)

Aggregations

ShadowActivity (org.robolectric.shadows.ShadowActivity)343 Test (org.junit.Test)330 Intent (android.content.Intent)163 ComponentName (android.content.ComponentName)100 Button (android.widget.Button)67 Config (org.robolectric.annotation.Config)53 IntentForResult (org.robolectric.shadows.ShadowActivity.IntentForResult)53 Activity (android.app.Activity)41 EnrollmentCallback (android.hardware.fingerprint.FingerprintManager.EnrollmentCallback)33 Bundle (android.os.Bundle)32 PartnerCustomizationLayout (com.google.android.setupcompat.PartnerCustomizationLayout)30 FooterBarMixin (com.google.android.setupcompat.template.FooterBarMixin)20 FragmentActivity (androidx.fragment.app.FragmentActivity)11 Tile (com.android.settingslib.drawer.Tile)11 Settings (com.android.settings.Settings)10 ContextualCardsFragment (com.android.settings.homepage.contextualcards.ContextualCardsFragment)10 IntentBuilder (com.android.settings.password.ChooseLockPassword.IntentBuilder)7 SetupChooseLockPasswordFragment (com.android.settings.password.SetupChooseLockPassword.SetupChooseLockPasswordFragment)7 ShadowIntent (org.robolectric.shadows.ShadowIntent)7 Preference (android.support.v7.preference.Preference)6