@SuppressWarnings("deprecation") // TODO: fix by using a fragment instead
  public static void assertDialogWasNotDisplayed(Activity activity, int dialogId) {
    // IMPLEMENTATION NOTE: This code below relies on the fact that, if a dialog with the ID was
    // every displayed, then dismissDialog will succeed, whereas if the dialog with the ID has
    // never been shown, then dismissDialog throws an IllegalArgumentException.
    try {
      activity.dismissDialog(dialogId);
      Assert.fail("Dialog with ID " + dialogId + " was displayed");
    } catch (IllegalArgumentException expected) {
      // Expected
    }
  }
Asserts that the provided {@link Activity} has not displayed a dialog with the provided ID.
javatests/com/google/android/apps/authenticator/testing/TestUtilities.java