### Question:
ModalStack { public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) { if (modals.isEmpty()) { listener.onError("Nothing to dismiss"); return; } String topModalId = peek().getId(); int modalsDismissed = size(); peek().mergeOptions(mergeOptions); while (!modals.isEmpty()) { if (modals.size() == 1) { dismissModal(modals.get(0).getId(), root, new CommandListenerAdapter(listener) { @Override public void onSuccess(String childId) { eventEmitter.emitModalDismissed(topModalId, modalsDismissed); super.onSuccess(childId); } }); } else { modals.get(0).destroy(); modals.remove(0); } } } ModalStack(Activity activity); @RestrictTo(RestrictTo.Scope.TESTS)  ModalStack(ModalPresenter presenter); void setEventEmitter(EventEmitter eventEmitter); void setModalsLayout(ViewGroup modalsLayout); void setRootLayout(ViewGroup rootLayout); void setDefaultOptions(Options defaultOptions); void showModal(ViewController viewController, ViewController root, CommandListener listener); boolean dismissModal(String componentId, @Nullable ViewController root, CommandListener listener); void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener); boolean handleBack(CommandListener listener, ViewController root); ViewController get(int index); boolean isEmpty(); int size(); @Nullable ViewController findControllerById(String componentId); void destroy();  }### Answer:
@Test public void dismissAllModals() { uut.showModal(modal1, root, new CommandListenerAdapter()); uut.showModal(modal2, root, new CommandListenerAdapter()); CommandListener listener = spy(new CommandListenerAdapter() { @Override public void onSuccess(String childId) { assertThat(findModal(modal1.getId())).isNull(); assertThat(findModal(modal2.getId())).isNull(); assertThat(uut.isEmpty()).isTrue(); } }); uut.dismissAllModals(root, Options.EMPTY, listener); verify(listener, times(1)).onSuccess(anyString()); verifyZeroInteractions(listener); }
@Test public void dismissAllModals_rejectIfEmpty() { CommandListener spy = spy(new CommandListenerAdapter()); uut.dismissAllModals(root, Options.EMPTY, spy); verify(spy, times(1)).onError(any()); }