ModernRouterNavigator implements RouterNavigator<StateT> { @Override public <R extends Router> void pushRetainedState( final StateT newState, final AttachTransition<R, StateT> attachTransition, @Nullable final DetachTransition<R, StateT> detachTransition) { pushInternal(newState, attachTransition, detachTransition, false); } ModernRouterNavigator(Router<?, ?> hostRouter); @SuppressWarnings("unchecked") @Override void popState(); @Override void pushRetainedState(
      final StateT newState,
      final AttachTransition<R, StateT> attachTransition,
      @Nullable final DetachTransition<R, StateT> detachTransition); @Override void pushRetainedState(
      StateT newState, AttachTransition<R, StateT> attachTransition); @Override void pushTransientState(
      final StateT newState,
      final AttachTransition<R, StateT> attachTransition,
      @Nullable final DetachTransition<R, StateT> detachTransition); @Override void pushTransientState(
      StateT newState, AttachTransition<R, StateT> attachTransition); @Nullable @Override Router peekRouter(); @Nullable @Override StateT peekState(); @IntRange(from = 0) @Override int size(); @Override void hostWillDetach();  }
@Test public void pushRetained_whenNotInitialPush_shouldRunPreviousDetachRunnerAndRunNewAttachRunnerWithCorrectState() { routerNavigator.pushRetainedState(TestState.STATE_1, attachTransitionOne, detachTransitionOne); verify(attachTransitionOne).willAttachToHost(routerOne, null, TestState.STATE_1, true); verify(hostRouter).attachChild(routerOne); verifyZeroInteractions(detachTransitionOne); routerNavigator.pushRetainedState(TestState.STATE_2, attachTransitionTwo, detachTransitionTwo); verify(detachTransitionOne) .willDetachFromHost(routerOne, TestState.STATE_1, TestState.STATE_2, true); verify(hostRouter).detachChild(routerOne); verify(attachTransitionTwo) .willAttachToHost(routerTwo, TestState.STATE_1, TestState.STATE_2, true); verifyZeroInteractions(detachTransitionTwo); }
@Test public void pushRetained_whenChildRouterSwitchesStateImmediately_shouldSwitchToCorrectState() { routerNavigator.pushRetainedState(TestState.STATE_1, attachTransitionOne, detachTransitionOne); verify(attachTransitionOne).willAttachToHost(routerOne, null, TestState.STATE_1, true); verify(hostRouter).attachChild(routerOne); verifyZeroInteractions(detachTransitionOne); Answer attachChildAnswer = new Answer() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { routerNavigator.pushRetainedState( TestState.STATE_3, attachTransitionThree, detachTransitionThree); return null; } }; doAnswer(attachChildAnswer).when(hostRouter).attachChild(routerTwo); routerNavigator.pushRetainedState(TestState.STATE_2, attachTransitionTwo, detachTransitionTwo); verify(detachTransitionOne) .willDetachFromHost(routerOne, TestState.STATE_1, TestState.STATE_2, true); verify(attachTransitionTwo) .willAttachToHost(routerTwo, TestState.STATE_1, TestState.STATE_2, true); verify(detachTransitionTwo) .willDetachFromHost(routerTwo, TestState.STATE_2, TestState.STATE_3, true); verify(attachTransitionThree) .willAttachToHost(routerThree, TestState.STATE_2, TestState.STATE_3, true); verify(attachTransitionThree, never()) .willAttachToHost(routerThree, TestState.STATE_1, TestState.STATE_3, true); }