JAMES-2400 Disable nested And clauses at the DSL level

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

Branch: refs/heads/master
Commit: 62682f688252963040ee7c6b276f67fe94ce00c0
Parents: c58a673
Author: benwa <btell...@linagora.com>
Authored: Tue May 22 16:09:19 2018 +0700
Committer: benwa <btell...@linagora.com>
Committed: Wed May 23 09:09:41 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/quota/search/QuotaClause.java     | 6 ++++++
 .../java/org/apache/james/quota/search/QuotaClauseTest.java | 9 +++++++++
 2 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/62682f68/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java
----------------------------------------------------------------------
diff --git 
a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java
 
b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java
index 359b231..078d15c 100644
--- 
a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java
+++ 
b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java
@@ -143,9 +143,15 @@ public interface QuotaClause {
 
         private And(List<QuotaClause> clauses) {
             Preconditions.checkNotNull(clauses, "'clauses' is mandatory");
+            Preconditions.checkArgument(doesNotContainAnd(clauses), "Nested 
And clauses are not supported");
             this.clauses = ImmutableList.copyOf(clauses);
         }
 
+        private boolean doesNotContainAnd(List<QuotaClause> clauses) {
+            return clauses.stream()
+                .noneMatch(clause -> clause instanceof And);
+        }
+
         public List<QuotaClause> getClauses() {
             return clauses;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/62682f68/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
 
b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
index 8f98475..09e6f4e 100644
--- 
a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
+++ 
b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
@@ -118,4 +118,13 @@ public class QuotaClauseTest implements QuotaClause {
         assertThat(andQuery.getClauses())
             .containsExactly(first, second);
     }
+
+    @Test
+    public void nestedAndClausesAreNotSupported() {
+        QuotaClause.MoreThan first = QuotaClause.moreThan(_50);
+        QuotaClause.MoreThan second = QuotaClause.moreThan(_75);
+
+        assertThatThrownBy(() -> QuotaClause.and(first, 
QuotaClause.and(second)))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
 }


---------------------------------------------------------------------
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