@Test
  @FixWhenMinSdkVersion(11)
  @SuppressWarnings("deprecation")
  public void testContextMenuCopyToClipboard() {
    // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
    accountDb.add(HOTP_ACCOUNT_NAME, "7777777777777777", OtpType.HOTP, null, null, null);

    activityTestRule.launchActivity(null);

    ListView userList = activityTestRule.getActivity().findViewById(R.id.user_list);
    // find and click next otp button.
    View buttonView = activityTestRule.getActivity().findViewById(R.id.next_otp);
    TestUtilities.clickView(InstrumentationRegistry.getInstrumentation(), buttonView);
    // get the pin being displayed
    View listEntry0 = userList.getChildAt(0);
    String pin =
        getOriginalPincode(
            ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString());
    openListViewContextualActionBar(activityTestRule.getActivity(), userList, 0);

    InstrumentationRegistry.getInstrumentation().waitForIdleSync();

    TestUtilities.runOnMainSyncWithTimeout(
        new Callable<Void>() {
          @Override
          public Void call() {
            // Check clipboard value.
            String clipboardContent = "";
            Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
            ClipboardManager clipboard =
                (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipboard.hasPrimaryClip()
                && clipboard.getPrimaryClipDescription()
                    .hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
              clipboardContent = clipboard.getPrimaryClip().getItemAt(0).getText().toString();
            }
            assertThat(clipboardContent).isEqualTo(pin);
            return null;
          }
        });
  }
Unit tests for {@link AuthenticatorActivity} (part/shard 1).
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java