@Test
  public void testAddWithNullIssuer() {
    String accountName = "johndoe@dasher.com";
    // Add the account as a "Google Account" and verify the result
    accountDb.add(accountName, SECRET, OtpType.HOTP, 3, true, null);
    assertThat(accountDb.getAccounts()).containsExactly(index(accountName, null));
    validateAccountRecord(index(accountName, null), SECRET, OtpType.HOTP, 3, true);

    // Add with the same name again, which should create a new account with the
    // suffix "(1)"
    accountDb.add(accountName, SECRET2, OtpType.TOTP, 7, null, null);
    String accountName2 = accountName + "(1)";
    assertThat(accountDb.getAccounts())
        .containsExactly(index(accountName, null), index(accountName2, null));
    validateAccountRecord(index(accountName2, null), SECRET2, OtpType.TOTP, 7, false);
    // Check that the first account was unaffected
    validateAccountRecord(index(accountName, null), SECRET, OtpType.HOTP, 3, true);

    // And again, this time creating an account with suffix "(2)"
    // Use an empty string for issuer, which should be treated equivalently to a null
    accountDb.add(accountName, SECRET3, OtpType.TOTP, 1, false, "");
    String accountName3 = accountName + "(2)";
    assertThat(accountDb.getAccounts())
        .containsExactly(index(accountName, null), index(accountName2, null) , index(accountName3, null));
    validateAccountRecord(index(accountName3, null), SECRET3, OtpType.TOTP, 1, false);
    // Check that the other two accounts are unaffected
    validateAccountRecord(index(accountName2, null), SECRET2, OtpType.TOTP, 7, false);
    validateAccountRecord(index(accountName, null), SECRET, OtpType.HOTP, 3, true);

    // Test max duplicate account name limit
    String anotherAccountName = "janedoe@example.com";
    for (int i = 0; i < AccountDb.MAX_DUPLICATE_NAMES; i++) {
      accountDb.add(anotherAccountName, SECRET + i, OtpType.TOTP, null, false, null);
      String expectedAccountName = anotherAccountName + "(" + i + ")";
      if (i == 0) {
        expectedAccountName = anotherAccountName;
      }
      validateAccountRecord(index(expectedAccountName, null), SECRET + i, OtpType.TOTP, 0, false);
    }
    // Now add one more than the limit
    try {
      accountDb.add(anotherAccountName, SECRET, OtpType.TOTP, null, false, null);
      fail();
    } catch (AccountDb.AccountDbDuplicateLimitException expected) {
      // pass
    }
  }
A list of {@link TestAccount}s that all have issuers.
javatests/com/google/android/apps/authenticator/otp/AccountDbTest.java