@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.about_menu_option:
        Navigation.findNavController(requireView())
            .navigate(MainFragmentDirections.actionMainFragmentToAboutAnySoftKeyboardFragment());
        return true;
      case R.id.tweaks_menu_option:
        Navigation.findNavController(requireView())
            .navigate(MainFragmentDirections.actionMainFragmentToMainTweaksFragment());
        return true;
      case R.id.backup_prefs:
        mDialogController.showDialog(R.id.backup_prefs);
        return true;
      case R.id.restore_prefs:
        mDialogController.showDialog(R.id.restore_prefs);
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
@Test
  public void testBackupMenuItem() throws Exception {
    final MainFragment fragment = startFragment();
    final FragmentActivity activity = fragment.getActivity();

    Menu menu = Shadows.shadowOf(activity).getOptionsMenu();
    Assert.assertNotNull(menu);
    final MenuItem item = menu.findItem(R.id.backup_prefs);
    Assert.assertNotNull(item);

    fragment.onOptionsItemSelected(item);
    TestRxSchedulers.foregroundFlushAllJobs();

    final AlertDialog dialog = GeneralDialogTestUtil.getLatestShownDialog();
    Assert.assertNotSame(GeneralDialogTestUtil.NO_DIALOG, dialog);
    Assert.assertEquals(
        getApplicationContext().getText(R.string.pick_prefs_providers_to_backup),
        GeneralDialogTestUtil.getTitleFromDialog(dialog));
    final ListView dialogListView = dialog.getListView();
    Assert.assertNotNull(dialogListView);
    Assert.assertEquals(View.VISIBLE, dialogListView.getVisibility());
    final List<GlobalPrefsBackup.ProviderDetails> allPrefsProviders =
        GlobalPrefsBackup.getAllPrefsProviders(getApplicationContext());
    Assert.assertEquals(allPrefsProviders.size(), dialogListView.getCount());
    // everything is checked at first
    for (int providerIndex = 0; providerIndex < allPrefsProviders.size(); providerIndex++) {
      Assert.assertEquals(
          activity.getText(allPrefsProviders.get(providerIndex).providerTitle),
          dialogListView.getItemAtPosition(providerIndex));
    }

    Assert.assertTrue(dialog.getButton(DialogInterface.BUTTON_NEGATIVE).callOnClick());
    // no dialog here
    Assert.assertSame(
        GeneralDialogTestUtil.NO_DIALOG, GeneralDialogTestUtil.getLatestShownDialog());
  }