Closed TWiStErRob closed 1 year ago
Revised code: an added test
@Parameters(named = POTENTIAL_DIALOGS)
@TestCaseName(POTENTIAL_DIALOGS_NAME)
@Test(timeout = DIALOG_TIMEOUT)
public void testDialogIsDisplayedWithoutActivityForAppCompatAlert(
final boolean positive, final boolean negative, final boolean neutral, final boolean cancellable) {
Espresso.onIdle();
onRoot().perform(loopMainThreadUntilIdle());
assertThat(getAllActivitiesByStage().get(Stage.RESUMED), not(Matchers.<Activity>empty()));
activity.getActivity().finish();
Espresso.onIdle();
assertThat(getAllActivitiesByStage().get(Stage.DESTROYED), not(Matchers.<Activity>empty()));
Context context = getInstrumentation().getContext();
androidx.appcompat.app.AlertDialog dialog = displayAppCompatAlertDialog(
context, positive, negative, neutral, cancellable
);
try {
assertDialogIsDisplayed_withTimeout();
} finally {
dialog.dismiss();
}
}
but this is not viable: this throws an exception wanting an AppCompat activity, and the built-in version throws because the app context doesn't have a window token.
Don't remember what, but found this patch that wasn't committed yet: