LdapRdn implements Serializable, Comparable { public int compareTo(Object obj) { LdapRdn that = (LdapRdn) obj; if(this.components.size() != that.components.size()) { return this.components.size() - that.components.size(); } Set<Map.Entry<String,LdapRdnComponent>> theseEntries = this.components.entrySet(); for (Map.Entry<String, LdapRdnComponent> oneEntry : theseEntries) { LdapRdnComponent thatEntry = that.components.get(oneEntry.getKey()); if(thatEntry == null) { return -1; } int compared = oneEntry.getValue().compareTo(thatEntry); if(compared != 0) { return compared; } } return 0; } LdapRdn();  LdapRdn(String string);  LdapRdn(String key, String value); void addComponent(LdapRdnComponent rdnComponent); List getComponents(); LdapRdnComponent getComponent(); LdapRdnComponent getComponent(int idx); String getLdapEncoded(); String encodeUrl(); int compareTo(Object obj); boolean equals(Object obj); int hashCode(); String toString(); String getValue(); String getKey(); String getValue(String key); LdapRdn immutableLdapRdn();  }
@Test public void testCompareTo_Equals() throws Exception { LdapRdn rdn1 = new LdapRdn("cn=john doe"); LdapRdn rdn2 = new LdapRdn("cn=john doe"); int result = rdn1.compareTo(rdn2); assertThat(result).isEqualTo(0); }
@Test public void testCompareTo_EqualsComplex() throws Exception { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe"); LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe"); int result = rdn1.compareTo(rdn2); assertThat(result).isEqualTo(0); }
@Test public void testCompareTo_LessWithMissingKey() { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe"); LdapRdn rdn2 = new LdapRdn("cn=john doe+tn=doe"); int result = rdn1.compareTo(rdn2); assertThat(result < 0).isTrue(); }
@Test public void testCompareTo_LessWithExistingKey() { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doa"); LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe"); int result = rdn1.compareTo(rdn2); assertThat(result < 0).isTrue(); }
@Test public void testCompareTo_Greater() { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe"); LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doa"); int result = rdn1.compareTo(rdn2); assertThat(result > 0).isTrue(); }
@Test public void testCompareTo_Shorter() { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe"); LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe+description=tjo"); int result = rdn1.compareTo(rdn2); assertThat(result < 0).isTrue(); }
@Test public void testCompareTo_Longer() { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe+description=tjo"); LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe"); int result = rdn1.compareTo(rdn2); assertThat(result > 0).isTrue(); }