private void refreshView() {
    TestUtilities.runOnMainSyncWithTimeout(
        new Callable<Void>() {
          @Override
          public Void call() {
            activityTestRule.getActivity().refreshView(true);
            return null;
          }
        });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
  }
Set the preference for key KEY_DARK_MODE_ENABLED of {@link AuthenticatorActivity}.
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java