@Test
  public void testTalkBackTextForAccount() throws Throwable {
    // This test checks the text returned by an account row's getContentDescription as well as the
    // text added into AccessibilityEvent by the row.
    // A real object is used for the AuthenticatorActivity#otpProvider instance,
    // but a mock (spy) instance is used only for this test method because it needs to return
    // fixed pin codes to verify.
    String totpAccount = "johndoeTotp@gmail.com";
    String hotpAccount = "johndoeHotp@google.com";
    TotpClock mockOtpClock = mock(TotpClock.class);
    otpSource = spy(otpSource);
    doReturn("192834").when(otpSource).getNextCode(new AccountIndex(totpAccount, null));
    doReturn("722389").when(otpSource).getNextCode(new AccountIndex(hotpAccount, null));
    doReturn(mockOtpClock).when(otpSource).getTotpClock();
    doReturn(new TotpCounter(30)).when(otpSource).getTotpCounter();
    accountDb.add(totpAccount, "7777777777777777", OtpType.TOTP, null, null, null);
    accountDb.add(hotpAccount, "7777777777777777", OtpType.HOTP, null, null, null);

    activityTestRule.launchActivity(null);

    ListView userList = activityTestRule.getActivity().findViewById(R.id.user_list);
    assertThat(userList.getChildCount()).isEqualTo(2);

    // TOTP account
    View totpListEntry = getUserRowView((DragSortItemView) userList.getChildAt(0));
    assertThat(String.valueOf(totpListEntry.getContentDescription()))
        .isEqualTo("1 9 2   8 3 4 " + totpAccount);

    AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain();
    assertThat(totpListEntry.dispatchPopulateAccessibilityEvent(accessibilityEvent)).isTrue();
    assertThat(accessibilityEvent.getContentDescription()).isNull();
    assertThat(String.valueOf(Iterables.getOnlyElement(accessibilityEvent.getText())))
        .isEqualTo("1 9 2   8 3 4 " + totpAccount);

    // HOTP account
    // No OTP is yet displayed for the HOTP account -- the text should say "get code <account name>"
    View hotpListEntry = getUserRowView((DragSortItemView) userList.getChildAt(1));
    assertThat(String.valueOf(hotpListEntry.getContentDescription()))
        .isEqualTo(
            activityTestRule.getActivity().getString(R.string.counter_pin) + " " + hotpAccount);

    accessibilityEvent = AccessibilityEvent.obtain();
    assertThat(hotpListEntry.dispatchPopulateAccessibilityEvent(accessibilityEvent)).isTrue();
    assertThat(accessibilityEvent.getContentDescription()).isNull();
    assertThat(String.valueOf(Iterables.getOnlyElement(accessibilityEvent.getText())))
        .isEqualTo(
            activityTestRule.getActivity().getString(R.string.counter_pin) + " " + hotpAccount);

    View getNextCodeButton = hotpListEntry.findViewById(R.id.next_otp);
    assertThat(getNextCodeButton.isShown()).isTrue();
    // Get an OTP
    TestUtilities.clickView(InstrumentationRegistry.getInstrumentation(), getNextCodeButton);
    // Re-obtain the list entry View reference as it may have changed due to how ListView refreshes
    // itself.
    hotpListEntry = getUserRowView((DragSortItemView) userList.getChildAt(1));
    assertThat(String.valueOf(hotpListEntry.getContentDescription()))
        .isEqualTo("7 2 2   3 8 9 " + hotpAccount);

    accessibilityEvent = AccessibilityEvent.obtain();
    assertThat(hotpListEntry.dispatchPopulateAccessibilityEvent(accessibilityEvent)).isTrue();
    assertThat(accessibilityEvent.getContentDescription()).isNull();
    assertThat(String.valueOf(Iterables.getOnlyElement(accessibilityEvent.getText())))
        .isEqualTo("7 2 2   3 8 9 " + hotpAccount);
  }
Unit tests for {@link AuthenticatorActivity} (part/shard 1).
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java