Search in sources :

Example 6 with ShadowActivity

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

the class SecondActivityTest method testIntent.

@Test
public void testIntent() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com/deepLink/123/myname"));
    DeepLinkActivity deepLinkActivity = Robolectric.buildActivity(DeepLinkActivity.class).withIntent(intent).create().get();
    ShadowActivity shadowActivity = shadowOf(deepLinkActivity);
    Intent launchedIntent = shadowActivity.peekNextStartedActivityForResult().intent;
    assertThat(launchedIntent.getComponent(), equalTo(new ComponentName(deepLinkActivity, SecondActivity.class)));
    assertThat(launchedIntent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false), equalTo(true));
    assertThat(launchedIntent.getStringExtra(DeepLink.URI), equalTo("http://example.com/deepLink/123/myname"));
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 7 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project scdl by passy.

the class DownloadActivityTest method purchaseFlow.

@Test
public void purchaseFlow() {
    final TrackEntity track = new TrackEntity();
    final UserEntity user = new UserEntity();
    final String downloadUrl = "http://3lau.to/downloadstuff";
    user.setUsername("awesomesauce");
    track.setDownloadable(false);
    track.setUser(user);
    track.setPurchaseUrl(downloadUrl);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(DownloadActivity.MEDIA_STATE_TAG, MediaState.fromEntity(track));
    final DownloadActivity activity = Robolectric.buildActivity(DownloadActivity.class).attach().create(bundle).start().resume().get();
    final View button = activity.findViewById(R.id.btn_download);
    assertTrue(button.isEnabled());
    button.performClick();
    final ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    final Intent nextIntent = shadowActivity.getNextStartedActivity();
    assertThat(nextIntent.getAction(), equalTo("android.intent.action.VIEW"));
    assertThat(nextIntent.toUri(0), startsWith(downloadUrl));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) Bundle(android.os.Bundle) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) View(android.view.View) UserEntity(net.rdrei.android.scdl2.api.entity.UserEntity) DownloadActivity(net.rdrei.android.scdl2.ui.DownloadActivity) Test(org.junit.Test)

Example 8 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project scdl by passy.

the class PreferencesMenuTest method shouldStartPreferencesInActivity.

private void shouldStartPreferencesInActivity(Fragment fragment) {
    final ActivityController<FragmentActivity> controller = Robolectric.buildActivity(FragmentActivity.class);
    controller.create().start().resume();
    final FragmentActivity activity = controller.get();
    activity.getSupportFragmentManager().beginTransaction().add(fragment, null).commit();
    final MenuItem item = new TestMenuItem(R.id.preferences);
    fragment.onOptionsItemSelected(item);
    final ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    final Intent startedActivity = shadowActivity.getNextStartedActivity();
    // Intent was actually started
    assertThat(startedActivity, notNullValue());
    final ShadowIntent intent = Robolectric.shadowOf(startedActivity);
    assertThat(intent.getComponent().getClassName(), equalTo(ApplicationPreferencesActivity.class.getName()));
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) ShadowIntent(org.robolectric.shadows.ShadowIntent) TestMenuItem(org.robolectric.tester.android.view.TestMenuItem) ShadowActivity(org.robolectric.shadows.ShadowActivity) TestMenuItem(org.robolectric.tester.android.view.TestMenuItem) MenuItem(android.view.MenuItem) ShadowIntent(org.robolectric.shadows.ShadowIntent) Intent(android.content.Intent)

Example 9 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project androidannotations by androidannotations.

the class AwaitingResultFragmentTest method testOnResultCalledInFragment.

@Test
public void testOnResultCalledInFragment() {
    FragmentStartedActivity_.intent(fragment).startForResult(AwaitingResultFragment.FIRST_REQUEST);
    ShadowActivity a = (ShadowActivity) extract(fragment.getActivity());
    a.receiveResult(FragmentStartedActivity_.intent(fragment).get(), Activity.RESULT_OK, new Intent());
    assertThat(fragment.onResultCalled).isTrue();
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)9 ShadowActivity (org.robolectric.shadows.ShadowActivity)9 Test (org.junit.Test)7 ComponentName (android.content.ComponentName)5 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TrackEntity (net.rdrei.android.scdl2.api.entity.TrackEntity)1 UserEntity (net.rdrei.android.scdl2.api.entity.UserEntity)1 DownloadActivity (net.rdrei.android.scdl2.ui.DownloadActivity)1 ShadowIntent (org.robolectric.shadows.ShadowIntent)1 TestMenuItem (org.robolectric.tester.android.view.TestMenuItem)1