コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
 @Test
 public void shouldCallOnCreateDialogFromShowDialog() {
   ActivityWithOnCreateDialog activity = create(ActivityWithOnCreateDialog.class);
   activity.showDialog(123);
   assertTrue(activity.onCreateDialogWasCalled);
   assertThat(ShadowDialog.getLatestDialog()).isNotNull();
 }
コード例 #4
0
 @Test
 public void showDialog_shouldShowDialog() throws Exception {
   final DialogCreatingActivity activity = create(DialogCreatingActivity.class);
   activity.showDialog(1);
   Dialog dialog = ShadowDialog.getLatestDialog();
   assertTrue(dialog.isShowing());
 }
コード例 #5
0
 @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());
 }
コード例 #6
0
  @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"));
  }
コード例 #7
0
  @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());
  }
コード例 #8
0
  @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"));
  }
コード例 #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);
  }