### Question:
ModalPresenter { void showModal(ViewController toAdd, ViewController toRemove, CommandListener listener) { if (modalsLayout == null) { listener.onError("Can not show modal before activity is created"); return; } Options options = toAdd.resolveCurrentOptions(defaultOptions); toAdd.setWaitForRender(options.animations.showModal.waitForRender); modalsLayout.addView(toAdd.getView()); if (options.animations.showModal.enabled.isTrueOrUndefined()) { if (options.animations.showModal.waitForRender.isTrue()) { toAdd.addOnAppearedListener(() -> animateShow(toAdd, toRemove, listener, options)); } else { animateShow(toAdd, toRemove, listener, options); } } else { if (options.animations.showModal.waitForRender.isTrue()) { toAdd.addOnAppearedListener(() -> onShowModalEnd(toAdd, toRemove, listener)); } else { onShowModalEnd(toAdd, toRemove, listener); } } } ModalPresenter(ModalAnimator animator); void setRootLayout(ViewGroup rootLayout); void setDefaultOptions(Options defaultOptions);  }### Answer:
@Test public void showModal() { Options defaultOptions = new Options(); uut.setDefaultOptions(defaultOptions); disableShowModalAnimation(modal1); uut.showModal(modal1, root, new CommandListenerAdapter()); verify(modal1).setWaitForRender(any()); verify(modal1).resolveCurrentOptions(defaultOptions); }
@Test public void showModal_noAnimation() { disableShowModalAnimation(modal1); CommandListener listener = spy(new CommandListenerAdapter() { @Override public void onSuccess(String childId) { assertThat(modal1.getView().getParent()).isEqualTo(modalsLayout); verify(modal1, times(1)).onViewAppeared(); } }); uut.showModal(modal1, root, listener); verify(animator, times(0)).show( eq(modal1.getView()), eq(modal1.options.animations.showModal), any() ); verify(listener, times(1)).onSuccess(MODAL_ID_1); }
@Test public void showModal_previousModalIsRemovedFromHierarchy() { uut.showModal(modal1, null, new CommandListenerAdapter() { @Override public void onSuccess(String childId) { uut.showModal(modal2, modal1, new CommandListenerAdapter() { @Override public void onSuccess(String childId) { assertThat(modal1.getView().getParent()).isNull(); verify(modal1, times(1)).onViewDisappear(); } }); assertThat(modal1.getView().getParent()).isEqualTo(modal2.getView().getParent()); } }); }
@Test public void showModal_animatesByDefault() { uut.showModal(modal1, null, new CommandListenerAdapter() { @Override public void onSuccess(String childId) { verify(animator, times(1)).show( eq(modal1.getView()), eq(modal1.options.animations.showModal), any() ); assertThat(animator.isRunning()).isFalse(); } }); }
@Test public void showModal_waitForRender() { modal1.options.animations.showModal.waitForRender = new Bool(true); uut.showModal(modal1, root, new CommandListenerAdapter()); verify(modal1).addOnAppearedListener(any()); verifyZeroInteractions(animator); }
@Test public void dismissModal_previousViewIsNotDetachedIfOverCurrentContext() { modal1.options.modal.presentationStyle = ModalPresentationStyle.OverCurrentContext; disableShowModalAnimation(modal1, modal2); uut.showModal(modal1, root, new CommandListenerAdapter()); assertThat(root.getView().getParent()).isNotNull(); verify(root, times(0)).onViewDisappear(); }