@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); }
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(toDismiss.getId(), 1); super.onSuccess(childId); } }; 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 { 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(toDismiss.getId(), 1); super.onSuccess(childId); } }; 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 { 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(toDismiss.getId(), 1); super.onSuccess(childId); } }; 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); }
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(toDismiss.getId(), 1); super.onSuccess(childId); } }; 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(); }
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(toDismiss.getId(), 1); super.onSuccess(childId); } }; 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();  }