RootPresenter { public void setRoot(ViewController root, Options defaultOptions, CommandListener listener) { rootLayout.addView(root.getView()); Options options = root.resolveCurrentOptions(defaultOptions); if (options.animations.setRoot.hasAnimation()) { animator.setRoot(root.getView(), options.animations.setRoot, () -> listener.onSuccess(root.getId())); } else { listener.onSuccess(root.getId()); } } RootPresenter(Context context);   RootPresenter(NavigationAnimator animator); void setRootContainer(FrameLayout rootLayout); void setRoot(ViewController root, Options defaultOptions, CommandListener listener);  }
@Test public void setRoot_viewIsAddedToContainer() { uut.setRoot(root, defaultOptions, new CommandListenerAdapter()); assertThat(root.getView().getParent()).isEqualTo(rootContainer); }
@Test public void setRoot_reportsOnSuccess() { CommandListenerAdapter listener = spy(new CommandListenerAdapter()); uut.setRoot(root, defaultOptions, listener); verify(listener).onSuccess(root.getId()); }
@Test public void setRoot_doesNotAnimateByDefault() { CommandListenerAdapter listener = spy(new CommandListenerAdapter()); uut.setRoot(root, defaultOptions, listener); verifyZeroInteractions(animator); verify(listener).onSuccess(root.getId()); }
@Test public void setRoot_animates() { Options animatedSetRoot = new Options(); animatedSetRoot.animations.setRoot = new AnimationOptions() { @Override public boolean hasAnimation() { return true; } }; ViewController spy = spy(root); when(spy.resolveCurrentOptions(defaultOptions)).thenReturn(animatedSetRoot); CommandListenerAdapter listener = spy(new CommandListenerAdapter()); uut.setRoot(spy, defaultOptions, listener); verify(animator).setRoot(eq(spy.getView()), eq(animatedSetRoot.animations.setRoot), any()); verify(listener).onSuccess(spy.getId()); }