@Test
  public void testFindSimilarExistingIndex() {
    addAllTestRecords(); // Just to provide some extra data
    String accountName = "bob@example.com";
    String issuer = "Some issuer";
    String prefixedName = issuer + ":" + accountName;
    String whitespaceName = issuer + ":   " + accountName + "   ";
    AccountIndex plainWithNoIssuer = new AccountIndex(accountName, null);
    AccountIndex prefixedWithNoIssuer = new AccountIndex(prefixedName, null);
    AccountIndex whitespaceWithNoIssuer = new AccountIndex(whitespaceName, null);
    AccountIndex plainWithIssuer = new AccountIndex(accountName, issuer);
    AccountIndex prefixedWithIssuer = new AccountIndex(prefixedName, issuer);
    AccountIndex whitespaceWithIssuer = new AccountIndex(whitespaceName, issuer);

    assertThat(accountDb.findSimilarExistingIndex(prefixedWithNoIssuer)).isNull();
    accountDb.add(prefixedName, "AAAAA", OtpType.TOTP, null, false, null);
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithNoIssuer))
        .isEqualTo(prefixedWithNoIssuer);
    // Stripped names are never "similar" for null issuers
    assertThat(accountDb.findSimilarExistingIndex(plainWithNoIssuer)).isNull();
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithIssuer)).isNull();

    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithNoIssuer)).isNull();
    accountDb.add(whitespaceName, "BBBBB", OtpType.TOTP, null, false, null);
    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithNoIssuer))
        .isEqualTo(whitespaceWithNoIssuer);

    assertThat(accountDb.findSimilarExistingIndex(plainWithIssuer)).isNull();
    accountDb.add(accountName, "CCCCC", OtpType.TOTP, null, false, issuer);
    assertThat(accountDb.findSimilarExistingIndex(plainWithIssuer)).isEqualTo(plainWithIssuer);
    // Now find it using similar but different indexes
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithIssuer)).isEqualTo(plainWithIssuer);
    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithIssuer)).isEqualTo(plainWithIssuer);
    // Should still not be similar to the case of no issuer
    assertThat(accountDb.findSimilarExistingIndex(plainWithNoIssuer)).isNull();

    accountDb.delete(plainWithIssuer);
    assertThat(accountDb.findSimilarExistingIndex(plainWithIssuer)).isNull();
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithIssuer)).isNull();
    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithIssuer)).isNull();
    accountDb.add(prefixedName, "DDDDD", OtpType.TOTP, null, false, issuer);
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithIssuer))
        .isEqualTo(prefixedWithIssuer);
    // Now find it using similar but different indexes
    assertThat(accountDb.findSimilarExistingIndex(plainWithIssuer)).isEqualTo(prefixedWithIssuer);
    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithIssuer))
        .isEqualTo(prefixedWithIssuer);

    accountDb.delete(prefixedWithIssuer);
    assertThat(accountDb.findSimilarExistingIndex(plainWithIssuer)).isNull();
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithIssuer)).isNull();
    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithIssuer)).isNull();
    accountDb.add(whitespaceName, "EEEEE", OtpType.TOTP, null, false, issuer);
    assertThat(accountDb.findSimilarExistingIndex(whitespaceWithIssuer))
        .isEqualTo(whitespaceWithIssuer);
    // Now find it using similar but different indexes
    assertThat(accountDb.findSimilarExistingIndex(plainWithIssuer)).isEqualTo(whitespaceWithIssuer);
    assertThat(accountDb.findSimilarExistingIndex(prefixedWithIssuer))
        .isEqualTo(whitespaceWithIssuer);
  }
A list of {@link TestAccount}s that all have issuers.
javatests/com/google/android/apps/authenticator/otp/AccountDbTest.java