org.robolectric.shadows.ShadowActivity Java Examples

The following examples show how to use org.robolectric.shadows.ShadowActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WelcomeBackPasswordPromptTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInButton_validatesFields() {
    WelcomeBackPasswordPrompt welcomeBack = createActivity();
    Button signIn = welcomeBack.findViewById(R.id.button_done);
    signIn.performClick();
    TextInputLayout passwordLayout =
            welcomeBack.findViewById(R.id.password_layout);

    assertEquals(
            welcomeBack.getString(R.string.fui_error_invalid_password),
            passwordLayout.getError().toString());

    // should block and not start a new activity
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(welcomeBack).getNextStartedActivityForResult();
    assertNull(nextIntent);
}
 
Example #2
Source File: InterstitialAdViewLoadAdTest.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testANInterstitialWithoutAutoDismissAdDelay() {

    setInterstitialShowonLoad(true);
    setAutoDismissDelay(false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.banner())); // First queue a regular HTML banner response
    assertTrue(interstitialAdView.getAdType() == AdType.UNKNOWN); // First tests if ad_type is UNKNOWN initially
    executeInterstitialRequest();

    //Checking if onAdLoaded is called or not
    assertTrue(adLoaded);


    //Creating shadow of the required activity
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    //Checking if an AdActivity is opened or not
    assertEquals(AdActivity.class.getCanonicalName(), startedIntent.getComponent().getClassName());

    //Checking if an INTENT_KEY_ACTIVITY_TYPE is equivalent to INTERSTITIAL or not
    assertEquals(startedIntent.getStringExtra(INTENT_KEY_ACTIVITY_TYPE), ACTIVITY_TYPE_INTERSTITIAL);

    //Checking if an INTENT_KEY_AUTODISMISS_DELAY is equual to 5 or not
    assertEquals(startedIntent.getIntExtra(INTENT_KEY_AUTODISMISS_DELAY, 0), -1);
}
 
Example #3
Source File: FormRecordProcessingTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void fillOutFormWithCaseUpdate() {
    StandardHomeActivity homeActivity = buildHomeActivityForFormEntryLaunch();

    ShadowActivity shadowActivity = Shadows.shadowOf(homeActivity);
    Intent formEntryIntent = shadowActivity.getNextStartedActivity();

    // make sure the form entry activity should be launched
    String intentActivityName = formEntryIntent.getComponent().getClassName();
    assertTrue(intentActivityName.equals(FormEntryActivity.class.getName()));

    ShadowActivity shadowFormEntryActivity = navigateFormEntry(formEntryIntent);

    // trigger CommCareHomeActivity.onActivityResult for the completion of
    // FormEntryActivity
    shadowActivity.receiveResult(formEntryIntent,
            shadowFormEntryActivity.getResultCode(),
            shadowFormEntryActivity.getResultIntent());
    assertStoredFroms();
}
 
Example #4
Source File: BaseFragmentActivityTest.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * Testing overall lifecycle and setup
 */
@Test
public void lifecycleTest() {
    ActivityController<? extends BaseFragmentActivity> controller =
            Robolectric.buildActivity(getActivityClass(), getIntent());
    BaseFragmentActivity activity = controller.get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);

    controller.create().start();
    // Action bar state initialization
    ActionBar bar = activity.getSupportActionBar();
    if (bar != null) {
        int displayOptions = bar.getDisplayOptions();
        assertTrue((displayOptions & ActionBar.DISPLAY_HOME_AS_UP) > 0);
        assertTrue((displayOptions & ActionBar.DISPLAY_SHOW_HOME) > 0);
        assertTrue(null == activity.findViewById(android.R.id.home));
    }

    controller.postCreate(null).resume().postResume().visible();

    // Action bar home button
    assertTrue(shadowActivity.clickMenuItem(android.R.id.home));
    activity.finish();
    assertThat(activity).isFinishing();
}
 
Example #5
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onLoginLoad_withEmptyScopes_shouldReturnErrorResultIntent() {
    Intent intent = new Intent();
    intent.putExtra(LoginActivity.EXTRA_SESSION_CONFIGURATION, new SessionConfiguration.Builder().setClientId(CLIENT_ID).build());

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class)
            .withIntent(intent)
            .create();

    ShadowActivity shadowActivity = shadowOf(controller.get());

    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(getErrorFromIntent(shadowActivity.getResultIntent()))
            .isEqualTo(AuthenticationError.INVALID_SCOPE);
    assertThat(shadowActivity.isFinishing()).isTrue();
}
 
Example #6
Source File: FormRecordListActivityTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public static void openASavedForm(int expectedFormCount, int formIndexToSelect) {
    Intent savedFormsIntent =
            new Intent(RuntimeEnvironment.application, FormRecordListActivity.class);
    ShadowActivity homeActivityShadow = prepSavedFormsActivity(savedFormsIntent);

    FormRecordListActivity savedFormsActivity =
            Robolectric.buildActivity(FormRecordListActivity.class, savedFormsIntent)
                    .create().start()
                    .resume().get();

    // wait for saved forms to load
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();

    ShadowListView shadowEntityList = assertSavedFormEntries(expectedFormCount, savedFormsActivity);
    shadowEntityList.performItemClick(formIndexToSelect);

    launchFormEntryForSavedForm(homeActivityShadow, savedFormsIntent, savedFormsActivity);
}
 
Example #7
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onLoginLoad_withNullResponseType_shouldReturnErrorResultIntent() {
    Intent intent = new Intent();
    intent.putExtra(LoginActivity.EXTRA_SESSION_CONFIGURATION, loginConfiguration);
    intent.putExtra(LoginActivity.EXTRA_RESPONSE_TYPE, (ResponseType) null);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class)
            .withIntent(intent)
            .create();

    ShadowActivity shadowActivity = shadowOf(controller.get());

    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(getErrorFromIntent(shadowActivity.getResultIntent()))
            .isEqualTo(AuthenticationError.INVALID_RESPONSE_TYPE);
    assertThat(shadowActivity.isFinishing()).isTrue();
}
 
Example #8
Source File: FormRecordListActivityTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private static void launchFormEntryForSavedForm(ShadowActivity homeActivityShadow,
                                                Intent savedFormsIntent,
                                                FormRecordListActivity savedFormsActivity) {

    ShadowActivity formRecordShadow = Shadows.shadowOf(savedFormsActivity);
    homeActivityShadow.receiveResult(savedFormsIntent,
            formRecordShadow.getResultCode(),
            formRecordShadow.getResultIntent());
    ShadowActivity.IntentForResult formEntryIntent =
            homeActivityShadow.getNextStartedActivityForResult();
    Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent.intent)
                    .create().start().resume().get();

    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();

    assertNotNull(FormEntryActivity.mFormController);
}
 
Example #9
Source File: MultimediaInflaterActivityTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure user sees invalid path toast when the file browser doesn't return a path uri
 */
@Test
public void emptyFileSelectionTest() {
    MultimediaInflaterActivity multimediaInflaterActivity =
            Robolectric.buildActivity(MultimediaInflaterActivity.class)
                    .create().start().resume().get();

    ImageButton selectFileButton =
            multimediaInflaterActivity.findViewById(
                    R.id.screen_multimedia_inflater_filefetch);
    selectFileButton.performClick();

    Intent fileSelectIntent = new Intent(Intent.ACTION_GET_CONTENT);
    fileSelectIntent.setType("application/zip");

    Intent emptyFileSelectResult = new Intent();

    ShadowActivity shadowActivity =
            Shadows.shadowOf(multimediaInflaterActivity);
    shadowActivity.receiveResult(fileSelectIntent,
            Activity.RESULT_OK,
            emptyFileSelectResult);

    Assert.assertEquals(Localization.get("file.invalid.path"),
            ShadowToast.getTextOfLatestToast());
}
 
Example #10
Source File: BaseActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void finish_finishesWithException() {
    Exception exception = new Exception("Error message");
    setup(new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .getIntent(RuntimeEnvironment.application));

    mActivity.finish(exception);

    ShadowActivity shadowActivity = shadowOf(mActivity);
    assertTrue(mActivity.isFinishing());
    assertEquals(RESULT_FIRST_USER, shadowActivity.getResultCode());
    Exception error = (Exception) shadowActivity.getResultIntent()
            .getSerializableExtra(DropInActivity.EXTRA_ERROR);
    assertNotNull(error);
    assertEquals("Error message", error.getMessage());
}
 
Example #11
Source File: BaseActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void finish_finishesWithPaymentMethodNonceAndDeviceDataInDropInResult()
        throws JSONException {
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));
    setup(new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .getIntent(RuntimeEnvironment.application));

    mActivity.finish(cardNonce, "device_data");

    ShadowActivity shadowActivity = shadowOf(mActivity);
    assertTrue(mActivity.isFinishing());
    assertEquals(RESULT_OK, shadowActivity.getResultCode());
    DropInResult result = shadowActivity.getResultIntent()
            .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
    assertNotNull(result);
    assertEquals(cardNonce.getNonce(), result.getPaymentMethodNonce().getNonce());
    assertEquals("device_data", result.getDeviceData());
}
 
Example #12
Source File: PictureResizeDialogTest.java    From Onosendai with Apache License 2.0 6 votes vote down vote up
@Test
public void itCanBeCancelled () throws Exception {
	this.alert.show();

	assertTrue(this.shadowAlert.isCancelable());
	assertFalse(this.shadowAlert.hasBeenDismissed());

	this.alert.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
	assertTrue(this.shadowAlert.hasBeenDismissed());

	assertEquals(0, this.okClick.get());
	assertEquals(1, this.cancelClick.get());

	final ShadowActivity shadowActivity = Robolectric.shadowOf(this.activity);
	assertNull(shadowActivity.getNextStartedActivity());
}
 
Example #13
Source File: InterstitialAdViewLoadAdTest.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testANInterstitialWithAutoDismissAdDelay() throws InterruptedException {

    setInterstitialShowonLoad(true);
    setAutoDismissDelay(true);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.banner())); // First queue a regular HTML banner response
    assertTrue(interstitialAdView.getAdType() == AdType.UNKNOWN); // First 2tests if ad_type is UNKNOW initially
    executeInterstitialRequest();

    //Checking if onAdLoaded is called or not
    assertTrue(adLoaded);

    //Creating shadow of the required activity
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    //Checking if an AdActivity is opened or not
    assertEquals(AdActivity.class.getCanonicalName(), startedIntent.getComponent().getClassName());

    //Checking if an INTENT_KEY_ACTIVITY_TYPE is equivalent to INTERSTITIAL or not
    assertEquals(startedIntent.getStringExtra(INTENT_KEY_ACTIVITY_TYPE), ACTIVITY_TYPE_INTERSTITIAL);

    //Checking if an INTENT_KEY_AUTODISMISS_DELAY is equual to 5 or not
    assertEquals(startedIntent.getIntExtra(INTENT_KEY_AUTODISMISS_DELAY, 0), 5);
}
 
Example #14
Source File: IntentsTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_false_when_nothing_on_the_device_can_open_the_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), (ResolveInfo) null);

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isFalse();
    assertThat(startedIntent).isNull();
}
 
Example #15
Source File: EndOfFormTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private static ShadowActivity navigateFormEntry(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();



    // enter an answer for the question
    QuestionsView questionsView = formEntryActivity.getODKView();
    IntegerWidget favoriteNumber = (IntegerWidget)questionsView.getWidgets().get(0);
    favoriteNumber.setAnswer("2");
    View finishButton = formEntryActivity.findViewById(R.id.nav_btn_finish);
    finishButton.performClick();

    ShadowActivity shadowFormEntryActivity = Shadows.shadowOf(formEntryActivity);
    while (!shadowFormEntryActivity.isFinishing()) {
        Log.d(TAG, "Waiting for the form to save and the form entry activity to finish");
    }

    return shadowFormEntryActivity;
}
 
Example #16
Source File: EndOfFormTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Test filling out and saving a form ending in a hidden repeat group. This
 * type of form exercises uncommon end-of-form code paths
 */
@Test
public void testHiddenRepeatAtEndOfForm() {
    ShadowActivity shadowActivity =
            ActivityLaunchUtils.buildHomeActivityForFormEntryLaunch("m0-f0");

    Intent formEntryIntent = shadowActivity.getNextStartedActivity();

    // make sure the form entry activity should be launched
    String intentActivityName = formEntryIntent.getComponent().getClassName();
    assertTrue(intentActivityName.equals(FormEntryActivity.class.getName()));

    ShadowActivity shadowFormEntryActivity = navigateFormEntry(formEntryIntent);

    // trigger CommCareHomeActivity.onActivityResult for the completion of
    // FormEntryActivity
    shadowActivity.receiveResult(formEntryIntent,
            shadowFormEntryActivity.getResultCode(),
            shadowFormEntryActivity.getResultIntent());
    assertStoredForms();
}
 
Example #17
Source File: FinishWithResultActivityTest.java    From OpenYOLO-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void startActivity_withResult_finishesWithResult() {
    int givenResultCode = 0x2c001;
    Intent givenIntent =
            new HintRetrieveResult.Builder(givenResultCode).build().toResultDataIntent();
    Intent intent = FinishWithResultActivity.createIntent(
            CONTEXT,
            ActivityResult.of(givenResultCode, givenIntent));

    ShadowActivity activity = startActivity(intent);

    assertThat(activity.isFinishing()).isTrue();
    HintRetrieveResult result =
            CredentialClient.getInstance(CONTEXT)
                    .getHintRetrieveResult(activity.getResultIntent());
    assertThat(result.getResultCode()).isEqualTo(givenResultCode);
    assertThat(activity.getResultCode()).isEqualTo(givenResultCode);
}
 
Example #18
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomAuthMethodPickerLayout() {
    List<String> providers = Arrays.asList(EmailAuthProvider.PROVIDER_ID);

    AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
            .Builder(R.layout.fui_provider_button_email)
            .setEmailButtonId(R.id.email_button)
            .build();

    AuthMethodPickerActivity authMethodPickerActivity = createActivityWithCustomLayout(providers, customLayout);

    Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button);
    emailButton.performClick();

    //Expected result -> Directing users to EmailActivity
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
    assertEquals(
            EmailActivity.class.getName(),
            nextIntent.intent.getComponent().getClassName());
}
 
Example #19
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomAuthMethodPickerLayoutWithEmailLink() {
    List<String> providers = Arrays.asList(EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD);

    AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
            .Builder(R.layout.fui_provider_button_email)
            .setEmailButtonId(R.id.email_button)
            .build();

    AuthMethodPickerActivity authMethodPickerActivity = createActivityWithCustomLayout(providers, customLayout);

    Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button);
    emailButton.performClick();

    //Expected result -> Directing users to EmailActivity
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
    assertEquals(
            EmailActivity.class.getName(),
            nextIntent.intent.getComponent().getClassName());
}
 
Example #20
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onTokenReceived_shouldReturnAccessTokenResult() {
    String tokenString = "accessToken1234";

    String redirectUrl = REDIRECT_URI + "?access_token=accessToken1234&expires_in=" + 2592000
            + "&scope=history&refresh_token=refreshToken1234&token_type=bearer";

    ShadowActivity shadowActivity = shadowOf(loginActivity);
    loginActivity.onTokenReceived(Uri.parse(redirectUrl));

    assertNotNull(shadowActivity.getResultIntent());
    assertEquals(shadowActivity.getResultCode(), Activity.RESULT_OK);

    AccessToken resultAccessToken =
            AuthUtils.createAccessToken(shadowActivity.getResultIntent());

    assertEquals(resultAccessToken.getExpiresIn(), 2592000);
    assertEquals(resultAccessToken.getToken(), tokenString);
    assertEquals(resultAccessToken.getScopes().size(), 1);
    assertTrue(resultAccessToken.getScopes().contains(Scope.HISTORY));
    assertThat(shadowActivity.isFinishing()).isTrue();
}
 
Example #21
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onLoginLoad_withSsoEnabled_andNotSupported_shouldReturnErrorResultIntent() {
    Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), productPriority,
            loginConfiguration, ResponseType.TOKEN, false, true, true);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent);
    loginActivity = controller.get();
    loginActivity.ssoDeeplinkFactory = ssoDeeplinkFactory;
    ShadowActivity shadowActivity = shadowOf(loginActivity);
    when(ssoDeeplink.isSupported(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK)).thenReturn(false);

    controller.create();

    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(getErrorFromIntent(shadowActivity.getResultIntent()))
            .isEqualTo(AuthenticationError.INVALID_REDIRECT_URI);
    assertThat(shadowActivity.isFinishing()).isTrue();
}
 
Example #22
Source File: IntentsTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_start_external_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    Intents.startExternalUrl(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
Example #23
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testPhoneLoginFlow() {
    List<String> providers = Arrays.asList(PhoneAuthProvider.PROVIDER_ID);

    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);

    Button phoneButton = authMethodPickerActivity.findViewById(R.id.phone_button);
    phoneButton.performClick();
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();

    assertEquals(
            PhoneActivity.class.getName(),
            nextIntent.intent.getComponent().getClassName());
}
 
Example #24
Source File: BaseFragmentActivityTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Generic method for asserting pending transition animation
 *
 * @param shadowActivity The shadow activity
 * @param enterAnim      The enter animation resource
 * @param exitAnim       The exit animation resource
 */
private static void assertOverridePendingTransition(ShadowActivity shadowActivity,
                                                    @AnimRes int enterAnim, @AnimRes int exitAnim) {
    assertEquals(enterAnim, shadowActivity
            .getPendingTransitionEnterAnimationResourceId());
    assertEquals(exitAnim, shadowActivity
            .getPendingTransitionExitAnimationResourceId());
}
 
Example #25
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmailLoginFlow() {
    List<String> providers = Arrays.asList(EmailAuthProvider.PROVIDER_ID);

    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);

    Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button);
    emailButton.performClick();
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();

    assertEquals(
            EmailActivity.class.getName(),
            nextIntent.intent.getComponent().getClassName());
}
 
Example #26
Source File: BaseFragmentActivityTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Generic method for asserting next started activity along with
 * the custom transition animation override
 *
 * @param currentActivity   The current activity
 * @param nextActivityClass The class of the newly started activity
 */
protected Intent assertNextStartedActivity(BaseFragmentActivity currentActivity,
                                           Class<? extends Activity> nextActivityClass) {
    ShadowActivity shadowActivity = Shadows.shadowOf(currentActivity);
    Intent intent = shadowActivity.getNextStartedActivity();
    assertNotNull(intent);
    assertThat(intent).hasComponent(currentActivity, nextActivityClass);
    return intent;
}
 
Example #27
Source File: BaseActivityTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onOptionsItemSelected_shouldOpenAboutPage() throws Exception {
    MenuItem menuItem = menu.findItem(R.id.about);
    activity.onOptionsItemSelected(menuItem);
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(shadowIntent.getData()).isEqualTo(Uri.parse("https://mapzen.com/open/about"));
}
 
Example #28
Source File: FormRecordProcessingTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private ShadowActivity navigateFormEntry(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();

    // enter an answer for the question
    QuestionsView questionsView = formEntryActivity.getODKView();
    IntegerWidget cohort = (IntegerWidget)questionsView.getWidgets().get(0);
    cohort.setAnswer("2");

    ImageButton nextButton = formEntryActivity.findViewById(R.id.nav_btn_next);
    nextButton.performClick();
    View finishButton = formEntryActivity.findViewById(R.id.nav_btn_finish);
    finishButton.performClick();

    ShadowActivity shadowFormEntryActivity = Shadows.shadowOf(formEntryActivity);

    long waitStartTime = new Date().getTime();
    while (!shadowFormEntryActivity.isFinishing()) {
        Log.d(TAG, "Waiting for the form to save and the form entry activity to finish");
        if ((new Date().getTime()) - waitStartTime > 5000) {
            Assert.fail("form entry activity took too long to finish");
        }
    }

    return shadowFormEntryActivity;
}
 
Example #29
Source File: IntentCalloutTests.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntentCalloutHardCodedData() {
    ShadowActivity shadowActivity =
            ActivityLaunchUtils.buildHomeActivityForFormEntryLaunch("m0-f3");
    Intent formEntryIntent = shadowActivity.getNextStartedActivity();
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();
    IntentWidget phoneCallWidget = (IntentWidget) formEntryActivity.getODKView().getWidgets().get(0);
    Intent intent = phoneCallWidget.getIntentCallout().generate(FormEntryActivity.mFormController.getFormEntryController().getModel().getForm().getEvaluationContext());
    Assert.assertEquals(intent.getData().toString(), "tel:3333333333");
    Assert.assertEquals(intent.getAction(), "android.intent.action.CALL");
}
 
Example #30
Source File: CommCareSetupActivityTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test that trying to install an app with an invalid suite file results in
 * the appropriate error message and a pinned notification with more
 * details
 */
@Test
public void invalidAppInstall() {
    String invalidUpdateReference = "jr://resource/commcare-apps/update_tests/invalid_suite_update/profile.ccpr";


    // start the setup activity
    Intent setupIntent =
            new Intent(RuntimeEnvironment.application, CommCareSetupActivity.class);

    CommCareSetupActivity setupActivity =
            Robolectric.buildActivity(CommCareSetupActivity.class, setupIntent)
                    .setup().get();

    // click the 'offline install' menu item
    ShadowActivity shadowActivity = Shadows.shadowOf(setupActivity);
    shadowActivity.clickMenuItem(CommCareSetupActivity.MENU_ARCHIVE);

    // make sure there are no pinned notifications
    NotificationManager notificationManager =
            (NotificationManager)RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = Shadows.shadowOf(notificationManager).getNotification(CommCareNoficationManager.MESSAGE_NOTIFICATION);
    assertNull(notification);

    // mock receiving the offline app reference and start the install
    Intent referenceIntent = new Intent();
    referenceIntent.putExtra(InstallArchiveActivity.ARCHIVE_JR_REFERENCE, invalidUpdateReference);
    shadowActivity.receiveResult(shadowActivity.getNextStartedActivity(), Activity.RESULT_OK, referenceIntent);

    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();

    // assert that we get the right error message
    assertTrue(setupActivity.getErrorMessageToDisplay().contains(Localization.get("notification.install.invalid.title")));

    // check that a pinned notification was created for invalid update
    // NOTE: it is way more work to assert the notification body is correct, so skip over that
    notification = Shadows.shadowOf(notificationManager).getNotification(CommCareNoficationManager.MESSAGE_NOTIFICATION);
    assertNotNull(notification);
}