@Test
  public void shouldSupportStartActivityForResult() throws Exception {
    activity = create(DialogLifeCycleActivity.class);
    ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class);
    assertThat(shadowActivity.getNextStartedActivity()).isNull();

    activity.startActivityForResult(intent, 142);

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertThat(startedIntent).isNotNull();
    assertThat(startedIntent).isSameAs(intent);
  }
  @Test
  public void execute_whenUberAppInsalled_shouldPointToUberApp() throws IOException {
    String expectedUri =
        readUriResourceWithUserAgentParam(
            "src/test/resources/deeplinkuris/just_client_provided", USER_AGENT_DEEPLINK);

    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);

    RobolectricPackageManager packageManager =
        (RobolectricPackageManager) shadowActivity.getPackageManager();

    PackageInfo uberPackage = new PackageInfo();
    uberPackage.packageName = UBER_PACKAGE_NAME;
    packageManager.addPackage(uberPackage);

    RideParameters rideParameters = new RideParameters.Builder().build();

    RequestDeeplink requestDeeplink =
        new RequestDeeplink.Builder()
            .setClientId(CLIENT_ID)
            .setRideParameters(rideParameters)
            .build();

    requestDeeplink.execute(activity);

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(expectedUri, startedIntent.getData().toString());
  }
  @Test
  public void shouldOpenPreferencesWhenPreferenceButtonFromMainMenuSelected() {

    MenuItem item = new RoboMenuItem(R.id.main_menu_preferences);
    activity.onOptionsItemSelected(item);

    Intent expectedIntent = new Intent(activity, TestbedPreferenceActivity.class);
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent actualIntent = shadowActivity.getNextStartedActivity();
    assertTrue(actualIntent.filterEquals(expectedIntent));
  }
  @Test
  public void pressingTheButtonShouldStartAppetizerFragmentActivity() throws Exception {
    pressMeButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(
        shadowIntent.getComponent().getClassName(),
        equalTo(AppetizerFragmentActivity.class.getName()));
  }
Пример #5
0
  @Test
  public void skipLoginAndCancel() {
    ShadowActivity shadowActivity = Robolectric.shadowOf(loginActivity);

    ((TextView) loginActivity.findViewById(R.id.skipLogin)).performClick();
    AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog dialog = Robolectric.shadowOf(latestAlertDialog);
    assertEquals(loginActivity.getString(R.string.noLoginWarn), dialog.getMessage());
    assertTrue(latestAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick());
    assertNull(shadowActivity.getNextStartedActivity());
  }
  @Test
  @Ignore("Robolectric does not work with appcompact AlertDialogs yet")
  public void shouldOpenAboutBoxWhenAboutButtonFromMainMenuSelected() {

    MenuItem item = new RoboMenuItem(R.id.main_menu_about);
    activity.onOptionsItemSelected(item);

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

    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowDialog = shadowOf(dialog);
    assertEquals("Helsinki Testbed Viewer 2.0.13", shadowDialog.getTitle());
  }
 @Test
 public void testOnItemClick_startsFullPhotoViewIntent() {
   subject.setupPhotoList();
   RecyclerView recyclerView = subject.getPhotoRecyclerView();
   recyclerView.measure(0, 0);
   recyclerView.layout(0, 0, 100, 1000);
   RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(0);
   View view = viewHolder.itemView;
   view.performClick();
   Intent expectedIntent = new Intent(subject, PhotoFullScreenActivity.class);
   ShadowActivity shadowActivity = Shadows.shadowOf(subject);
   Intent actualIntent = shadowActivity.getNextStartedActivity();
   Assertions.assertThat(actualIntent).isNotNull();
   assertTrue(actualIntent.filterEquals(expectedIntent));
 }
Пример #8
0
  @Test
  public void clickWithIntent() {
    MyActivity activity = new MyActivity();

    TestMenu testMenu = new TestMenu(activity);
    testMenu.add(0, 10, 0, org.robolectric.R.string.ok);

    TestMenuItem testMenuItem = (TestMenuItem) testMenu.findItem(10);
    Assert.assertNull(testMenuItem.getIntent());

    Intent intent = new Intent(activity, MyActivity.class);
    testMenuItem.setIntent(intent);
    testMenuItem.click();

    Assert.assertNotNull(testMenuItem);

    ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertNotNull(startedIntent);
  }
  @Test
  public void execute_whenNoUberApp_shouldPointToMobileSite() throws IOException {
    String expectedUri =
        readUriResourceWithUserAgentParam(
            "src/test/resources/deeplinkuris/no_app_installed", USER_AGENT_DEEPLINK);

    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);

    RideParameters rideParameters = new RideParameters.Builder().build();

    RequestDeeplink requestDeeplink =
        new RequestDeeplink.Builder()
            .setClientId(CLIENT_ID)
            .setRideParameters(rideParameters)
            .build();
    requestDeeplink.execute(activity);

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(expectedUri, startedIntent.getData().toString());
  }