### Question:
RootPresenter { void setRoot(ViewController root, Options defaultOptions, CommandListener listener, ReactInstanceManager reactInstanceManager) { setLayoutDirection(root, defaultOptions, (ReactApplicationContext) reactInstanceManager.getCurrentReactContext()); rootLayout.addView(root.getView()); Options options = root.resolveCurrentOptions(defaultOptions); root.setWaitForRender(options.animations.setRoot.waitForRender); if (options.animations.setRoot.waitForRender.isTrue()) { root.getView().setAlpha(0); root.addOnAppearedListener(() -> { root.getView().setAlpha(1); animateSetRootAndReportSuccess(root, listener, options); }); } else { animateSetRootAndReportSuccess(root, listener, options); } } RootPresenter(Context context);   RootPresenter(NavigationAnimator animator);   }### Answer:
@Test public void setRoot_viewIsAddedToContainer() { uut.setRoot(root, defaultOptions, new CommandListenerAdapter(), reactInstanceManager); assertThat(root.getView().getParent()).isEqualTo(rootContainer); }
@Test public void setRoot_reportsOnSuccess() { CommandListenerAdapter listener = spy(new CommandListenerAdapter()); uut.setRoot(root, defaultOptions, listener, reactInstanceManager); verify(listener).onSuccess(root.getId()); }
@Test public void setRoot_doesNotAnimateByDefault() { CommandListenerAdapter listener = spy(new CommandListenerAdapter()); uut.setRoot(root, defaultOptions, listener, reactInstanceManager); 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, reactInstanceManager); verify(animator).setRoot(eq(spy.getView()), eq(animatedSetRoot.animations.setRoot), any()); verify(listener).onSuccess(spy.getId()); }
@Test public void setRoot_waitForRenderIsSet() { root.options.animations.setRoot.waitForRender = new Bool(true); ViewController spy = spy(root); uut.setRoot(spy, defaultOptions, new CommandListenerAdapter(), reactInstanceManager); ArgumentCaptor<Bool> captor = ArgumentCaptor.forClass(Bool.class); verify(spy).setWaitForRender(captor.capture()); assertThat(captor.getValue().get()).isTrue(); }
@Test public void setRoot_waitForRender() { root.options.animations.setRoot.waitForRender = new Bool(true); ViewController spy = spy(root); CommandListenerAdapter listener = spy(new CommandListenerAdapter()); uut.setRoot(spy, defaultOptions, listener, reactInstanceManager); verify(spy).addOnAppearedListener(any()); assertThat(spy.getView().getAlpha()).isZero(); verifyZeroInteractions(listener); spy.onViewAppeared(); assertThat(spy.getView().getAlpha()).isOne(); verify(listener).onSuccess(spy.getId()); }