@SuppressWarnings("unchecked")
  private void checkOptionsMenuItemWithComponent(int menuTextId, Class<?> cls) {
    activityTestRule.launchActivity(null);

    onView(isRoot()).perform(pressMenuKey());
    onView(
            withText(
                InstrumentationRegistry
                    .getInstrumentation()
                    .getTargetContext()
                    .getString(menuTextId)))
        .perform(click());
    Matcher<Intent> intentMatcher =
        hasComponent(
            equalTo(
                new ComponentName(
                    InstrumentationRegistry.getInstrumentation().getTargetContext(), cls)));
    intended(intentMatcher);
    assertThat(TestUtilities.isStrayIntentRemaining()).isFalse();
  }
Set the preference for key KEY_DARK_MODE_ENABLED of {@link AuthenticatorActivity}.
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java