### Question:
ModalStack { public boolean dismissModal(String componentId, @Nullable ViewController root, CommandListener listener) { ViewController toDismiss = findModalByComponentId(componentId); if (toDismiss != null) { boolean isDismissingTopModal = isTop(toDismiss); modals.remove(toDismiss); @Nullable ViewController toAdd = isEmpty() ? root : isDismissingTopModal ? get(size() - 1) : null; CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) { @Override public void onSuccess(String childId) { eventEmitter.emitModalDismissed(componentId, 1); super.onSuccess(componentId); } }; if (isDismissingTopModal) { if (toAdd == null) { listener.onError("Could not dismiss modal"); return false; } } presenter.dismissModal(toDismiss, toAdd, root, onDismiss); return true; } else { listener.onError("Nothing to dismiss"); return false; } } 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:
@SuppressWarnings("Convert2Lambda") @Test public void dismissModal() { uut.showModal(modal1, root, new CommandListenerAdapter()); CommandListener listener = spy(new CommandListenerAdapter()); uut.dismissModal(modal1.getId(), root, listener); assertThat(findModal(modal1.getId())).isNull(); verify(presenter, times(1)).dismissModal(eq(modal1), eq(root), eq(root), any()); verify(listener).onSuccess(modal1.getId()); }
@SuppressWarnings("Convert2Lambda") @Test public void dismissModal_rejectIfModalNotFound() { CommandListener listener = spy(new CommandListenerAdapter()); Runnable onModalWillDismiss = spy(new Runnable() { @Override public void run() { } }); uut.dismissModal(MODAL_ID_1, root, listener); verify(onModalWillDismiss, times(0)).run(); verify(listener, times(1)).onError(anyString()); verifyZeroInteractions(listener); }