You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/03/28 03:22:01 UTC
[james-project] 17/23: MAILBOX-388 MailRepositoryUrl::hasPrefix
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit cb97101180ce85ffe4a6d5f2f84bcfa077ac4dc2
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 21 15:35:06 2019 +0700
MAILBOX-388 MailRepositoryUrl::hasPrefix
---
.../mailrepository/api/MailRepositoryUrl.java | 5 ++
.../mailrepository/api/MailRepositoryUrlTest.java | 72 ++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrl.java b/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrl.java
index 7bd99b3..ae00938 100644
--- a/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrl.java
+++ b/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrl.java
@@ -91,6 +91,11 @@ public class MailRepositoryUrl {
return URLEncoder.encode(value, StandardCharsets.UTF_8.displayName());
}
+ public boolean hasPrefix(MailRepositoryUrl other) {
+ return Objects.equals(this.protocol, other.protocol)
+ && this.path.hasPrefix(other.path);
+ }
+
public Protocol getProtocol() {
return protocol;
}
diff --git a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
index f0842c3..3420906 100644
--- a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
+++ b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
@@ -117,4 +117,76 @@ public class MailRepositoryUrlTest {
assertThatThrownBy(() -> MailRepositoryUrl.from("proto://abc://def").subUrl("/ghi"))
.isInstanceOf(IllegalArgumentException.class);
}
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenEquals() {
+ assertThat(MailRepositoryUrl.from("proto://abc/def").hasPrefix(MailRepositoryUrl.from("proto://abc/def")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenSiblings() {
+ assertThat(MailRepositoryUrl.from("proto://abc/def").hasPrefix(MailRepositoryUrl.from("proto://abc/ghi")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenAncestor() {
+ assertThat(MailRepositoryUrl.from("proto://abc").hasPrefix(MailRepositoryUrl.from("proto://abc/ghi")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnTrueWhenDescendant() {
+ assertThat(MailRepositoryUrl.from("proto://abc/ghi").hasPrefix(MailRepositoryUrl.from("proto://abc")))
+ .isTrue();
+ }
+
+ @Test
+ void hasPrefixShouldReturnTrueWhenFarDescendant() {
+ assertThat(MailRepositoryUrl.from("proto://abc/ghi/klm").hasPrefix(MailRepositoryUrl.from("proto://abc")))
+ .isTrue();
+ }
+
+ @Test
+ void hasPrefixShouldReturnTrueWhenEmpty() {
+ assertThat(MailRepositoryUrl.from("proto://abc").hasPrefix(MailRepositoryUrl.from("proto://")))
+ .isTrue();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenBothEmpty() {
+ assertThat(MailRepositoryUrl.from("proto://").hasPrefix(MailRepositoryUrl.from("proto://")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenMissingSlah() {
+ assertThat(MailRepositoryUrl.from("proto://abcghi").hasPrefix(MailRepositoryUrl.from("proto://abc")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenDifferentProtocol() {
+ assertThat(MailRepositoryUrl.from("proto://abc/ghi").hasPrefix(MailRepositoryUrl.from("proto2://abc")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnTrueWhenDescendantStartingWithSlash() {
+ assertThat(MailRepositoryUrl.from("proto:///abc/ghi").hasPrefix(MailRepositoryUrl.from("proto:///abc")))
+ .isTrue();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenDescendantAdditionalFirstSlash() {
+ assertThat(MailRepositoryUrl.from("proto://abc/ghi").hasPrefix(MailRepositoryUrl.from("proto:///abc")))
+ .isFalse();
+ }
+
+ @Test
+ void hasPrefixShouldReturnFalseWhenDescendantMissingFirstSlash() {
+ assertThat(MailRepositoryUrl.from("proto:///abc/ghi").hasPrefix(MailRepositoryUrl.from("proto://abc")))
+ .isFalse();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org