MailboxAnnotationKey { public boolean isAncestorOrIsEqual(MailboxAnnotationKey key) { return asString().equals(key.asString()) || key.asString().startsWith(this.asString() + SLASH_CHARACTER); } MailboxAnnotationKey(String key); int countComponents(); String asString(); boolean isParentOrIsEqual(MailboxAnnotationKey key); boolean isAncestorOrIsEqual(MailboxAnnotationKey key); @Override boolean equals(Object obj); @Override int hashCode(); static final String SLASH_CHARACTER; static final String TWO_SLASH_CHARACTER; static final int MINIMUM_COMPONENTS; static final int MINIMUM_COMPONENTS_OF_VENDOR; static final int SECOND_COMPONENT_INDEX; static final String VENDOR_COMPONENT; }
@Test void isAncestorOrIsEqualShouldReturnTrueWhenSameKey() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); assertThat(key1.isAncestorOrIsEqual(key1)).isTrue(); }
@Test void isAncestorOrIsEqualShouldReturnTrueWhenParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); assertThat(key1.isAncestorOrIsEqual(key2)).isTrue(); }
@Test void isAncestorOrIsEqualShouldReturnFalseWhenChild() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); assertThat(key2.isAncestorOrIsEqual(key1)).isFalse(); }
@Test void isAncestorOrIsEqualShouldReturnTrueWhenGrandParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); assertThat(key1.isAncestorOrIsEqual(key2)).isTrue(); }
@Test void isAncestorOrIsEqualShouldReturnFalseWhenCousin() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); assertThat(key1.isAncestorOrIsEqual(key2)).isFalse(); }
@Test void isAncestorOrIsEqualShouldWorkOnCousinKeyUsingKeyAsAPrefix() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/tututata"); assertThat(key1.isAncestorOrIsEqual(key2)).isFalse(); }