### Question:
BrowseSupportFragment extends BaseSupportFragment { public Fragment getMainFragment() { return mMainFragment; }  static Bundle createArgs(Bundle args, String title, int headersState); void setBrandColor(@ColorInt int color); @ColorInt int getBrandColor(); void setAdapter(ObjectAdapter adapter); final MainFragmentAdapterRegistry getMainFragmentRegistry(); ObjectAdapter getAdapter(); void setOnItemViewSelectedListener(OnItemViewSelectedListener listener); OnItemViewSelectedListener getOnItemViewSelectedListener(); RowsSupportFragment getRowsSupportFragment(); Fragment getMainFragment(); HeadersSupportFragment getHeadersSupportFragment(); void setOnItemViewClickedListener(OnItemViewClickedListener listener); OnItemViewClickedListener getOnItemViewClickedListener(); void startHeadersTransition(boolean withHeaders); boolean isInHeadersTransition(); boolean isShowingHeaders(); void setBrowseTransitionListener(BrowseTransitionListener listener); @Deprecated void enableRowScaling(boolean enable); void enableMainFragmentScaling(boolean enable); @Override void onSaveInstanceState(Bundle outState); @Override void onCreate(Bundle savedInstanceState); @Override void onDestroyView(); @Override void onDestroy(); HeadersSupportFragment onCreateHeadersSupportFragment(); @Override View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState); void setHeaderPresenterSelector(PresenterSelector headerPresenterSelector); void setSelectedPosition(int position); int getSelectedPosition(); RowPresenter.ViewHolder getSelectedRowViewHolder(); void setSelectedPosition(int position, boolean smooth); void setSelectedPosition(int rowPosition, boolean smooth,
            final Presenter.ViewHolderTask rowHolderTask); @Override void onStart(); final void setHeadersTransitionOnBackEnabled(boolean headersBackStackEnabled); final boolean isHeadersTransitionOnBackEnabled(); void setHeadersState(int headersState); int getHeadersState(); static final int HEADERS_ENABLED; static final int HEADERS_HIDDEN; static final int HEADERS_DISABLED; }### Answer:
@Test public void testTwoBackKeysWithBackStack() throws Throwable { final long dataLoadingDelay = 0L; Intent intent = new Intent(); intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, dataLoadingDelay); intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK , true); mActivity = activityTestRule.launchActivity(intent); waitForEntranceTransitionFinished(); assertNotNull(mActivity.getBrowseTestSupportFragment().getMainFragment()); sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); waitForHeaderTransitionFinished(); sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK); }
@Test public void testTwoBackKeysWithoutBackStack() throws Throwable { final long dataLoadingDelay = 0L; Intent intent = new Intent(); intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, dataLoadingDelay); intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK , false); mActivity = activityTestRule.launchActivity(intent); waitForEntranceTransitionFinished(); assertNotNull(mActivity.getBrowseTestSupportFragment().getMainFragment()); sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); waitForHeaderTransitionFinished(); sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK); }
@Test public void testPressRightBeforeMainFragmentCreated() throws Throwable { final long dataLoadingDelay = 1000; Intent intent = new Intent(); intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, dataLoadingDelay); intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK , false); mActivity = activityTestRule.launchActivity(intent); assertNull(mActivity.getBrowseTestSupportFragment().getMainFragment()); sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); }