This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 14bba3e472d575d1d503c67c943d9711712f357b
Author: Rene Cordier <rcord...@linagora.com>
AuthorDate: Tue Apr 21 17:34:13 2020 +0700

    JAMES-3138 Change CurrentQuotaManagerTest into CurrentQuotaManagerContract
---
 .../quota/CassandraCurrentQuotaManagerTest.java    |   6 +-
 .../jpa/quota/JPACurrentQuotaManagerTest.java      |   6 +-
 .../store/quota/CurrentQuotaManagerContract.java   | 135 +++++++++++++++++++
 .../store/quota/CurrentQuotaManagerTest.java       | 143 ---------------------
 4 files changed, 141 insertions(+), 149 deletions(-)

diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/CassandraCurrentQuotaManagerTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/CassandraCurrentQuotaManagerTest.java
index 60e3db3..f8f3fe8 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/CassandraCurrentQuotaManagerTest.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/CassandraCurrentQuotaManagerTest.java
@@ -22,16 +22,16 @@ package org.apache.james.mailbox.cassandra.quota;
 import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule;
 import org.apache.james.mailbox.quota.CurrentQuotaManager;
-import org.apache.james.mailbox.store.quota.CurrentQuotaManagerTest;
+import org.apache.james.mailbox.store.quota.CurrentQuotaManagerContract;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
-class CassandraCurrentQuotaManagerTest extends CurrentQuotaManagerTest {
+class CassandraCurrentQuotaManagerTest implements CurrentQuotaManagerContract {
 
     @RegisterExtension
     static CassandraClusterExtension cassandraCluster = new 
CassandraClusterExtension(CassandraQuotaModule.MODULE);
 
     @Override
-    protected CurrentQuotaManager provideTestee() {
+    public CurrentQuotaManager testee() {
         return new 
CassandraCurrentQuotaManager(cassandraCluster.getCassandraCluster().getConf());
     }
 }
diff --git 
a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/quota/JPACurrentQuotaManagerTest.java
 
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/quota/JPACurrentQuotaManagerTest.java
index c347113..1897513 100644
--- 
a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/quota/JPACurrentQuotaManagerTest.java
+++ 
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/quota/JPACurrentQuotaManagerTest.java
@@ -22,15 +22,15 @@ package org.apache.james.mailbox.jpa.quota;
 import org.apache.james.backends.jpa.JpaTestCluster;
 import org.apache.james.mailbox.jpa.JPAMailboxFixture;
 import org.apache.james.mailbox.quota.CurrentQuotaManager;
-import org.apache.james.mailbox.store.quota.CurrentQuotaManagerTest;
+import org.apache.james.mailbox.store.quota.CurrentQuotaManagerContract;
 import org.junit.jupiter.api.AfterEach;
 
-class JPACurrentQuotaManagerTest extends CurrentQuotaManagerTest {
+class JPACurrentQuotaManagerTest implements CurrentQuotaManagerContract {
 
     static final JpaTestCluster JPA_TEST_CLUSTER = 
JpaTestCluster.create(JPAMailboxFixture.QUOTA_PERSISTANCE_CLASSES);
 
     @Override
-    protected CurrentQuotaManager provideTestee() {
+    public CurrentQuotaManager testee() {
         return new 
JpaCurrentQuotaManager(JPA_TEST_CLUSTER.getEntityManagerFactory());
     }
 
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/CurrentQuotaManagerContract.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/CurrentQuotaManagerContract.java
new file mode 100644
index 0000000..e79173c
--- /dev/null
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/CurrentQuotaManagerContract.java
@@ -0,0 +1,135 @@
+/****************************************************************
+ * 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.store.quota;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.james.core.quota.QuotaCountUsage;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Mono;
+
+public interface CurrentQuotaManagerContract {
+    QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa", Optional.empty());
+    CurrentQuotas CURRENT_QUOTAS = new 
CurrentQuotas(QuotaCountUsage.count(10), QuotaSizeUsage.size(100));
+    QuotaOperation RESET_QUOTA_OPERATION = new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100));
+    
+    CurrentQuotaManager testee();
+
+    @Test
+    default void getCurrentStorageShouldReturnZeroByDefault() {
+        
assertThat(Mono.from(testee().getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(0));
+    }
+
+    @Test
+    default void getCurrentMessageCountShouldReturnZeroByDefault() {
+        
assertThat(Mono.from(testee().getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(0));
+    }
+
+    @Test
+    default void getCurrentQuotasShouldReturnZeroByDefault() {
+        
assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block()).isEqualTo(CurrentQuotas.emptyQuotas());
+    }
+
+    @Test
+    default void increaseShouldWork() {
+        Mono.from(testee().increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100)))).block();
+
+        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            
softly.assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block()).isEqualTo(CURRENT_QUOTAS);
+            
softly.assertThat(Mono.from(testee().getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(10));
+            
softly.assertThat(Mono.from(testee().getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(100));
+        }));
+    }
+
+    @Test
+    default void decreaseShouldWork() {
+        Mono.from(testee().increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(20), QuotaSizeUsage.size(200)))).block();
+
+        Mono.from(testee().decrease(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100)))).block();
+
+        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            
softly.assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block()).isEqualTo(CURRENT_QUOTAS);
+            
softly.assertThat(Mono.from(testee().getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(10));
+            
softly.assertThat(Mono.from(testee().getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(100));
+        }));
+    }
+
+    @Test
+    default void decreaseShouldNotFailWhenItLeadsToNegativeValues() {
+        Mono.from(testee().decrease(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100)))).block();
+
+        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            
softly.assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block())
+                .isEqualTo(new CurrentQuotas(QuotaCountUsage.count(-10), 
QuotaSizeUsage.size(-100)));
+            
softly.assertThat(Mono.from(testee().getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(-10));
+            
softly.assertThat(Mono.from(testee().getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(-100));
+        }));
+    }
+
+    @Test
+    default void setCurrentQuotasShouldNoopWhenZeroAndNoData() {
+        QuotaOperation quotaOperation = new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(0), QuotaSizeUsage.size(0));
+
+        Mono.from(testee().setCurrentQuotas(quotaOperation)).block();
+
+        assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block())
+            .isEqualTo(CurrentQuotas.emptyQuotas());
+    }
+
+    @Test
+    default void setCurrentQuotasShouldReInitQuotasWhenNothing() {
+        Mono.from(testee().setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
+
+        assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block())
+            .isEqualTo(CURRENT_QUOTAS);
+    }
+
+    @Test
+    default void setCurrentQuotasShouldReInitQuotasWhenData() {
+        Mono.from(testee().increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(20), QuotaSizeUsage.size(200)))).block();
+
+        Mono.from(testee().setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
+
+        assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block())
+            .isEqualTo(CURRENT_QUOTAS);
+    }
+
+    @Test
+    default void setCurrentQuotasShouldBeIdempotent() {
+        Mono.from(testee().increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(20), QuotaSizeUsage.size(200)))).block();
+
+        Mono.from(testee().setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
+        Mono.from(testee().setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
+
+        assertThat(Mono.from(testee().getCurrentQuotas(QUOTA_ROOT)).block())
+            .isEqualTo(CURRENT_QUOTAS);
+    }
+}
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/CurrentQuotaManagerTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/CurrentQuotaManagerTest.java
deleted file mode 100644
index e331c95..0000000
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/CurrentQuotaManagerTest.java
+++ /dev/null
@@ -1,143 +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.store.quota;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Optional;
-
-import org.apache.james.core.quota.QuotaCountUsage;
-import org.apache.james.core.quota.QuotaSizeUsage;
-import org.apache.james.mailbox.model.CurrentQuotas;
-import org.apache.james.mailbox.model.QuotaOperation;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.quota.CurrentQuotaManager;
-import org.assertj.core.api.SoftAssertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import com.github.fge.lambdas.Throwing;
-
-import reactor.core.publisher.Mono;
-
-public abstract class CurrentQuotaManagerTest {
-    private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa", 
Optional.empty());
-    private static final CurrentQuotas CURRENT_QUOTAS = new 
CurrentQuotas(QuotaCountUsage.count(10), QuotaSizeUsage.size(100));
-    private static final QuotaOperation RESET_QUOTA_OPERATION = new 
QuotaOperation(QUOTA_ROOT, QuotaCountUsage.count(10), QuotaSizeUsage.size(100));
-    
-    protected abstract CurrentQuotaManager provideTestee();
-    
-    private CurrentQuotaManager testee;
-
-    @BeforeEach
-    void setUp() {
-        testee = provideTestee();
-    }
-
-    @Test
-    void getCurrentStorageShouldReturnZeroByDefault() {
-        
assertThat(Mono.from(testee.getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(0));
-    }
-
-    @Test
-    void getCurrentMessageCountShouldReturnZeroByDefault() {
-        
assertThat(Mono.from(testee.getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(0));
-    }
-
-    @Test
-    void getCurrentQuotasShouldReturnZeroByDefault() {
-        
assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block()).isEqualTo(CurrentQuotas.emptyQuotas());
-    }
-
-    @Test
-    void increaseShouldWork() {
-        Mono.from(testee.increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100)))).block();
-
-        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-            
softly.assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block()).isEqualTo(CURRENT_QUOTAS);
-            
softly.assertThat(Mono.from(testee.getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(10));
-            
softly.assertThat(Mono.from(testee.getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(100));
-        }));
-    }
-
-    @Test
-    void decreaseShouldWork() {
-        Mono.from(testee.increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(20), QuotaSizeUsage.size(200)))).block();
-
-        Mono.from(testee.decrease(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100)))).block();
-
-        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-            
softly.assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block()).isEqualTo(CURRENT_QUOTAS);
-            
softly.assertThat(Mono.from(testee.getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(10));
-            
softly.assertThat(Mono.from(testee.getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(100));
-        }));
-    }
-
-    @Test
-    void decreaseShouldNotFailWhenItLeadsToNegativeValues() {
-        Mono.from(testee.decrease(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(10), QuotaSizeUsage.size(100)))).block();
-
-        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-            
softly.assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block())
-                .isEqualTo(new CurrentQuotas(QuotaCountUsage.count(-10), 
QuotaSizeUsage.size(-100)));
-            
softly.assertThat(Mono.from(testee.getCurrentMessageCount(QUOTA_ROOT)).block()).isEqualTo(QuotaCountUsage.count(-10));
-            
softly.assertThat(Mono.from(testee.getCurrentStorage(QUOTA_ROOT)).block()).isEqualTo(QuotaSizeUsage.size(-100));
-        }));
-    }
-
-    @Test
-    void setCurrentQuotasShouldNoopWhenZeroAndNoData() {
-        QuotaOperation quotaOperation = new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(0), QuotaSizeUsage.size(0));
-
-        Mono.from(testee.setCurrentQuotas(quotaOperation)).block();
-
-        assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block())
-            .isEqualTo(CurrentQuotas.emptyQuotas());
-    }
-
-    @Test
-    void setCurrentQuotasShouldReInitQuotasWhenNothing() {
-        Mono.from(testee.setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
-
-        assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block())
-            .isEqualTo(CURRENT_QUOTAS);
-    }
-
-    @Test
-    void setCurrentQuotasShouldReInitQuotasWhenData() {
-        Mono.from(testee.increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(20), QuotaSizeUsage.size(200)))).block();
-
-        Mono.from(testee.setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
-
-        assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block())
-            .isEqualTo(CURRENT_QUOTAS);
-    }
-
-    @Test
-    void setCurrentQuotasShouldBeIdempotent() {
-        Mono.from(testee.increase(new QuotaOperation(QUOTA_ROOT, 
QuotaCountUsage.count(20), QuotaSizeUsage.size(200)))).block();
-
-        Mono.from(testee.setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
-        Mono.from(testee.setCurrentQuotas(RESET_QUOTA_OPERATION)).block();
-
-        assertThat(Mono.from(testee.getCurrentQuotas(QUOTA_ROOT)).block())
-            .isEqualTo(CURRENT_QUOTAS);
-    }
-}


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