Search in sources :

Example 6 with ShadowApplication

use of org.robolectric.shadows.ShadowApplication in project DeepLinkDispatch by airbnb.

the class MainActivityTest method testTaskStackBuilderIntents.

@Test
public void testTaskStackBuilderIntents() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com/deepLink/testid/testname/testplace"));
    DeepLinkActivity deepLinkActivity = Robolectric.buildActivity(DeepLinkActivity.class).withIntent(intent).create().get();
    ShadowApplication shadowApplication = shadowOf(RuntimeEnvironment.application);
    Intent launchedIntent = shadowApplication.getNextStartedActivity();
    assertNotNull(launchedIntent);
    assertThat(launchedIntent.getComponent(), equalTo(new ComponentName(deepLinkActivity, SecondActivity.class)));
    assertThat(launchedIntent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false), equalTo(true));
    assertThat(launchedIntent.getStringExtra("id"), equalTo("testid"));
    assertThat(launchedIntent.getStringExtra("name"), equalTo("testname"));
    assertThat(launchedIntent.getStringExtra("place"), equalTo("testplace"));
    assertThat(launchedIntent.getStringExtra(DeepLink.URI), equalTo("http://example.com/deepLink/testid/testname/testplace"));
    Intent parentIntent = shadowApplication.getNextStartedActivity();
    assertNotNull(parentIntent);
    assertThat(parentIntent.getComponent(), equalTo(new ComponentName(deepLinkActivity, MainActivity.class)));
    Intent nextNullIntent = shadowApplication.getNextStartedActivity();
    assertNull(nextNullIntent);
}
Also used : Intent(android.content.Intent) ComponentName(android.content.ComponentName) ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test)

Aggregations

ShadowApplication (org.robolectric.shadows.ShadowApplication)6 Test (org.junit.Test)4 Application (android.app.Application)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Config (org.robolectric.annotation.Config)1