@Test
  public void showDialog_shouldReuseDialogs() {
    final DialogCreatingActivity activity = create(DialogCreatingActivity.class);
    activity.showDialog(1);
    Dialog firstDialog = ShadowDialog.getLatestDialog();
    activity.showDialog(1);

    Dialog secondDialog = ShadowDialog.getLatestDialog();
    assertSame("dialogs should be the same instance", firstDialog, secondDialog);
  }
  @Test
  public void removeDialog_shouldCreateDialogAgain() {
    final DialogCreatingActivity activity = create(DialogCreatingActivity.class);
    activity.showDialog(1);
    Dialog firstDialog = ShadowDialog.getLatestDialog();

    activity.removeDialog(1);
    assertNull(Robolectric.shadowOf(activity).getDialogById(1));

    activity.showDialog(1);
    Dialog secondDialog = ShadowDialog.getLatestDialog();

    assertNotSame("dialogs should not be the same instance", firstDialog, secondDialog);
  }
 @Test
 public void shouldCallOnCreateDialogFromShowDialog() {
   ActivityWithOnCreateDialog activity = create(ActivityWithOnCreateDialog.class);
   activity.showDialog(123);
   assertTrue(activity.onCreateDialogWasCalled);
   assertThat(ShadowDialog.getLatestDialog()).isNotNull();
 }
 @Test
 public void showDialog_shouldShowDialog() throws Exception {
   final DialogCreatingActivity activity = create(DialogCreatingActivity.class);
   activity.showDialog(1);
   Dialog dialog = ShadowDialog.getLatestDialog();
   assertTrue(dialog.isShowing());
 }
 @Test
 public void dismissDialog_shouldDismissPreviouslyShownDialog() throws Exception {
   final DialogCreatingActivity activity = create(DialogCreatingActivity.class);
   activity.showDialog(1);
   activity.dismissDialog(1);
   Dialog dialog = ShadowDialog.getLatestDialog();
   assertFalse(dialog.isShowing());
 }
  @Test
  public void show_shouldShowDialogThatWasAutomaticallyCreated_whenOnCreateDialogReturnsNull()
      throws Exception {
    dialogFragment.show(fragmentManager, "this is a tag");

    Dialog dialog = ShadowDialog.getLatestDialog();
    assertNotNull(dialog);
    assertSame(dialog, dialogFragment.getDialog());
    assertNotNull(dialog.findViewById(R.id.title));
    assertSame(dialogFragment, fragmentManager.findFragmentByTag("this is a tag"));
  }
  @Test
  public void removeUsingTransaction_shouldDismissTheDialog() throws Exception {
    dialogFragment.show(fragmentManager, null);

    FragmentTransaction t = fragmentManager.beginTransaction();
    t.remove(dialogFragment);
    t.commit();

    Dialog dialog = ShadowDialog.getLatestDialog();
    assertFalse(dialog.isShowing());
    assertTrue(shadowOf(dialog).hasBeenDismissed());
  }
  @Test
  public void
      show_shouldShowDialogThatWasReturnedFromOnCreateDialog_whenOnCreateDialogReturnsADialog()
          throws Exception {
    Dialog dialogFromOnCreateDialog = new Dialog(activity);
    dialogFragment.returnThisDialogFromOnCreateDialog(dialogFromOnCreateDialog);
    dialogFragment.show(fragmentManager, "this is a tag");

    Dialog dialog = ShadowDialog.getLatestDialog();
    assertSame(dialogFromOnCreateDialog, dialog);
    assertSame(dialogFromOnCreateDialog, dialogFragment.getDialog());
    assertSame(dialogFragment, fragmentManager.findFragmentByTag("this is a tag"));
  }
Exemplo n.º 9
0
  private void assertLatestDialogsSet(
      CharSequence expectedTitle,
      CharSequence expectedMessage,
      boolean expectedIndeterminate,
      boolean expectedCancelable,
      DialogInterface.OnCancelListener expectedCancelListener,
      Callable<ProgressDialog> callable)
      throws Exception {
    assertNull(ShadowDialog.getLatestDialog());
    assertNull(ShadowAlertDialog.getLatestAlertDialog());

    dialog = callable.call();

    assertNotNull(dialog);
    assertThat(ShadowDialog.getLatestDialog()).isEqualTo(dialog);
    assertThat(ShadowAlertDialog.getLatestAlertDialog()).isEqualTo(dialog);

    assertThat(dialog.isIndeterminate()).as("isIndeterminate").isEqualTo(expectedIndeterminate);
    assertThat(shadowOf(dialog).getMessage()).as("message").isEqualTo(expectedMessage);
    assertThat(shadowOf(dialog).getTitle()).as("title").isEqualTo(expectedTitle);
    assertThat(shadowOf(dialog).isCancelable()).as("isCancelable").isEqualTo(expectedCancelable);
    assertThat(shadowOf(dialog).getOnCancelListener()).isEqualTo(expectedCancelListener);
  }