DistinguishedName implements PrincipalIndentifier, BcPrincipalIdentifier { @Override public byte[] getEncoded() throws IOException { return this.dn.getEncoded(); } DistinguishedName(Object name); @Override byte[] getEncoded(); @Override String getName(); @Override X500Name getX500Name(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test void equality() { PrincipalIndentifier john = new DistinguishedName("CN=John Doe"); PrincipalIndentifier jane = new DistinguishedName("CN=Jane Doe"); PrincipalIndentifier johnAlias = new DistinguishedName(new X500Name("CN=John Doe")); PrincipalIndentifier johnOtherImpl = new PrincipalIndentifier() { @Override public byte[] getEncoded() throws IOException { return new X500Name("CN=John Doe").getEncoded(); } @Override public String getName() { return "CN=John Doe"; } }; PrincipalIndentifier janeOtherImpl = new PrincipalIndentifier() { @Override public byte[] getEncoded() throws IOException { return new X500Name("CN=Jane Doe").getEncoded(); } @Override public String getName() { return "CN=Jane Doe"; } }; assertThat(john, equalTo(john)); assertThat(john, equalTo(johnAlias)); assertThat(john, equalTo(johnOtherImpl)); assertThat(john, not(equalTo(jane))); assertThat(jane, not(equalTo(john))); assertThat(john, not(equalTo(janeOtherImpl))); assertThat(john, not(equalTo(new Object()))); }