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 ma...@apache.org on 2017/10/05 18:02:23 UTC
[11/27] james-project git commit: MAILBOX-310 Mailbox query
refactoring: Create dedicated packages for Mailbox search related classes
http://git-wip-us.apache.org/repos/asf/james-project/blob/0cfb3951/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedRegexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedRegexTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedRegexTest.java
deleted file mode 100644
index 69b4ec9..0000000
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedRegexTest.java
+++ /dev/null
@@ -1,1058 +0,0 @@
-/****************************************************************
- * 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 org.junit.Test;
-
-public class PrefixedRegexTest {
- private static final char PATH_DELIMITER = '.';
- private static final String PREFIX = "name";
- private static final String EMPTY_PREFIX = "";
-
- @Test
- public void isWildShouldReturnTrueWhenOnlyFreeWildcard() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "*", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenOnlyLocalWildcard() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "%", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenFreeWildcardAtBeginning() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "*One", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenLocalWildcardAtBeginning() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "%One", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenFreeWildcardInMiddle() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "A*A", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenLocalWildcardInMiddle() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "A%A", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenFreeWildcardAtEnd() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "One*", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnTrueWhenLocalWildcardAtEnd() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "One%", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isWildShouldReturnFalseWhenEmptyExpression() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isWildShouldReturnFalseWhenNullExpression() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, null, PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isWildShouldReturnFalseWhenNoWildcard() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "ONE", PATH_DELIMITER);
-
- boolean actual = prefixedRegex.isWild();
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void getCombinedNameShouldWork() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "mailbox", PATH_DELIMITER);
-
- String actual = prefixedRegex.getCombinedName();
-
- assertThat(actual).isEqualTo("name.mailbox");
- }
-
- @Test
- public void getCombinedNameShouldWorkWhenEmptyExpression() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "", PATH_DELIMITER);
-
- String actual = prefixedRegex.getCombinedName();
-
- assertThat(actual).isEqualTo("name");
- }
-
- @Test
- public void getCombinedNameShouldReturnEmptyStringWhenNullMailboxPathAndExpression() throws Exception {
- String prefix = null;
- String regex = null;
- PrefixedRegex prefixedRegex = new PrefixedRegex(prefix, regex, PATH_DELIMITER);
-
- String actual = prefixedRegex.getCombinedName();
-
- assertThat(actual).isEmpty();
- }
-
- @Test
- public void getCombinedNameShouldIgnoreDelimiterWhenPresentAtBeginningOfExpression() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, ".mailbox", PATH_DELIMITER);
-
- String actual = prefixedRegex.getCombinedName();
-
- assertThat(actual).isEqualTo("name.mailbox");
- }
-
- @Test
- public void getCombinedNameShouldIgnoreDelimiterWhenPresentAtEndOfMailboxName() throws Exception {
- PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX + ".", ".mailbox", PATH_DELIMITER);
-
- String actual = prefixedRegex.getCombinedName();
-
- assertThat(actual).isEqualTo("name.mailbox");
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenNullExpression() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(PREFIX, null, PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("folder");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenNameBeginsWithDelimiter() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch(".mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenNameEndsWithDelimiter() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWithExpandedEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox123");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolder() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.123");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenEmptyNameAndExpression() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyExpressionAndNameBeginsWithDelimiter() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch(".123");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenEmptyExpression() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("folder");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenEmptyNameAndOnlyLocalWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenOnlyLocalWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("folder");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenOnlyLocalWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenEmptyNameAndOnlyFreeWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenOnlyFreeWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenOnlyFreeWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.sub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalWildcardAtEnd() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenLocalWildcardAtEndAndNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenLocalWildcardAtEndNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenLocalWildcardAtEndUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailboxsub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardAtEnd() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalWildcardAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenLocalWildcardAtBeginningAndNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenLocalWildcardAtBeginningNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenLocalWildcardAtBeginningUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenLocalWildcardAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenLocalWildcardInMiddleAndMissingEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenLocalWildcardInMiddleAndMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub123mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenLocalWildcardInMiddleAndExpandedMiddleName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.123mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenLocalWildcardInMiddleAndMissingBeginningName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenFreeWildcardAtEnd() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.sub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeWildcardAtEnd() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenFreeWildcardAtEndAndNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenFreeWildcardAtEndNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenFreeWildcardAtEndUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "mailbox*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox123");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeWildcardAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenFreeWildcardAtBeginningAndNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenFreeWildcardAtBeginningNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenFreeWildcardAtBeginningUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenFreeWildcardAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenFreeWildcardInMiddleAndMissingEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenFreeWildcardInMiddleNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenFreeWildcardInMiddleNotUsedAndMissingBeginningName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFolderWhenFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndDoubleFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub**mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenDoubleFreeWildcardInMiddleAndMissingEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub**mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenDoubleFreeWildcardInMiddleNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub**mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenDoubleFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub**mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenDoubleFreeWildcardInMiddleAndMissingBeginningName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub**mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFolderWhenDoubleFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub**mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndFreeLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenFreeLocalWildcardInMiddleAndMissingEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenFreeLocalWildcardInMiddleNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenFreeLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenFreeLocalWildcardInMiddleAndMissingBeginningName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFolderWhenFreeLocalWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*%mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenEmptyNameAndLocalFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenLocalFreeWildcardInMiddleAndMissingEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenLocalFreewildcardInMiddleNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenLocalFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenLocalFreeWildcardInMiddleAndMissingBeginningName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFolderWhenLocalFreeWildcardInMiddle() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%*mailbox", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("subw.hat.eve.rmailbox");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenMultipleFreeWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox*sub**", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailboxsub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFolderWhenMultipleFreeWildcardsNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox*sub**", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailbox.sub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFolderWhenMultipleFreeWildcardsUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox*sub**", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("subtosh.boshmailboxtosh.boshsubboshtosh");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMultipleFreeWildcardsAndMissingMiddleName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox*sub**", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.a.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMultipleFreeWildcardsAndMissingEndName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox*sub**", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.a.submailbox.u");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMultipleFreeWildcardsAndMissingBeginningdName() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox*sub**", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("utosh.boshmailboxtosh.boshsubasubboshtoshmailboxu");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenMixedLocalFreeWildcardsNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox*sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailboxsub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenMixedLocalFreeWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub%mailbox*sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailboxsub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenMixedFreeLocalWildcardsNotUsed() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailboxsub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailboxsub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailbox.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchFolderWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailboxwhateversub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderEndingWithDelimiterWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("submailboxsub.Whatever.");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailboxsub.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFoldeWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.mailboxsub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchDeeplyNestedFoldeWhenMixedFreeLocalWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "sub*mailbox%sub", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("sub.whatever.mailbox123sub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchFolderWhenTwoLocalPathDelimitedWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%.%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenTwoLocalPathDelimitedWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%.%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.sub.sub");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenTwoLocalPathDelimitedWildcards() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "%.%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("mailbox.sub");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchSubFolderWhenFreeWildcardAndPathDelimiterAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*.test", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("blah.test");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchSubFolderWhenWhenFreeWildcardAndPathDelimiterAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*.test", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("blah.test3");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldNotMatchDeeplyNestedFolderWhenFreeWildcardAndPathDelimiterAtBeginning() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "*.test", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("blah.test.go");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldIgnoreRegexInjection() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "folder^$!)(%3", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("folder^$!)(123");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldIgnoreRegexInjectionWhenUsingEndOfQuoteAndNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "\\Efo.", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("\\Efol");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldIgnoreRegexInjectionWhenUsingEndOfQuoteAndMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "\\Efo.", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("\\Efo.");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldIgnoreRegexInjectionWhenUsingBeginOfQuoteAndNoMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "\\Qfo?", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("\\Qfol");
-
- assertThat(actual).isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldIgnoreRegexInjectionWhenUsingBeginOfQuoteAndMatching() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "\\Qfo?", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("\\Qfo?");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotEscapeFreeWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "folder\\*", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("folder\\123");
-
- assertThat(actual).isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldNotEscapeLocalWildcard() throws Exception {
- PrefixedRegex testee = new PrefixedRegex(EMPTY_PREFIX, "folder\\%", PATH_DELIMITER);
-
- boolean actual = testee.isExpressionMatch("folder\\123");
-
- assertThat(actual).isTrue();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/0cfb3951/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedWildcardTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedWildcardTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedWildcardTest.java
deleted file mode 100644
index 85af043..0000000
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/PrefixedWildcardTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************
- * 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 PrefixedWildcardTest {
- public static final String NAME = "toto";
-
- @Test
- public void constructorShouldThrowOnNullName() {
- assertThatThrownBy(() -> new PrefixedWildcard(null))
- .isInstanceOf(NullPointerException.class);
- }
-
- @Test
- public void isWildShouldReturnTrue() {
- assertThat(new PrefixedWildcard(NAME).isWild())
- .isTrue();
- }
-
- @Test
- public void getCombinedNameShouldReturnName() {
- assertThat(new PrefixedWildcard(NAME).getCombinedName())
- .isEqualTo(NAME + MailboxNameExpression.FREEWILDCARD);
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenName() {
- assertThat(new PrefixedWildcard(NAME).isExpressionMatch(NAME))
- .isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnTrueWhenNameAndPostfix() {
- assertThat(new PrefixedWildcard(NAME).isExpressionMatch(NAME + "any"))
- .isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldReturnFalseWhenOtherValue() {
- assertThat(new PrefixedWildcard(NAME).isExpressionMatch("other"))
- .isFalse();
- }
-
- @Test
- public void isExpressionMatchShouldThrowOnNullValue() {
- assertThatThrownBy(() -> new PrefixedWildcard(NAME).isExpressionMatch(null))
- .isInstanceOf(NullPointerException.class);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/0cfb3951/mailbox/api/src/test/java/org/apache/james/mailbox/model/WildcardTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/WildcardTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/WildcardTest.java
deleted file mode 100644
index 714e73d..0000000
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/WildcardTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************
- * 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 WildcardTest {
-
- @Test
- public void isWildShouldBeTrue() {
- assertThat(new Wildcard().isWild())
- .isTrue();
- }
-
- @Test
- public void getCombinedNameShouldReturnWildcard() {
- assertThat(new Wildcard().getCombinedName())
- .isEqualTo(String.valueOf(MailboxNameExpression.FREEWILDCARD));
- }
-
- @Test
- public void isExpressionMatchShouldMatchAnyValue() {
- assertThat(new Wildcard().isExpressionMatch("any"))
- .isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldMatchEmptyValue() {
- assertThat(new Wildcard().isExpressionMatch(""))
- .isTrue();
- }
-
- @Test
- public void isExpressionMatchShouldThrowOnNullValue() {
- assertThatThrownBy(() -> new Wildcard().isExpressionMatch(null))
- .isInstanceOf(NullPointerException.class);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/0cfb3951/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/ExactNameTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/ExactNameTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/ExactNameTest.java
new file mode 100644
index 0000000..c63bf00
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/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.search;
+
+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/0cfb3951/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
new file mode 100644
index 0000000..7f59c12
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
@@ -0,0 +1,267 @@
+/*
+ * 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.search;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxSession.User;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.search.MailboxQuery.Builder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MailboxQueryTest {
+ private static final String CURRENT_USER = "user";
+
+ private MailboxPath mailboxPath;
+ private MailboxSession mailboxSession;
+
+ @Before
+ public void setUp() {
+ mailboxPath = new MailboxPath("namespace", "user", "name");
+ mailboxSession = new MockMailboxSession("user");
+ }
+
+ @Test
+ public void buildShouldMatchAllValuesWhenMatchesAll() throws Exception {
+ //When
+ MailboxQuery actual = MailboxQuery.builder()
+ .base(mailboxPath)
+ .matchesAll()
+ .mailboxSession(mailboxSession)
+ .build();
+ //Then
+ assertThat(actual.isExpressionMatch("folder")).isTrue();
+ }
+
+ @Test
+ public void buildShouldConstructMailboxPathWhenPrivateUserMailboxes() throws Exception {
+ //Given
+ MailboxPath expected = MailboxPath.forUser("user", "");
+ //When
+ MailboxQuery actual = MailboxQuery.builder()
+ .username("user")
+ .privateMailboxes()
+ .mailboxSession(mailboxSession)
+ .build();
+ //Then
+ assertThat(actual.getNamespace()).contains(expected.getNamespace());
+ assertThat(actual.getUser()).contains(expected.getUser());
+ assertThat(actual.getBaseName()).contains(expected.getName());
+ }
+
+ @Test
+ public void buildShouldMatchAllValuesWhenPrivateUserMailboxes() throws Exception {
+ //Given
+ Builder testee = MailboxQuery.builder()
+ .username("user")
+ .privateMailboxes()
+ .mailboxSession(mailboxSession);
+ //When
+ MailboxQuery actual = testee.build();
+ //Then
+ assertThat(actual.isExpressionMatch("folder")).isTrue();
+ }
+
+ @Test
+ public void builderShouldInitFromSessionWhenGiven() throws Exception {
+ //Given
+ MailboxSession mailboxSession = mock(MailboxSession.class);
+ when(mailboxSession.getPathDelimiter()).thenReturn('#');
+ User user = mock(User.class);
+ when(user.getUserName()).thenReturn("little bobby table");
+ when(mailboxSession.getUser()).thenReturn(user);
+ // When
+ Builder query = MailboxQuery.privateMailboxesBuilder(mailboxSession);
+ //Then
+ assertThat(query.pathDelimiter).contains('#');
+ assertThat(query.username).contains("little bobby table");
+ }
+
+ @Test
+ public void builderShouldNotThrowWhenNoBaseDefined() throws Exception {
+ //Given
+ Builder testee = MailboxQuery.builder()
+ .expression("abc")
+ .mailboxSession(mailboxSession);
+ //When
+ testee.build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void builderShouldThrowWhenBaseAndUsernameGiven() throws Exception {
+ //Given
+ Builder testee = MailboxQuery.builder()
+ .base(mailboxPath)
+ .username("user");
+ //When
+ testee.build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void builderShouldThrowWhenBaseGiven() throws Exception {
+ //Given
+ Builder testee = MailboxQuery.builder()
+ .base(mailboxPath)
+ .privateMailboxes();
+ //When
+ testee.build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void builderShouldThrowWhenMissingUsername() throws Exception {
+ //Given
+ Builder testee = MailboxQuery.builder()
+ .privateMailboxes();
+ //When
+ testee.build();
+ }
+
+ @Test
+ public void builderShouldUseBaseWhenGiven() throws Exception {
+ //When
+ MailboxQuery actual = MailboxQuery.builder()
+ .base(mailboxPath)
+ .mailboxSession(mailboxSession)
+ .build();
+ //Then
+ assertThat(actual.getNamespace()).contains(mailboxPath.getNamespace());
+ assertThat(actual.getUser()).contains(mailboxPath.getUser());
+ assertThat(actual.getBaseName()).contains(mailboxPath.getName());
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnTrueWithIdenticalMailboxes() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(mailboxPath)
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath))
+ .isTrue();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnTrueWithIdenticalMailboxesWithNullUser() {
+ MailboxPath base = new MailboxPath("namespace", null, "name");
+
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(base)
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath))
+ .isTrue();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnTrueWithIdenticalMailboxesWithNullNamespace() {
+ MailboxPath mailboxPath = new MailboxPath(null, "user", "name");
+
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(mailboxPath)
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath))
+ .isTrue();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnTrueWithMailboxWithSameNamespaceAndUserWithNullUser() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", null, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", null, "name")))
+ .isTrue();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnTrueWithMailboxWithSameNamespaceAndUser() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", CURRENT_USER, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", CURRENT_USER, "name2")))
+ .isTrue();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnFalseWithDifferentNamespace() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", CURRENT_USER, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace2", CURRENT_USER, "name")))
+ .isFalse();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnFalseWithDifferentUser() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", CURRENT_USER, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", CURRENT_USER + "2", "name")))
+ .isFalse();
+ }
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnFalseWithOneOfTheUserNull() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", CURRENT_USER, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", null, "name")))
+ .isFalse();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnFalseWhenDifferentUser() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", CURRENT_USER, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", "other", "name")))
+ .isFalse();
+ }
+
+ @Test
+ public void belongsToNamespaceAndUserShouldReturnFalseIfNamespaceAreDifferentWithNullUser() {
+ MailboxQuery mailboxQuery = MailboxQuery.builder()
+ .base(new MailboxPath("namespace", null, "name"))
+ .mailboxSession(mailboxSession)
+ .build();
+
+ assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace2", null, "name")))
+ .isFalse();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org