MailboxAnnotationKey { public boolean isParentOrIsEqual(MailboxAnnotationKey key) { int thatComponentsSize = key.countComponents(); int thisComponentsSize = this.countComponents(); return (thatComponentsSize == thisComponentsSize || thatComponentsSize == thisComponentsSize + 1) && isAncestorOrIsEqual(key); } 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 isParentOrIsEqualShouldReturnTrueWhenSameKey() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); assertThat(key1.isParentOrIsEqual(key1)).isTrue(); }
@Test void isParentOrIsEqualShouldReturnTrueWhenParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); assertThat(key1.isParentOrIsEqual(key2)).isTrue(); }
@Test void isParentOrIsEqualShouldReturnFalseWhenChild() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); assertThat(key2.isParentOrIsEqual(key1)).isFalse(); }
@Test void isParentOrIsEqualShouldReturnFalseWhenGrandParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); assertThat(key1.isParentOrIsEqual(key2)).isFalse(); }
@Test void isParentOrIsEqualShouldReturnFalseWhenCousin() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); assertThat(key1.isParentOrIsEqual(key2)).isFalse(); }
@Test void isParentOrIsEqualShouldWorkOnCousinKeyUsingKeyAsAPrefix() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/tututata"); assertThat(key1.isParentOrIsEqual(key2)).isFalse(); }