Java Code Examples for org.robolectric.shadows.ShadowActivity#getNextStartedActivity()

The following examples show how to use org.robolectric.shadows.ShadowActivity#getNextStartedActivity() . 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: IntentsTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,114.1043205";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

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

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

    assertThat(result).isTrue();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
Example 2
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 3
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 4
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 5
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 6
Source File: CaseLoadUtils.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public static EntitySelectActivity launchEntitySelectActivity(String command) {
    ShadowActivity shadowHomeActivity =
            ActivityLaunchUtils.buildHomeActivityForFormEntryLaunch(command);

    Intent entitySelectIntent = shadowHomeActivity.getNextStartedActivity();

    String intentActivityName = entitySelectIntent.getComponent().getClassName();
    Assert.assertEquals(EntitySelectActivity.class.getName(), intentActivityName);

    // start the entity select activity
    return Robolectric.buildActivity(EntitySelectActivity.class, entitySelectIntent)
            .setup().get();
}
 
Example 7
Source File: RecoveryMeasuresTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void executeRecoveryMeasuresActivity_ShouldGetLaunched_WhenRecoveryMeasuresArePending() {
    requestRecoveryMeasures(REINSTALL_AND_UPDATE_VALID_FOR_CURRENT_APP_VERSION);

    // Set resources as valid so that dispatch doesn't fire VerificationActivity
    CommCareApplication.instance().getCurrentApp().getAppRecord().setResourcesStatus(true);
    ActivityController<DispatchActivity> dispatchActivityController
            = Robolectric.buildActivity(DispatchActivity.class).create().resume().start();

    DispatchActivity dispatchActivity = dispatchActivityController.get();
    ShadowActivity shadowDispatchActivity = Shadows.shadowOf(dispatchActivity);

    // Verify that Dispatch fires HomeActivity
    Intent homeActivityIntent = shadowDispatchActivity.getNextStartedActivity();
    String intentActivityName = homeActivityIntent.getComponent().getClassName();
    assertTrue(intentActivityName.contentEquals(StandardHomeActivity.class.getName()));

    // launch home activty
    StandardHomeActivity homeActivity =
            Robolectric.buildActivity(StandardHomeActivity.class, homeActivityIntent)
                    .create().start().resume().get();
    ShadowActivity shadowHomeActivity = Shadows.shadowOf(homeActivity);

    // Verify HomeActivity finishes since recovery measures are pending
    assertTrue(shadowHomeActivity.isFinishing());

    shadowDispatchActivity.receiveResult(homeActivityIntent,
            shadowHomeActivity.getResultCode(),
            shadowHomeActivity.getResultIntent());

    // Verify that Dispatch fires up the ExecuteRecoveryMeasuresActivity this time
    dispatchActivityController.resume();
    Intent executeRecoveryMeasuresActivityIntent = shadowDispatchActivity.getNextStartedActivity();
    intentActivityName  = executeRecoveryMeasuresActivityIntent.getComponent().getClassName();
    assertTrue(intentActivityName.contentEquals(ExecuteRecoveryMeasuresActivity.class.getName()));
}
 
Example 8
Source File: IntentCalloutTests.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test different behaviors for possibly grouped intent callout views
 */
@Test
public void testIntentCalloutWithDataXPath() {
    ShadowActivity shadowActivity =
            ActivityLaunchUtils.buildHomeActivityForFormEntryLaunch("m0-f0");
    Intent formEntryIntent = shadowActivity.getNextStartedActivity();

    FormEntryActivity formEntryActivity = navigateFormStructure(formEntryIntent);

    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:1234567890");
    Assert.assertEquals(intent.getAction(), "android.intent.action.CALL");
}
 
Example 9
Source File: FormIntentTests.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test different behaviors for possibly grouped intent callout views
 */
@Test
public void testIntentCalloutAggregation() {
    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()));

    navigateFormStructure(formEntryIntent);
}
 
Example 10
Source File: HomeActivityTest.java    From Inside_Android_Testing with Apache License 2.0 5 votes vote down vote up
@Test
public void pressingTheButtonShouldStartTheSignInActivity() throws Exception {
    trackerRecentActivityButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);

    assertThat(shadowIntent.getComponent().getClassName(), equalTo(RecentActivityActivity.class.getName()));
}
 
Example 11
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 12
Source File: RecoveryMeasuresTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void ccUpdateMeasure_ShouldlaunchAokUpdatePrompt() {
    requestRecoveryMeasures(CC_UPDATE_VALID);
    ShadowActivity shadowRecoveryMeasuresActivity = launchRecoveryMeasuresActivity();
    Intent intent = shadowRecoveryMeasuresActivity.getNextStartedActivity();
    assertTrue(getIntentActivityName(intent).contentEquals(PromptApkUpdateActivity.class.getName()));
}
 
Example 13
Source File: RideRequestActivityBehaviorTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onRequestRide_shouldLaunchActivity() {
    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);
    RideRequestActivityBehavior behavior = new RideRequestActivityBehavior(activity, 4005,
            new SessionConfiguration.Builder().setClientId("clientId").build());
    behavior.requestRide(activity, new RideParameters.Builder().build());
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertThat(startedIntent.getComponent().getClassName()).isEqualTo(RideRequestActivity.class.getName());
}
 
Example 14
Source File: RideRequestViewTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void shouldOverrideUrlLoading_whenNonHttpOrRedirect_shouldOverrideAndLaunchActivity() {
    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);
    RideRequestView rideRequestView = new RideRequestView(activity);

    client = rideRequestView.new RideRequestWebViewClient(callback);

    assertTrue(client.shouldOverrideUrlLoading(mock(WebView.class), "tel:+91555555555"));
    verifyZeroInteractions(callback);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(Intent.ACTION_VIEW, startedIntent.getAction());
    assertEquals("tel:+91555555555#Intent;action=android.intent.action.VIEW;end", startedIntent.toUri(0));
}
 
Example 15
Source File: IntentCalloutTests.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntentCalloutNoData() {
    ShadowActivity shadowActivity =
            ActivityLaunchUtils.buildHomeActivityForFormEntryLaunch("m0-f2");
    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(), null);
    Assert.assertEquals(intent.getAction(), "android.intent.action.CALL");
}
 
Example 16
Source File: BudgetActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void clickOnBudget()
{
    ActivityController activityController = Robolectric.buildActivity(BudgetActivity.class).create();
    Activity activity = (Activity)activityController.get();

    DBHelper db = new DBHelper(activity);
    db.insertBudget("name", 100);
    db.close();

    activityController.start();
    activityController.resume();

    ListView list = (ListView)activity.findViewById(R.id.list);

    ShadowListView shadowList = shadowOf(list);
    shadowList.populateItems();
    shadowList.performItemClick(0);

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

    ComponentName name = startedIntent.getComponent();
    assertEquals("protect.budgetwatch/.TransactionActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    String budget = bundle.getString("budget");
    assertEquals("name", budget);
}
 
Example 17
Source File: CalendarLocaleTest.java    From commcare-android with Apache License 2.0 5 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 testNepaliEthiopianCalendar() {
    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()));

    navigateCalendarForm(formEntryIntent);
}
 
Example 18
Source File: NoInternetActivityTest.java    From ello-android with MIT License 5 votes vote down vote up
@Test
public void tapRefreshStartsMainActivityWhenInternetPresent()
{
    when(reachability.isNetworkConnected()).thenReturn(true);

    ShadowActivity shadowActivity = shadowOf(activity);
    button.performClick();
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(startedIntent.getComponent().getClassName(),
            equalTo(MainActivity.class.getName()));
}
 
Example 19
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 20
Source File: PostRequestActivityTest.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
/**
 * Launch post request through session dispatch
 */
@Test
public void makeSuccessfulPostRequestTest() {
    ModernHttpRequesterMock.setResponseCodes(new Integer[]{200});
    CommcareRequestEndpointsMock.setCaseFetchResponseCodes(new Integer[]{200});
    LocalReferencePullResponseFactory.setRequestPayloads(new String[]{"jr://resource/commcare-apps/case_search_and_claim/empty_restore.xml"});

    AndroidSessionWrapper sessionWrapper =
            CommCareApplication.instance().getCurrentSessionWrapper();
    CommCareSession session = sessionWrapper.getSession();
    session.setCommand("patient-search");
    InputStream is =
            PostRequestActivity.class.getClassLoader().getResourceAsStream("commcare-apps/case_search_and_claim/good-query-result.xml");

    RemoteQuerySessionManager remoteQuerySessionManager =
            RemoteQuerySessionManager.buildQuerySessionManager(sessionWrapper.getSession(),
                    sessionWrapper.getEvaluationContext());
    Pair<ExternalDataInstance, String> instanceOrError =
            remoteQuerySessionManager.buildExternalDataInstance(is);
    session.setQueryDatum(instanceOrError.first);
    session.setDatum("case_id", "321");

    ShadowActivity shadowActivity =
            ActivityLaunchUtils.buildHomeActivity();

    Intent postActivityIntent = shadowActivity.getNextStartedActivity();

    String intentActivityName = postActivityIntent.getComponent().getClassName();
    assertTrue(intentActivityName.equals(PostRequestActivity.class.getName()));

    assertEquals("https://www.fake.com/claim_patient/", postActivityIntent.getSerializableExtra(PostRequestActivity.URL_KEY).toString());
    HashMap<String, String> postUrlParams =
            (HashMap<String, String>)postActivityIntent.getSerializableExtra(PostRequestActivity.PARAMS_KEY);
    assertEquals("321", postUrlParams.get("selected_case_id"));

    PostRequestActivity postRequestActivity =
            Robolectric.buildActivity(PostRequestActivity.class, postActivityIntent)
                    .create().start().resume().get();

    assertTrue(postRequestActivity.isFinishing());
}