org.robolectric.shadows.ShadowResolveInfo Java Examples

The following examples show how to use org.robolectric.shadows.ShadowResolveInfo. 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_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 #3
Source File: SsoDeeplinkTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Before
public void setUp() {
    activity = spy(Robolectric.setupActivity(Activity.class));

    redirectIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(REDIRECT_URI));
    redirectIntent.setPackage(activity.getPackageName());
    resolveInfo = ShadowResolveInfo.newResolveInfo("", activity.getPackageName());
    packageManager = RuntimeEnvironment.getRobolectricPackageManager();
    packageManager.addResolveInfoForIntent(redirectIntent, resolveInfo);

    ssoDeeplink = new SsoDeeplink.Builder(activity)
            .clientId(CLIENT_ID)
            .scopes(GENERAL_SCOPES)
            .appProtocol(appProtocol)
            .activityRequestCode(REQUEST_CODE)
            .redirectUri(REDIRECT_URI)
            .build();
}
 
Example #4
Source File: TestApplication.java    From materialistic with Apache License 2.0 4 votes vote down vote up
public static void addResolver(Intent intent) {
    ShadowPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());
    packageManager.addResolveInfoForIntent( intent,
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
}
 
Example #5
Source File: ItemActivityTest.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Test
public void testOptionExternal() {
    ShadowPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://example.com")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public String getId() {
            return "1";
        }
    });
    controller = Robolectric.buildActivity(ItemActivity.class, intent);
    controller.create().start().resume();
    activity = controller.get();

    // inflate menu, see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();

    // open article
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_article));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);

    // open item
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}