MainViewModel implements ViewModel { public void showData(@Nullable String accessToken, @Nullable String authCode, @IdRes int layoutResId) { if (!TextUtils.isEmpty(accessToken)) { navigator.replaceMainFragment(layoutResId); } else { if (TextUtils.isEmpty(authCode)) { navigator.startLoginActivity(); navigator.finish(); } else { navigator.replaceMainFragment(authCode, layoutResId); } } } @Inject  MainViewModel(PageNavigator navigator); void showData(@Nullable String accessToken, @Nullable String authCode,
        @IdRes int layoutResId); @Override void destroy(); void onClickSearchMenu(); void onClickSettingMenu();  }
@Test public void testShowData() { final int layoutResId = R.id.content_view; mainViewModel.showData("abcdefghijklmn", "", layoutResId); verify(navigator, times(1)).replaceMainFragment(layoutResId); mainViewModel.showData("", "abcdefghijklmn", layoutResId); verify(navigator, times(1)).replaceMainFragment("abcdefghijklmn", layoutResId); mainViewModel.showData("", "", layoutResId); verify(navigator, times(1)).startLoginActivity(); }