NavigatingViewModel extends BaseViewModel { public void setNavigator(@Nullable T navigator) { this.navigator = navigator; if (navigator != null && pendingCommand != null) { pendingCommand.execute(navigator); pendingCommand = null; } }  void setNavigator(@Nullable T navigator); void executeNavigationCommand(NavigationCommand<T> navigationCommand);  }
@Test public void testNotExecuteCommandOnNavigatorSetterIfNavigatorNull() { viewModel.pendingCommand = command; viewModel.setNavigator(null); verifyZeroInteractions(command); }
@Test public void testNoNullPointerOnNavigatorSetterIfCommandNull() { viewModel.pendingCommand = null; viewModel.setNavigator(navigator); }
@Test public void testExecutePendingCommandOnNavigatorAttach() { viewModel.pendingCommand = command; viewModel.setNavigator(navigator); verify(command).execute(navigator); }
@Test public void testPendingCommandExecutedOnceOnly() { viewModel.pendingCommand = command; final Navigator anotherNavigator = mock(Navigator.class); viewModel.setNavigator(navigator); viewModel.setNavigator(anotherNavigator); verify(command, times(1)).execute(navigator); }