@Test
  public void testGetOtpWithMultipleAccounts() {
    accountDb.add(HOTP_ACCOUNT_NAME, "7777777777777777", OtpType.HOTP, null, null, null);
    accountDb.add(
        "johndoeTotp1@gmail.com",
        "2222222222222222",
        OtpType.TOTP,
        null,
        null,
        AccountDb.GOOGLE_ISSUER_NAME);

    activityTestRule.launchActivity(null);

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

    // check hotp account
    View listEntry0 = userList.getChildAt(0);
    String user = ((TextView) listEntry0.findViewById(R.id.current_user)).getText().toString();
    String pin =
        getOriginalPincode(
            ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString());
    assertThat(user).isEqualTo(HOTP_ACCOUNT_NAME);
    // starts empty
    assertThat(pin).isEqualTo(activityTestRule.getActivity().getString(R.string.empty_pin));
    assertThat(listEntry0.findViewById(R.id.countdown_icon).isShown()).isFalse();
    View buttonView = listEntry0.findViewById(R.id.next_otp);
    assertThat(buttonView.isShown()).isTrue();
    // get next Otp value by clicking icon
    TestUtilities.clickView(InstrumentationRegistry.getInstrumentation(), buttonView);
    listEntry0 = userList.getChildAt(0); // get refreshed value after clicking nextOtp button.
    pin =
        getOriginalPincode(
            ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString());
    assertThat(pin).isEqualTo(FIRST_HOTP_EXPECTED_PIN);

    // check first totp account
    View listEntry1 = userList.getChildAt(1);
    user = ((TextView) listEntry1.findViewById(R.id.current_user)).getText().toString();
    pin =
        getOriginalPincode(
            ((TextView) listEntry1.findViewById(R.id.pin_value)).getText().toString());
    assertThat(user)
        .isEqualTo(
            Utilities.getCombinedTextForIssuerAndAccountName(
                AccountDb.GOOGLE_ISSUER_NAME, "johndoeTotp1@gmail.com"));
    assertThat(Integer.parseInt(pin) > 0 && Integer.parseInt(pin) <= 999999).isTrue();
    assertThat(listEntry1.findViewById(R.id.next_otp).isShown()).isFalse();
    assertThat(listEntry1.findViewById(R.id.countdown_icon).isShown()).isTrue();
  }
Unit tests for {@link AuthenticatorActivity} (part/shard 1).
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java