@Test
  public void testAddAndOverwrite() {
    addAllTestRecords();
    int expectedNumAccounts = TEST_ACCOUNTS.length;
    for (TestAccount t : TEST_ACCOUNTS) {
      assertThat(accountDb.getAccounts()).hasSize(expectedNumAccounts);
      // Create a new secret each iteration
      String newSecret = "ZZZZZZZZZZZZZ"
          + ('A' + (char) (expectedNumAccounts % 26))
          + ('A' + (char) ((expectedNumAccounts / 26) % 26));

      // Try overwriting with an account that has the stripped name
      AccountIndex newIndex = index(t.getStrippedName(), t.getIssuer());
      if (!accountDb.addWillOverwriteExistingSeedFor(newIndex)) {
        expectedNumAccounts++;
      }
      accountDb.add(newIndex.getName(), newSecret, t.type, t.counter, false, newIndex.getIssuer());
      assertThat(accountDb.getAccounts()).hasSize(expectedNumAccounts);

      // Try overwriting with an account that has the full name
      newIndex = index(t.toString(), t.getIssuer());
      if (!accountDb.addWillOverwriteExistingSeedFor(newIndex)) {
        expectedNumAccounts++;
      }
      accountDb.add(newIndex.getName(), newSecret, t.type, t.counter, false, newIndex.getIssuer());
      assertThat(accountDb.getAccounts()).hasSize(expectedNumAccounts);
    }

    // Manual test
    AccountIndex first = index("LostPass:  whitespace@some.com", "LostPass");
    AccountIndex second = index("whitespace@some.com", "LostPass");
    AccountIndex third = index("LostPass:whitespace@some.com", "LostPass");

    assertThat(accountDb.addWillOverwriteExistingSeedFor(first)).isFalse();
    expectedNumAccounts++;
    accountDb.add(first.getName(), "AAAAAAAAAAAA", OtpType.TOTP, null, null, first.getIssuer());
    validateAccountRecord(first, "AAAAAAAAAAAA", OtpType.TOTP, 0, false);
    assertThat(accountDb.getAccounts()).hasSize(expectedNumAccounts);

    assertThat(accountDb.addWillOverwriteExistingSeedFor(second)).isTrue();
    assertThat(accountDb.addWillOverwriteExistingSeedFor(third)).isTrue();
    accountDb.add(second.getName(), "BBBBBBBBBBBB", OtpType.TOTP, null, null, second.getIssuer());
    validateAccountRecord(second, "BBBBBBBBBBBB", OtpType.TOTP, 0, false);
    accountDb.add(third.getName(), "CCCCCCCCCCCC", OtpType.TOTP, null, null, third.getIssuer());
    validateAccountRecord(third, "CCCCCCCCCCCC", OtpType.TOTP, 0, false);
    assertThat(accountDb.getAccounts()).hasSize(expectedNumAccounts);
  }
A list of {@link TestAccount}s that all have issuers.
javatests/com/google/android/apps/authenticator/otp/AccountDbTest.java