MAILBOX-310 Mailbox query refactoring: Copy mailboxPath matching in external 
class hierarchy


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2c048997
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2c048997
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2c048997

Branch: refs/heads/master
Commit: 2c048997b95815befe9ed8630e3bdd3ca9fefc44
Parents: cd37438
Author: benwa <btell...@linagora.com>
Authored: Wed Oct 4 11:27:25 2017 +0700
Committer: Matthieu Baechler <matth...@apache.org>
Committed: Thu Oct 5 20:00:38 2017 +0200

----------------------------------------------------------------------
 .../apache/james/mailbox/model/ExactName.java   |   48 +
 .../mailbox/model/MailboxNameExpression.java    |   38 +
 .../james/mailbox/model/PrefixedRegex.java      |  112 ++
 .../james/mailbox/model/PrefixedWildcard.java   |   47 +
 .../apache/james/mailbox/model/Wildcard.java    |   40 +
 .../james/mailbox/model/ExactNameTest.java      |   67 +
 .../james/mailbox/model/MailboxQueryTest.java   | 1615 ------------------
 .../james/mailbox/model/PrefixedRegexTest.java  | 1058 ++++++++++++
 .../mailbox/model/PrefixedWildcardTest.java     |   71 +
 .../james/mailbox/model/WildcardTest.java       |   59 +
 10 files changed, 1540 insertions(+), 1615 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/main/java/org/apache/james/mailbox/model/ExactName.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/ExactName.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/ExactName.java
new file mode 100644
index 0000000..298819e
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/ExactName.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.model;
+
+import com.google.common.base.Preconditions;
+
+public class ExactName implements MailboxNameExpression {
+
+    private final String name;
+
+    public ExactName(String name) {
+        Preconditions.checkNotNull(name);
+        this.name = name;
+    }
+
+    @Override
+    public boolean isExpressionMatch(String mailboxName) {
+        Preconditions.checkNotNull(mailboxName);
+        return name.equals(mailboxName);
+    }
+
+    @Override
+    public String getCombinedName() {
+        return name;
+    }
+
+    @Override
+    public boolean isWild() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxNameExpression.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxNameExpression.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxNameExpression.java
new file mode 100644
index 0000000..ec7d715
--- /dev/null
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxNameExpression.java
@@ -0,0 +1,38 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.model;
+
+interface MailboxNameExpression {
+    /**
+     * Use this wildcard to match every char including the hierarchy delimiter
+     */
+    char FREEWILDCARD = '*';
+
+    /**
+     * Use this wildcard to match every char except the hierarchy delimiter
+     */
+    char LOCALWILDCARD = '%';
+
+    boolean isExpressionMatch(String name);
+
+    String getCombinedName();
+
+    boolean isWild();
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedRegex.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedRegex.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedRegex.java
new file mode 100644
index 0000000..fa1d30f
--- /dev/null
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedRegex.java
@@ -0,0 +1,112 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.model;
+
+import java.util.Optional;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+
+public class PrefixedRegex implements MailboxNameExpression {
+
+    private final String prefix;
+    private final String regex;
+    private final Pattern pattern;
+    private final char pathDelimiter;
+
+    public PrefixedRegex(String prefix, String regex, char pathDelimiter) {
+        this.prefix = Optional.ofNullable(prefix).orElse("");
+        this.regex = Optional.ofNullable(regex).orElse("");
+        this.pathDelimiter = pathDelimiter;
+        this.pattern = constructEscapedRegex(this.regex);
+    }
+
+    @Override
+    public boolean isExpressionMatch(String name) {
+        return name.startsWith(prefix)
+            && regexMatching(name.substring(prefix.length()));
+    }
+
+    private boolean regexMatching(String name) {
+        if (isWild()) {
+            return name != null
+                && pattern.matcher(name).matches();
+        } else {
+            return regex.equals(name);
+        }
+    }
+
+    @Override
+    public String getCombinedName() {
+        if (prefix != null && prefix.length() > 0) {
+            final int baseLength = prefix.length();
+            if (prefix.charAt(baseLength - 1) == pathDelimiter) {
+                if (regex != null && regex.length() > 0) {
+                    if (regex.charAt(0) == pathDelimiter) {
+                        return prefix + regex.substring(1);
+                    } else {
+                        return prefix + regex;
+                    }
+                } else {
+                    return prefix;
+                }
+            } else {
+                if (regex != null && regex.length() > 0) {
+                    if (regex.charAt(0) == pathDelimiter) {
+                        return prefix + regex;
+                    } else {
+                        return prefix + pathDelimiter + regex;
+                    }
+                } else {
+                    return prefix;
+                }
+            }
+        } else {
+            return regex;
+        }
+    }
+
+    @Override
+    public boolean isWild() {
+        return regex != null
+            && (
+            regex.indexOf(FREEWILDCARD) >= 0
+                || regex.indexOf(LOCALWILDCARD) >= 0);
+    }
+
+    private Pattern constructEscapedRegex(String regex) {
+        StringBuilder stringBuilder = new StringBuilder();
+        StringTokenizer tokenizer = new StringTokenizer(regex, "*%", true);
+        while (tokenizer.hasMoreTokens()) {
+            stringBuilder.append(getRegexPartAssociatedWithToken(tokenizer));
+        }
+        return Pattern.compile(stringBuilder.toString());
+    }
+
+    private String getRegexPartAssociatedWithToken(StringTokenizer tokenizer) {
+        String token = tokenizer.nextToken();
+        if (token.equals("*")) {
+            return ".*";
+        } else if (token.equals("%")) {
+            return "[^" + Pattern.quote(String.valueOf(pathDelimiter)) + "]*";
+        } else {
+            return Pattern.quote(token);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedWildcard.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedWildcard.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedWildcard.java
new file mode 100644
index 0000000..d767038
--- /dev/null
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PrefixedWildcard.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.model;
+
+import com.google.common.base.Preconditions;
+
+public class PrefixedWildcard implements MailboxNameExpression {
+
+    private final String prefix;
+
+    public PrefixedWildcard(String prefix) {
+        Preconditions.checkNotNull(prefix);
+        this.prefix = prefix;
+    }
+
+    @Override
+    public boolean isExpressionMatch(String name) {
+        return name.startsWith(prefix);
+    }
+
+    @Override
+    public String getCombinedName() {
+        return prefix + FREEWILDCARD;
+    }
+
+    @Override
+    public boolean isWild() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/main/java/org/apache/james/mailbox/model/Wildcard.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Wildcard.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Wildcard.java
new file mode 100644
index 0000000..a8c4c23
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Wildcard.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.model;
+
+import com.google.common.base.Preconditions;
+
+public class Wildcard implements MailboxNameExpression {
+    @Override
+    public boolean isExpressionMatch(String name) {
+        Preconditions.checkNotNull(name);
+        return true;
+    }
+
+    @Override
+    public String getCombinedName() {
+        return String.valueOf(FREEWILDCARD);
+    }
+
+    @Override
+    public boolean isWild() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/test/java/org/apache/james/mailbox/model/ExactNameTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/ExactNameTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/ExactNameTest.java
new file mode 100644
index 0000000..9072503
--- /dev/null
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/ExactNameTest.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+
+public class ExactNameTest {
+
+    public static final String NAME = "toto";
+
+    @Test
+    public void constructorShouldThrowOnNullName() {
+        assertThatThrownBy(() -> new ExactName(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void isWildShouldReturnFalse() {
+        assertThat(new ExactName(NAME).isWild())
+            .isFalse();
+    }
+
+    @Test
+    public void getCombinedNameShouldReturnName() {
+        assertThat(new ExactName(NAME).getCombinedName())
+            .isEqualTo(NAME);
+    }
+
+    @Test
+    public void isExpressionMatchShouldReturnTrueWhenName() {
+        assertThat(new ExactName(NAME).isExpressionMatch(NAME))
+            .isTrue();
+    }
+
+    @Test
+    public void isExpressionMatchShouldReturnFalseWhenOtherValue() {
+        assertThat(new ExactName(NAME).isExpressionMatch("other"))
+            .isFalse();
+    }
+
+    @Test
+    public void isExpressionMatchShouldThrowOnNullValue() {
+        assertThatThrownBy(() -> new ExactName(NAME).isExpressionMatch(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c048997/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxQueryTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxQueryTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxQueryTest.java
index a3149f8..1656bc0 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxQueryTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxQueryTest.java
@@ -44,1621 +44,6 @@ public class MailboxQueryTest {
     }
 
     @Test
-    public void IsWildShouldReturnTrueWhenOnlyFreeWildcard() throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .matchesAll()
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenOnlyLocalWildcard() throws Exception 
{
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenFreeWildcardAtBeginning() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*One")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenLocalWildcardAtBeginning() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%One")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenFreeWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("A*A")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenLocalWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("A%A")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenFreeWildcardAtEnd() throws Exception 
{
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("One*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnTrueWhenLocalWildcardAtEnd() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("One%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void IsWildShouldReturnFalseWhenEmptyExpression() throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void IsWildShouldReturnFalseWhenNullExpression() throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression(null)
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void IsWildShouldReturnFalseWhenNoWildcard() throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("ONE")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isWild();
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void getCombinedNameShouldWork() throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        String actual = testee.getCombinedName();
-        //Then
-        assertThat(actual).isEqualTo("name.mailbox");
-    }
-
-    @Test
-    public void getCombinedNameShouldWorkWhenEmptyExpression() throws 
Exception { 
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        String actual = testee.getCombinedName();
-        //Then
-        assertThat(actual).isEqualTo("name");
-    }
-
-    @Test
-    public void 
getCombinedNameShouldReturnEmptyStringWhenNullMailboxPathAndExpression() throws 
Exception {
-        //Given
-        MailboxPath nullMailboxPath = new MailboxPath(null, null, null);
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(nullMailboxPath)
-            .expression(null)
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        String actual = testee.getCombinedName();
-        //Then
-        assertThat(actual).isEmpty();
-    }
-
-    @Test
-    public void 
getCombinedNameShouldIgnoreDelimiterWhenPresentAtBeginningOfExpression() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression(".mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        String actual = testee.getCombinedName();
-        //Then
-        assertThat(actual).isEqualTo("name.mailbox");
-    }
-
-    @Test
-    public void 
getCombinedNameShouldIgnoreDelimiterWhenPresentAtEndOfMailboxName() throws 
Exception {
-        //Given
-        MailboxPath mailboxPathWithNullNamespaceAndUser = new 
MailboxPath(null, null, "name.");
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPathWithNullNamespaceAndUser)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        String actual = testee.getCombinedName();
-        //Then
-        assertThat(actual).isEqualTo("name.mailbox");
-    }
-
-    @Test
-    public void 
getCombinedNameShouldIgnoreDelimiterWhenPresentAtBeginningOfExpressionAndEndOfMailboxName()
 throws Exception {
-        //Given
-        MailboxPath mailboxPathWithNullNamespaceAndUser = new 
MailboxPath(null, null, "name.");
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPathWithNullNamespaceAndUser)
-            .expression(".mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        String actual = testee.getCombinedName();
-        //Then
-        assertThat(actual).isEqualTo("name.mailbox");
-    }
-
-    @Test
-    public void isExpressionMatchShouldReturnFalseWhenNullExpression() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression(null)
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("folder");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test 
-    public void isExpressionMatchShouldMatchFolderWhenMatching() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenNameBeginsWithDelimiter() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch(".mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldReturnFalseWhenNameEndsWithDelimiter() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldNotMatchFolderWhenNoMatching() throws 
Exception {
-        //Given
-
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldNotMatchFolderWithExpandedEndName() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox123");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldNotMatchSubFolder() throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.123");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldReturnTrueWhenEmptyNameAndExpression() 
throws Exception {
-        //Given
-
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyExpressionAndNameBeginsWithDelimiter()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch(".123");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldNotMatchFolderWhenEmptyExpression() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("folder");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnTrueWhenEmptyNameAndOnlyLocalWildcard() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldReturnTrueWhenOnlyLocalWildcard() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("folder");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenOnlyLocalWildcard() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnTrueWhenEmptyNameAndOnlyFreeWildcard() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .matchesAll()
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldMatchFolderWhenOnlyFreeWildcard() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .matchesAll()
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldMatchSubFolderWhenOnlyFreeWildcard() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .matchesAll()
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.sub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalWildcardAtEnd() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenLocalWildcardAtEndAndNoMatching() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenLocalWildcardAtEndNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldReturnTrueWhenLocalWildcardAtEndUsed() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailboxsub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardAtEnd() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalWildcardAtBeginning() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenLocalWildcardAtBeginningAndNoMatching()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenLocalWildcardAtBeginningNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenLocalWildcardAtBeginningUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardAtBeginning() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenLocalWildcardAtBeginning() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenLocalWildcardInMiddleAndMissingEndName() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenLocalWildcardInMiddleAndMatching() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldMatchFolderWhenLocalWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub123mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardInMiddleAndExpandedMiddleName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.123mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenLocalWildcardInMiddleAndMissingBeginningName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenLocalWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldMatchSubFolderWhenFreeWildcardAtEnd() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.sub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeWildcardAtEnd() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenFreeWildcardAtEndAndNoMatching() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenFreeWildcardAtEndNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldMatchFolderWhenFreeWildcardAtEndUsed() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("mailbox*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox123");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeWildcardAtBeginning() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenFreeWildcardAtBeginningAndNoMatching() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenFreeWildcardAtBeginningNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenFreeWildcardAtBeginningUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenFreeWildcardAtBeginning() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenFreeWildcardInMiddleAndMissingEndName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenFreeWildcardInMiddleNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenFreeWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenFreeWildcardInMiddleNotUsedAndMissingBeginningName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFolderWhenFreeWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndDoubleFreeWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub**mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenDoubleFreeWildcardInMiddleAndMissingEndName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub**mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnTrueWhenDoubleFreeWildcardInMiddleNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub**mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenDoubleFreeWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub**mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenDoubleFreeWildcardInMiddleAndMissingBeginningName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub**mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFolderWhenDoubleFreeWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub**mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeLocalWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    } 
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenFreeLocalWildcardInMiddleAndMissingEndName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenFreeLocalWildcardInMiddleNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenFreeLocalWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenFreeLocalWildcardInMiddleAndMissingBeginningName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFolderWhenFreeLocalWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*%mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalFreeWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("");
-        //Then
-        assertThat(actual).isFalse();
-    } 
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenLocalFreeWildcardInMiddleAndMissingEndName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenLocalFreewildcardInMiddleNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenLocalFreeWildcardInMiddle() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenLocalFreeWildcardInMiddleAndMissingBeginningName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFolderWhenLocalFreeWildcardInMiddle() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%*mailbox")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldMatchFolderWhenMultipleFreeWildcards() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox*sub**")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailboxsub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFolderWhenMultipleFreeWildcardsNotUsed()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox*sub**")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailbox.sub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFolderWhenMultipleFreeWildcardsUsed() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox*sub**")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = 
testee.isExpressionMatch("subtosh.boshmailboxtosh.boshsubboshtosh");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMultipleFreeWildcardsAndMissingMiddleName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox*sub**")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.a.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMultipleFreeWildcardsAndMissingEndName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox*sub**")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.a.submailbox.u");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMultipleFreeWildcardsAndMissingBeginningdName()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox*sub**")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = 
testee.isExpressionMatch("utosh.boshmailboxtosh.boshsubasubboshtoshmailboxu");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenMixedLocalFreeWildcardsNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox*sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailboxsub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenMixedLocalFreeWildcards() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub%mailbox*sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailboxsub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenMixedFreeLocalWildcardsNotUsed() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailboxsub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenMixedFreeLocalWildcards() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailboxsub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenMixedFreeLocalWildcards() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailbox.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchFolderWhenMixedFreeLocalWildcards() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailboxwhateversub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderEndingWithDelimiterWhenMixedFreeLocalWildcards()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("submailboxsub.Whatever.");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMixedFreeLocalWildcards() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailboxsub.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFoldeWhenMixedFreeLocalWildcards() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("sub.mailboxsub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchDeeplyNestedFoldeWhenMixedFreeLocalWildcards() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("sub*mailbox%sub")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = 
testee.isExpressionMatch("sub.whatever.mailbox123sub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchFolderWhenTwoLocalPathDelimitedWildcards() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%.%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenTwoLocalPathDelimitedWildcards()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%.%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.sub.sub");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenTwoLocalPathDelimitedWildcards() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("%.%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("mailbox.sub");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldMatchSubFolderWhenFreeWildcardAndPathDelimiterAtBeginning()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*.test")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("blah.test");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchSubFolderWhenWhenFreeWildcardAndPathDelimiterAtBeginning()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*.test")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("blah.test3");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenFreeWildcardAndPathDelimiterAtBeginning()
 throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("*.test")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("blah.test.go");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void isExpressionMatchShouldIgnoreRegexInjection() throws Exception 
{
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("folder^$!)(%3")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("folder^$!)(123");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldIgnoreRegexInjectionWhenUsingEndOfQuoteAndNoMatching() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("\\Efo.")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("\\Efol");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldIgnoreRegexInjectionWhenUsingEndOfQuoteAndMatching() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("\\Efo.")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("\\Efo.");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldIgnoreRegexInjectionWhenUsingBeginOfQuoteAndNoMatching() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("\\Qfo?")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("\\Qfol");
-        //Then
-        assertThat(actual).isFalse();
-    }
-
-    @Test
-    public void 
isExpressionMatchShouldIgnoreRegexInjectionWhenUsingBeginOfQuoteAndMatching() 
throws Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("\\Qfo?")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("\\Qfo?");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldNotEscapeFreeWildcard() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("folder\\*")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("folder\\123");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
-    public void isExpressionMatchShouldNotEscapeLocalWildcard() throws 
Exception {
-        //Given
-        MailboxQuery testee = MailboxQuery.builder()
-            .base(mailboxPath)
-            .expression("folder\\%")
-            .mailboxSession(mailboxSession)
-            .build();
-        //When
-        boolean actual = testee.isExpressionMatch("folder\\123");
-        //Then
-        assertThat(actual).isTrue();
-    }
-
-    @Test
     public void buildShouldMatchAllValuesWhenMatchesAll() throws Exception {
         //When
         MailboxQuery actual = MailboxQuery.builder()


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to