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 rc...@apache.org on 2020/08/17 09:11:11 UTC

[james-project] branch master updated (71a6e3b -> 9e4f708)

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

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


    from 71a6e3b  JAMES-3349: add handle methodError
     new 670fad2  [Refactoring] Migrate TestExternalHostSystem to JUnit5
     new 57c11aa  [Refactoring] Migrate TestFileProtocolSessionBuilder to JUnit5
     new 0013920  [Refactoring] Migrate TestScriptedUserAdder to JUnit5
     new 69a3375  JAMES-3308 RabbitMQTerminationSubscriberTest should be thread safe
     new f52940d  [Refactoring] Migrate ScriptTest to JUnit5
     new f76deb6  [Refactoring] Migrate SieveQuotaTest to JUnit5
     new 4d50f06  [Refactoring] Migrate XMLDomainListTest to JUnit5
     new 8b3a128  [Refactoring] Migrate AbstractRecipientRewriteTableTest to RecipientRewriteTableContract in JUnit5
     new 0306f81  [Refactoring] Migrate AccessTokenRepositoryTest to AccessTokenRepositoryContract in JUnit5
     new a63ae40  [Refactoring] Migrate AccessTokenTest to JUnit5
     new 5c9da37  [Refactoring] Migrate AccountIdTest to JUnit5
     new 5f6e21f  [Refactoring] Migrate VacationPatchTest to JUnit5
     new 33df080  [Refactoring] Migrate VacationTest to JUnit5
     new 2026d32  [Refactoring] Migrate UsersRepositoryManagementTest to JUnit5
     new 8fadbc5  [Refactoring] Migrate DLPAggregateIdTest to JUnit5
     new 04f1ad7  [Refactoring] Migrate ClearCommandTest to JUnit5
     new 43cbb29  [Refactoring] Migrate StoreCommandTest to JUnit5
     new 0572e22  [Refactoring] Migrate ConfigurationItemsAddedTest to JUnit5
     new 03aa79d  [Refactoring] Migrate ConfigurationItemsRemovedTest to JUnit5
     new deb7996  [Refactoring] Migrate SieveRepositoryManagementTest to JUnit5
     new 7ff2ac7  [Refactoring] Migrate AbstractNotificationRegistryTest to NotificationRegistryContract JUnit5
     new 0b85634  [Refactoring] Migrate AbstractVacationRepositoryTest to VacationRepositoryContract JUnit5
     new 666c3af  [Refactoring] Migrate AbstractDomainListPrivateMethodsTest to JUnit5
     new e8d9cff  [Refactoring] Migrate AbstractDomainListTest to DomainListContract JUnit5
     new a5f5e57  [Refactoring] Migrate AbstractSieveRepositoryTest to SieveRepositoryContract JUnit5
     new 9e4f708  [Refactoring] Remove useless @Rule in JPAHealthCheckTest

The 26 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/james/mpt/TestExternalHostSystem.java   |  36 +-
 .../james/mpt/TestFileProtocolSessionBuilder.java  |  26 +-
 .../apache/james/mpt/TestScriptedUserAdder.java    |  23 +-
 .../cassandra/CassandraDomainListTest.java         |  41 +-
 .../CassandraRecipientRewriteTableV6Test.java      |  62 +-
 ...ndraRecipientRewriteTableV7BeforeStartTest.java |  63 +-
 .../CassandraRecipientRewriteTableV7Test.java      |  64 +-
 .../cassandra/CassandraSieveRepositoryTest.java    |  41 +-
 .../james/sieve/cassandra/model/ScriptTest.java    |  71 +--
 .../sieve/cassandra/model/SieveQuotaTest.java      |  42 +-
 .../james/domainlist/xml/XMLDomainListTest.java    |  39 +-
 .../rrt/file/XMLRecipientRewriteTableTest.java     | 109 ++--
 .../file/SieveFileRepositoryTest.java              |  39 +-
 .../access/CassandraAccessTokenRepositoryTest.java |  37 +-
 .../CassandraNotificationRegistryTest.java         |  49 +-
 .../vacation/CassandraVacationRepositoryTest.java  |  44 +-
 .../api/access/AccessTokenRepositoryContract.java  |  85 +++
 .../jmap/api/access/AccessTokenRepositoryTest.java |  91 ---
 .../james/jmap/api/access/AccessTokenTest.java     |  14 +-
 .../vacation/AbstractNotificationRegistryTest.java | 114 ----
 .../james/jmap/api/vacation/AccountIdTest.java     |  24 +-
 .../api/vacation/NotificationRegistryContract.java | 103 ++++
 .../james/jmap/api/vacation/VacationPatchTest.java |  56 +-
 ...ryTest.java => VacationRepositoryContract.java} | 148 +++--
 .../james/jmap/api/vacation/VacationTest.java      |  67 +--
 .../access/MemoryAccessTokenRepositoryTest.java    |  20 +-
 .../vacation/MemoryNotificationRegistryTest.java   |  25 +-
 .../vacation/MemoryVacationRepositoryTest.java     |  15 +-
 .../james/domainlist/jpa/JPADomainListTest.java    |  28 +-
 .../james/jpa/healthcheck/JPAHealthCheckTest.java  |  10 +-
 .../rrt/jpa/JPARecipientRewriteTableTest.java      |  35 +-
 .../james/sieve/jpa/JpaSieveRepositoryTest.java    |  27 +-
 .../aggregates/DLPAggregateIdTest.java             |  11 +-
 .../eventsourcing/commands/ClearCommandTest.java   |  10 +-
 .../eventsourcing/commands/StoreCommandTest.java   |  10 +-
 .../events/ConfigurationItemsAddedTest.java        |  14 +-
 .../events/ConfigurationItemsRemovedTest.java      |  14 +-
 .../lib/AbstractDomainListPrivateMethodsTest.java  |  64 +-
 .../domainlist/lib/AbstractDomainListTest.java     | 168 ------
 .../james/domainlist/lib/DomainListContract.java   | 159 +++++
 .../rrt/lib/AbstractRecipientRewriteTableTest.java | 643 ---------------------
 .../rrt/lib/RecipientRewriteTableContract.java     | 636 ++++++++++++++++++++
 .../lib/AbstractSieveRepositoryTest.java           | 361 ------------
 .../lib/SieveRepositoryContract.java               | 371 ++++++++++++
 .../lib/SieveRepositoryManagementTest.java         |  20 +-
 .../domainlist/memory/MemoryDomainListTest.java    |  24 +-
 .../memory/MemoryRecipientRewriteTableTest.java    |  31 +-
 .../user/memory/UsersRepositoryManagementTest.java |  26 +-
 .../RabbitMQTerminationSubscriberTest.java         |   9 +-
 49 files changed, 2093 insertions(+), 2126 deletions(-)
 create mode 100644 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryContract.java
 delete mode 100644 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryTest.java
 delete mode 100644 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractNotificationRegistryTest.java
 create mode 100644 server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/NotificationRegistryContract.java
 rename server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/{AbstractVacationRepositoryTest.java => VacationRepositoryContract.java} (59%)
 delete mode 100644 server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
 create mode 100644 server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListContract.java
 delete mode 100644 server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
 create mode 100644 server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableContract.java
 delete mode 100644 server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
 create mode 100644 server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryContract.java


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


[james-project] 10/26: [Refactoring] Migrate AccessTokenTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a63ae40f13488b33df3aa57cd36475fcabbb9a5e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:05:37 2020 +0700

    [Refactoring] Migrate AccessTokenTest to JUnit5
---
 .../org/apache/james/jmap/api/access/AccessTokenTest.java  | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenTest.java
index 118144d..9693af9 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenTest.java
@@ -20,19 +20,21 @@
 package org.apache.james.jmap.api.access;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.jmap.api.access.exceptions.NotAnAccessTokenException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class AccessTokenTest {
+class AccessTokenTest {
 
-    @Test(expected = NotAnAccessTokenException.class)
-    public void fromStringShouldThrowWhenNotAnUUID() throws NotAnAccessTokenException {
-        AccessToken.fromString("bad");
+    @Test
+    void fromStringShouldThrowWhenNotAnUUID() {
+        assertThatThrownBy(() -> AccessToken.fromString("bad"))
+            .isInstanceOf(NotAnAccessTokenException.class);
     }
 
     @Test
-    public void fromStringShouldWork() throws NotAnAccessTokenException {
+    void fromStringShouldWork() throws NotAnAccessTokenException {
         String expectedToken = "dab315ad-a59a-4107-8d00-0fef9a0745b8";
 
         AccessToken accessToken = AccessToken.fromString(expectedToken);


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


[james-project] 04/26: JAMES-3308 RabbitMQTerminationSubscriberTest should be thread safe

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 69a3375cdec191f2216557e7ae91fa1664ce853b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Aug 11 16:04:00 2020 +0700

    JAMES-3308 RabbitMQTerminationSubscriberTest should be thread safe
    
    We should enforce the use of thread safe collections to prevent unlikely runtime failures
    (ConcurrentModificationException)
---
 .../distributed/RabbitMQTerminationSubscriberTest.java           | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java b/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java
index 87bee6e..482035f 100644
--- a/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java
+++ b/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java
@@ -31,8 +31,10 @@ import static org.awaitility.Duration.TEN_SECONDS;
 
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.stream.IntStream;
 
 import org.apache.james.backends.rabbitmq.RabbitMQExtension;
@@ -123,12 +125,11 @@ class RabbitMQTerminationSubscriberTest implements TerminationSubscriberContract
 
         sendEvents(subscriber1, COMPLETED_EVENT);
 
-        List<Event> receivedEventsFirst = new ArrayList<>();
+        Collection<Event> receivedEventsFirst = new ConcurrentLinkedQueue<>();
         firstListener.subscribe(receivedEventsFirst::add);
 
         await().atMost(ONE_MINUTE).untilAsserted(() ->
-            SoftAssertions.assertSoftly(soft -> {
-                assertThat(receivedEventsFirst).containsExactly(COMPLETED_EVENT);
-            }));
+            SoftAssertions.assertSoftly(soft ->
+                assertThat(receivedEventsFirst).containsExactly(COMPLETED_EVENT)));
     }
 }
\ No newline at end of file


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


[james-project] 25/26: [Refactoring] Migrate AbstractSieveRepositoryTest to SieveRepositoryContract JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a5f5e57526afe4d8017d00a34a40b9170001c61e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 17:13:02 2020 +0700

    [Refactoring] Migrate AbstractSieveRepositoryTest to SieveRepositoryContract JUnit5
---
 .../cassandra/CassandraSieveRepositoryTest.java    |  41 +--
 .../file/SieveFileRepositoryTest.java              |  39 ++-
 .../james/sieve/jpa/JpaSieveRepositoryTest.java    |  27 +-
 .../lib/AbstractSieveRepositoryTest.java           | 361 --------------------
 .../lib/SieveRepositoryContract.java               | 371 +++++++++++++++++++++
 5 files changed, 420 insertions(+), 419 deletions(-)

diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraSieveRepositoryTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraSieveRepositoryTest.java
index c28d7ba..d0954d7 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraSieveRepositoryTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraSieveRepositoryTest.java
@@ -20,37 +20,28 @@
 package org.apache.james.sieve.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.sieverepository.api.SieveRepository;
-import org.apache.james.sieverepository.lib.AbstractSieveRepositoryTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.sieverepository.lib.SieveRepositoryContract;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraSieveRepositoryTest extends AbstractSieveRepositoryTest {
+class CassandraSieveRepositoryTest implements SieveRepositoryContract {
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraSieveRepositoryModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule();
-    
-    private CassandraCluster cassandra;
+    SieveRepository sieveRepository;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(CassandraSieveRepositoryModule.MODULE, cassandraServer.getHost());
-        super.setUp();
-    }
-    
-    @After
-    public void tearDown() {
-        cassandra.close();
-    }
-
-    @Override
-    protected SieveRepository createSieveRepository() {
-        return new CassandraSieveRepository(
+    @BeforeEach
+    void setUp(CassandraCluster cassandra) {
+        sieveRepository = new CassandraSieveRepository(
             new CassandraSieveDAO(cassandra.getConf()),
             new CassandraSieveQuotaDAO(cassandra.getConf()),
             new CassandraActiveScriptDAO(cassandra.getConf()));
     }
+
+    @Override
+    public SieveRepository sieveRepository() {
+        return sieveRepository;
+    }
 }
\ No newline at end of file
diff --git a/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java b/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
index dd194f5..42b9b70 100644
--- a/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
@@ -4,29 +4,28 @@ package org.apache.james.sieverepository.file;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.sieverepository.api.SieveRepository;
-import org.apache.james.sieverepository.lib.AbstractSieveRepositoryTest;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.james.sieverepository.lib.SieveRepositoryContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class SieveFileRepositoryTest extends AbstractSieveRepositoryTest {
+class SieveFileRepositoryTest implements SieveRepositoryContract {
 
-    private static final String SIEVE_ROOT = FileSystem.FILE_PROTOCOL + "sieve";
+    static final String SIEVE_ROOT = FileSystem.FILE_PROTOCOL + "sieve";
 
-    private FileSystem fileSystem;
+    FileSystem fileSystem;
+    SieveRepository sieveRepository;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         this.fileSystem = new FileSystem() {
             @Override
-            public File getBasedir() throws FileNotFoundException {
+            public File getBasedir() {
                 return new File(System.getProperty("java.io.tmpdir"));
             }
             
@@ -36,24 +35,24 @@ public class SieveFileRepositoryTest extends AbstractSieveRepositoryTest {
             }
             
             @Override
-            public File getFile(String fileURL) throws FileNotFoundException {
+            public File getFile(String fileURL) {
                 return new File(getBasedir(), fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
             }
         };
-        super.setUp();
-    }
-
-    @Override
-    protected SieveRepository createSieveRepository() throws Exception {
-        return new SieveFileRepository(fileSystem);
+        sieveRepository = new SieveFileRepository(fileSystem);
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterEach
+    void tearDown() throws Exception {
         File root = fileSystem.getFile(SIEVE_ROOT);
         // Remove files from the previous test, if any
         if (root.exists()) {
             FileUtils.forceDelete(root);
         }
     }
+
+    @Override
+    public SieveRepository sieveRepository() {
+        return sieveRepository;
+    }
 }
diff --git a/server/data/data-jpa/src/test/java/org/apache/james/sieve/jpa/JpaSieveRepositoryTest.java b/server/data/data-jpa/src/test/java/org/apache/james/sieve/jpa/JpaSieveRepositoryTest.java
index e79de07..ab59dc6 100644
--- a/server/data/data-jpa/src/test/java/org/apache/james/sieve/jpa/JpaSieveRepositoryTest.java
+++ b/server/data/data-jpa/src/test/java/org/apache/james/sieve/jpa/JpaSieveRepositoryTest.java
@@ -23,27 +23,28 @@ import org.apache.james.backends.jpa.JpaTestCluster;
 import org.apache.james.sieve.jpa.model.JPASieveQuota;
 import org.apache.james.sieve.jpa.model.JPASieveScript;
 import org.apache.james.sieverepository.api.SieveRepository;
-import org.apache.james.sieverepository.lib.AbstractSieveRepositoryTest;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.james.sieverepository.lib.SieveRepositoryContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class JpaSieveRepositoryTest extends AbstractSieveRepositoryTest {
+class JpaSieveRepositoryTest implements SieveRepositoryContract {
 
-    private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPASieveScript.class, JPASieveQuota.class);
+    final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPASieveScript.class, JPASieveQuota.class);
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
+    SieveRepository sieveRepository;
+
+    @BeforeEach
+    void setUp() {
+        sieveRepository = new JPASieveRepository(JPA_TEST_CLUSTER.getEntityManagerFactory());
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterEach
+    void tearDown() {
         JPA_TEST_CLUSTER.clear("JAMES_SIEVE_SCRIPT", "JAMES_SIEVE_QUOTA");
     }
 
     @Override
-    protected SieveRepository createSieveRepository() throws Exception {
-        return new JPASieveRepository(JPA_TEST_CLUSTER.getEntityManagerFactory());
+    public SieveRepository sieveRepository() {
+        return sieveRepository;
     }
 }
diff --git a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
deleted file mode 100644
index 4482d97..0000000
--- a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
+++ /dev/null
@@ -1,361 +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.sieverepository.lib;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.time.Instant;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.core.Username;
-import org.apache.james.core.quota.QuotaSizeLimit;
-import org.apache.james.sieverepository.api.ScriptContent;
-import org.apache.james.sieverepository.api.ScriptName;
-import org.apache.james.sieverepository.api.ScriptSummary;
-import org.apache.james.sieverepository.api.SieveRepository;
-import org.apache.james.sieverepository.api.exception.DuplicateException;
-import org.apache.james.sieverepository.api.exception.IsActiveException;
-import org.apache.james.sieverepository.api.exception.QuotaExceededException;
-import org.apache.james.sieverepository.api.exception.QuotaNotFoundException;
-import org.apache.james.sieverepository.api.exception.ScriptNotFoundException;
-import org.junit.Test;
-
-public abstract class AbstractSieveRepositoryTest {
-
-    protected static final Username USERNAME = Username.of("test");
-    protected static final ScriptName SCRIPT_NAME = new ScriptName("script");
-    protected static final ScriptContent SCRIPT_CONTENT = new ScriptContent("Hello World");
-
-    private static final ScriptName OTHER_SCRIPT_NAME = new ScriptName("other_script");
-    private static final ScriptContent OTHER_SCRIPT_CONTENT = new ScriptContent("Other script content");
-    private static final QuotaSizeLimit DEFAULT_QUOTA = QuotaSizeLimit.size(Long.MAX_VALUE - 1L);
-    private static final QuotaSizeLimit USER_QUOTA = QuotaSizeLimit.size(Long.MAX_VALUE / 2);
-
-    protected SieveRepository sieveRepository;
-
-    public void setUp() throws Exception {
-        sieveRepository = createSieveRepository();
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void getScriptShouldThrowIfUnableToFindScript() throws Exception {
-        sieveRepository.getScript(USERNAME, SCRIPT_NAME);
-    }
-
-    @Test
-    public void getScriptShouldReturnCorrectContent() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        assertThat(getScriptContent(sieveRepository.getScript(USERNAME, SCRIPT_NAME))).isEqualTo(SCRIPT_CONTENT);
-    }
-
-    @Test
-    public void getActivationDateForActiveScriptShouldReturnNonNullAndNonZeroResult() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        assertThat(sieveRepository.getActivationDateForActiveScript(USERNAME)).isNotNull();
-        assertThat(sieveRepository.getActivationDateForActiveScript(USERNAME)).isNotEqualTo(ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneOffset.UTC));
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void getActivationDateForActiveScriptShouldThrowOnMissingActiveScript() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.getActivationDateForActiveScript(USERNAME);
-    }
-
-    @Test
-    public void haveSpaceShouldNotThrowWhenUserDoesNotHaveQuota() throws Exception {
-        sieveRepository.haveSpace(USERNAME, SCRIPT_NAME, DEFAULT_QUOTA.asLong() + 1L);
-    }
-
-    @Test
-    public void haveSpaceShouldNotThrowWhenQuotaIsNotReached() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        sieveRepository.haveSpace(USERNAME, SCRIPT_NAME, DEFAULT_QUOTA.asLong());
-    }
-
-    @Test(expected = QuotaExceededException.class)
-    public void haveSpaceShouldThrowWhenQuotaIsExceed() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        sieveRepository.haveSpace(USERNAME, SCRIPT_NAME, DEFAULT_QUOTA.asLong() + 1);
-    }
-
-    @Test
-    public void haveSpaceShouldNotThrowWhenAttemptToReplaceOtherScript() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.haveSpace(USERNAME, SCRIPT_NAME, USER_QUOTA.asLong());
-    }
-
-    @Test(expected = QuotaExceededException.class)
-    public void haveSpaceShouldThrowWhenAttemptToReplaceOtherScriptWithTooLargeScript() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.haveSpace(USERNAME, SCRIPT_NAME, USER_QUOTA.asLong() + 1);
-    }
-
-    @Test(expected = QuotaExceededException.class)
-    public void haveSpaceShouldTakeAlreadyExistingScriptsIntoAccount() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.haveSpace(USERNAME, OTHER_SCRIPT_NAME, USER_QUOTA.asLong() - 1);
-    }
-
-    @Test
-    public void haveSpaceShouldNotThrowAfterActivatingAScript() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.haveSpace(USERNAME, SCRIPT_NAME, USER_QUOTA.asLong());
-    }
-
-    @Test
-    public void listScriptsShouldReturnAnEmptyListIfUserNotFound() throws Exception {
-        assertThat(sieveRepository.listScripts(USERNAME)).isEmpty();
-    }
-
-    @Test
-    public void listScriptsShouldReturnEmptyListWhenThereIsNoScript() throws Exception {
-        assertThat(sieveRepository.listScripts(USERNAME)).isEmpty();
-    }
-
-    @Test
-    public void putScriptShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        assertThat(sieveRepository.listScripts(USERNAME)).containsOnly(new ScriptSummary(SCRIPT_NAME, false));
-    }
-
-    @Test
-    public void setActiveShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        assertThat(sieveRepository.listScripts(USERNAME)).containsOnly(new ScriptSummary(SCRIPT_NAME, true));
-    }
-
-    @Test
-    public void listScriptShouldCombineActiveAndPassiveScripts() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.putScript(USERNAME, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
-        assertThat(sieveRepository.listScripts(USERNAME)).containsOnly(new ScriptSummary(SCRIPT_NAME, true), new ScriptSummary(OTHER_SCRIPT_NAME, false));
-    }
-
-    @Test(expected = QuotaExceededException.class)
-    public void putScriptShouldThrowWhenScriptTooBig() throws Exception {
-        sieveRepository.setDefaultQuota(QuotaSizeLimit.size(SCRIPT_CONTENT.length() - 1));
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-    }
-
-    @Test(expected = QuotaExceededException.class)
-    public void putScriptShouldThrowWhenQuotaChangedInBetween() throws Exception {
-        sieveRepository.setDefaultQuota(QuotaSizeLimit.size(SCRIPT_CONTENT.length()));
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setDefaultQuota(QuotaSizeLimit.size(SCRIPT_CONTENT.length() - 1));
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void setActiveScriptShouldThrowOnNonExistentScript() throws Exception {
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-    }
-
-    @Test
-    public void setActiveScriptShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        assertThat(getScriptContent(sieveRepository.getActive(USERNAME))).isEqualTo(SCRIPT_CONTENT);
-    }
-
-    @Test
-    public void setActiveSwitchScriptShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.putScript(USERNAME, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, OTHER_SCRIPT_NAME);
-        assertThat(getScriptContent(sieveRepository.getActive(USERNAME))).isEqualTo(OTHER_SCRIPT_CONTENT);
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void switchOffActiveScriptShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.setActive(USERNAME, SieveRepository.NO_SCRIPT_NAME);
-        sieveRepository.getActive(USERNAME);
-    }
-
-    @Test
-    public void switchOffActiveScriptShouldNotThrow() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.setActive(USERNAME, SieveRepository.NO_SCRIPT_NAME);
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void getActiveShouldThrowWhenNoActiveScript() throws Exception {
-        sieveRepository.getActive(USERNAME);
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void deleteActiveScriptShouldThrowIfScriptDoNotExist() throws Exception {
-        sieveRepository.deleteScript(USERNAME, SCRIPT_NAME);
-    }
-
-    @Test(expected = IsActiveException.class)
-    public void deleteActiveScriptShouldThrow() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.deleteScript(USERNAME, SCRIPT_NAME);
-    }
-
-    @Test(expected = IsActiveException.class)
-    public void deleteScriptShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.deleteScript(USERNAME, SCRIPT_NAME);
-        sieveRepository.getScript(USERNAME, SCRIPT_NAME);
-    }
-
-    @Test(expected = ScriptNotFoundException.class)
-    public void renameScriptShouldThrowIfScriptNotFound() throws Exception {
-        sieveRepository.renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME);
-    }
-
-    @Test
-    public void renameScriptShouldWork() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME);
-        assertThat(getScriptContent(sieveRepository.getScript(USERNAME, OTHER_SCRIPT_NAME))).isEqualTo(SCRIPT_CONTENT);
-    }
-
-    @Test
-    public void renameScriptShouldPropagateActiveScript() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.setActive(USERNAME, SCRIPT_NAME);
-        sieveRepository.renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME);
-        assertThat(getScriptContent(sieveRepository.getActive(USERNAME))).isEqualTo(SCRIPT_CONTENT);
-    }
-
-    @Test(expected = DuplicateException.class)
-    public void renameScriptShouldNotOverwriteExistingScript() throws Exception {
-        sieveRepository.putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
-        sieveRepository.putScript(USERNAME, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
-        sieveRepository.renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME);
-    }
-
-    @Test(expected = QuotaNotFoundException.class)
-    public void getQuotaShouldThrowIfQuotaNotFound() throws Exception {
-        sieveRepository.getDefaultQuota();
-    }
-
-    @Test
-    public void getQuotaShouldWork() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        assertThat(sieveRepository.getDefaultQuota()).isEqualTo(DEFAULT_QUOTA);
-    }
-
-    @Test
-    public void getQuotaShouldWorkOnUsers() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        assertThat(sieveRepository.getQuota(USERNAME)).isEqualTo(USER_QUOTA);
-    }
-
-    @Test
-    public void hasQuotaShouldReturnFalseWhenRepositoryDoesNotHaveQuota() throws Exception {
-        assertThat(sieveRepository.hasDefaultQuota()).isFalse();
-    }
-
-    @Test
-    public void hasQuotaShouldReturnTrueWhenRepositoryHaveQuota() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        assertThat(sieveRepository.hasDefaultQuota()).isTrue();
-    }
-
-    @Test
-    public void hasQuotaShouldReturnFalseWhenUserDoesNotHaveQuota() throws Exception {
-        assertThat(sieveRepository.hasDefaultQuota()).isFalse();
-    }
-
-    @Test
-    public void hasQuotaShouldReturnTrueWhenUserHaveQuota() throws Exception {
-        sieveRepository.setQuota(USERNAME, DEFAULT_QUOTA);
-        assertThat(sieveRepository.hasQuota(USERNAME)).isTrue();
-    }
-
-    @Test
-    public void removeQuotaShouldNotThrowIfRepositoryDoesNotHaveQuota() throws Exception {
-        sieveRepository.removeQuota();
-    }
-
-    @Test
-    public void removeUserQuotaShouldNotThrowWhenAbsent() throws Exception {
-        sieveRepository.removeQuota(USERNAME);
-    }
-
-    @Test
-    public void removeQuotaShouldWorkOnRepositories() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        sieveRepository.removeQuota();
-        assertThat(sieveRepository.hasDefaultQuota()).isFalse();
-    }
-
-    @Test
-    public void removeQuotaShouldWorkOnUsers() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.removeQuota(USERNAME);
-        assertThat(sieveRepository.hasQuota(USERNAME)).isFalse();
-    }
-
-    @Test(expected = QuotaNotFoundException.class)
-    public void removeQuotaShouldWorkOnUsersWithGlobalQuota() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.removeQuota(USERNAME);
-        sieveRepository.getQuota(USERNAME);
-    }
-
-    @Test
-    public void setQuotaShouldWork() throws Exception {
-        sieveRepository.setDefaultQuota(DEFAULT_QUOTA);
-        assertThat(sieveRepository.getDefaultQuota()).isEqualTo(DEFAULT_QUOTA);
-    }
-
-    @Test
-    public void setQuotaShouldWorkOnUsers() throws Exception {
-        sieveRepository.setQuota(USERNAME, DEFAULT_QUOTA);
-        assertThat(sieveRepository.getQuota(USERNAME)).isEqualTo(DEFAULT_QUOTA);
-    }
-
-    @Test
-    public void setQuotaShouldOverrideExistingQuota() throws Exception {
-        sieveRepository.setQuota(USERNAME, USER_QUOTA);
-        sieveRepository.setQuota(USERNAME, QuotaSizeLimit.size(USER_QUOTA.asLong() - 1));
-        assertThat(sieveRepository.getQuota(USERNAME)).isEqualTo(QuotaSizeLimit.size(USER_QUOTA.asLong() - 1));
-    }
-
-    protected ScriptContent getScriptContent(InputStream inputStream) throws IOException {
-        return new ScriptContent(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
-    }
-
-    protected abstract SieveRepository createSieveRepository() throws Exception;
-
-}
diff --git a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryContract.java b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryContract.java
new file mode 100644
index 0000000..a3e55e7
--- /dev/null
+++ b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryContract.java
@@ -0,0 +1,371 @@
+/****************************************************************
+ * 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.sieverepository.lib;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaSizeLimit;
+import org.apache.james.sieverepository.api.ScriptContent;
+import org.apache.james.sieverepository.api.ScriptName;
+import org.apache.james.sieverepository.api.ScriptSummary;
+import org.apache.james.sieverepository.api.SieveRepository;
+import org.apache.james.sieverepository.api.exception.DuplicateException;
+import org.apache.james.sieverepository.api.exception.IsActiveException;
+import org.apache.james.sieverepository.api.exception.QuotaExceededException;
+import org.apache.james.sieverepository.api.exception.QuotaNotFoundException;
+import org.apache.james.sieverepository.api.exception.ScriptNotFoundException;
+import org.junit.jupiter.api.Test;
+
+public interface SieveRepositoryContract {
+
+    Username USERNAME = Username.of("test");
+    ScriptName SCRIPT_NAME = new ScriptName("script");
+    ScriptContent SCRIPT_CONTENT = new ScriptContent("Hello World");
+
+    ScriptName OTHER_SCRIPT_NAME = new ScriptName("other_script");
+    ScriptContent OTHER_SCRIPT_CONTENT = new ScriptContent("Other script content");
+    QuotaSizeLimit DEFAULT_QUOTA = QuotaSizeLimit.size(Long.MAX_VALUE - 1L);
+    QuotaSizeLimit USER_QUOTA = QuotaSizeLimit.size(Long.MAX_VALUE / 2);
+
+    SieveRepository sieveRepository();
+
+    @Test
+    default void getScriptShouldThrowIfUnableToFindScript() {
+        assertThatThrownBy(() -> sieveRepository().getScript(USERNAME, SCRIPT_NAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void getScriptShouldReturnCorrectContent() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        assertThat(getScriptContent(sieveRepository().getScript(USERNAME, SCRIPT_NAME))).isEqualTo(SCRIPT_CONTENT);
+    }
+
+    @Test
+    default void getActivationDateForActiveScriptShouldReturnNonNullAndNonZeroResult() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        assertThat(sieveRepository().getActivationDateForActiveScript(USERNAME)).isNotNull();
+        assertThat(sieveRepository().getActivationDateForActiveScript(USERNAME)).isNotEqualTo(ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneOffset.UTC));
+    }
+
+    @Test
+    default void getActivationDateForActiveScriptShouldThrowOnMissingActiveScript() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        assertThatThrownBy(() -> sieveRepository().getActivationDateForActiveScript(USERNAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void haveSpaceShouldNotThrowWhenUserDoesNotHaveQuota() throws Exception {
+        sieveRepository().haveSpace(USERNAME, SCRIPT_NAME, DEFAULT_QUOTA.asLong() + 1L);
+    }
+
+    @Test
+    default void haveSpaceShouldNotThrowWhenQuotaIsNotReached() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        sieveRepository().haveSpace(USERNAME, SCRIPT_NAME, DEFAULT_QUOTA.asLong());
+    }
+
+    @Test
+    default void haveSpaceShouldThrowWhenQuotaIsExceed() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        assertThatThrownBy(() -> sieveRepository().haveSpace(USERNAME, SCRIPT_NAME, DEFAULT_QUOTA.asLong() + 1))
+            .isInstanceOf(QuotaExceededException.class);
+    }
+
+    @Test
+    default void haveSpaceShouldNotThrowWhenAttemptToReplaceOtherScript() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().haveSpace(USERNAME, SCRIPT_NAME, USER_QUOTA.asLong());
+    }
+
+    @Test
+    default void haveSpaceShouldThrowWhenAttemptToReplaceOtherScriptWithTooLargeScript() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        assertThatThrownBy(() -> sieveRepository().haveSpace(USERNAME, SCRIPT_NAME, USER_QUOTA.asLong() + 1))
+            .isInstanceOf(QuotaExceededException.class);
+    }
+
+    @Test
+    default void haveSpaceShouldTakeAlreadyExistingScriptsIntoAccount() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        assertThatThrownBy(() -> sieveRepository().haveSpace(USERNAME, OTHER_SCRIPT_NAME, USER_QUOTA.asLong() - 1))
+            .isInstanceOf(QuotaExceededException.class);
+    }
+
+    @Test
+    default void haveSpaceShouldNotThrowAfterActivatingAScript() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        sieveRepository().haveSpace(USERNAME, SCRIPT_NAME, USER_QUOTA.asLong());
+    }
+
+    @Test
+    default void listScriptsShouldReturnAnEmptyListIfUserNotFound() throws Exception {
+        assertThat(sieveRepository().listScripts(USERNAME)).isEmpty();
+    }
+
+    @Test
+    default void listScriptsShouldReturnEmptyListWhenThereIsNoScript() throws Exception {
+        assertThat(sieveRepository().listScripts(USERNAME)).isEmpty();
+    }
+
+    @Test
+    default void putScriptShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        assertThat(sieveRepository().listScripts(USERNAME)).containsOnly(new ScriptSummary(SCRIPT_NAME, false));
+    }
+
+    @Test
+    default void setActiveShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        assertThat(sieveRepository().listScripts(USERNAME)).containsOnly(new ScriptSummary(SCRIPT_NAME, true));
+    }
+
+    @Test
+    default void listScriptShouldCombineActiveAndPassiveScripts() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        sieveRepository().putScript(USERNAME, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
+        assertThat(sieveRepository().listScripts(USERNAME)).containsOnly(new ScriptSummary(SCRIPT_NAME, true), new ScriptSummary(OTHER_SCRIPT_NAME, false));
+    }
+
+    @Test
+    default void putScriptShouldThrowWhenScriptTooBig() throws Exception {
+        sieveRepository().setDefaultQuota(QuotaSizeLimit.size(SCRIPT_CONTENT.length() - 1));
+        assertThatThrownBy(() -> sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT))
+            .isInstanceOf(QuotaExceededException.class);
+    }
+
+    @Test
+    default void putScriptShouldThrowWhenQuotaChangedInBetween() throws Exception {
+        sieveRepository().setDefaultQuota(QuotaSizeLimit.size(SCRIPT_CONTENT.length()));
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setDefaultQuota(QuotaSizeLimit.size(SCRIPT_CONTENT.length() - 1));
+        assertThatThrownBy(() -> sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT))
+            .isInstanceOf(QuotaExceededException.class);
+    }
+
+    @Test
+    default void setActiveScriptShouldThrowOnNonExistentScript() {
+        assertThatThrownBy(() -> sieveRepository().setActive(USERNAME, SCRIPT_NAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void setActiveScriptShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        assertThat(getScriptContent(sieveRepository().getActive(USERNAME))).isEqualTo(SCRIPT_CONTENT);
+    }
+
+    @Test
+    default void setActiveSwitchScriptShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        sieveRepository().putScript(USERNAME, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, OTHER_SCRIPT_NAME);
+        assertThat(getScriptContent(sieveRepository().getActive(USERNAME))).isEqualTo(OTHER_SCRIPT_CONTENT);
+    }
+
+    @Test
+    default void switchOffActiveScriptShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        sieveRepository().setActive(USERNAME, SieveRepository.NO_SCRIPT_NAME);
+        assertThatThrownBy(() -> sieveRepository().getActive(USERNAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void switchOffActiveScriptShouldNotThrow() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        sieveRepository().setActive(USERNAME, SieveRepository.NO_SCRIPT_NAME);
+    }
+
+    @Test
+    default void getActiveShouldThrowWhenNoActiveScript() {
+        assertThatThrownBy(() -> sieveRepository().getActive(USERNAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void deleteActiveScriptShouldThrowIfScriptDoNotExist() {
+        assertThatThrownBy(() -> sieveRepository().deleteScript(USERNAME, SCRIPT_NAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void deleteActiveScriptShouldThrow() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        assertThatThrownBy(() -> sieveRepository().deleteScript(USERNAME, SCRIPT_NAME))
+            .isInstanceOf(IsActiveException.class);
+    }
+
+    @Test
+    default void deleteScriptShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().deleteScript(USERNAME, SCRIPT_NAME);
+        assertThatThrownBy(() -> sieveRepository().getScript(USERNAME, SCRIPT_NAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void renameScriptShouldThrowIfScriptNotFound() {
+        assertThatThrownBy(() -> sieveRepository().renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME))
+            .isInstanceOf(ScriptNotFoundException.class);
+    }
+
+    @Test
+    default void renameScriptShouldWork() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME);
+        assertThat(getScriptContent(sieveRepository().getScript(USERNAME, OTHER_SCRIPT_NAME))).isEqualTo(SCRIPT_CONTENT);
+    }
+
+    @Test
+    default void renameScriptShouldPropagateActiveScript() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().setActive(USERNAME, SCRIPT_NAME);
+        sieveRepository().renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME);
+        assertThat(getScriptContent(sieveRepository().getActive(USERNAME))).isEqualTo(SCRIPT_CONTENT);
+    }
+
+    @Test
+    default void renameScriptShouldNotOverwriteExistingScript() throws Exception {
+        sieveRepository().putScript(USERNAME, SCRIPT_NAME, SCRIPT_CONTENT);
+        sieveRepository().putScript(USERNAME, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
+        assertThatThrownBy(() -> sieveRepository().renameScript(USERNAME, SCRIPT_NAME, OTHER_SCRIPT_NAME))
+            .isInstanceOf(DuplicateException.class);
+    }
+
+    @Test
+    default void getQuotaShouldThrowIfQuotaNotFound() {
+        assertThatThrownBy(() -> sieveRepository().getDefaultQuota())
+            .isInstanceOf(QuotaNotFoundException.class);
+    }
+
+    @Test
+    default void getQuotaShouldWork() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        assertThat(sieveRepository().getDefaultQuota()).isEqualTo(DEFAULT_QUOTA);
+    }
+
+    @Test
+    default void getQuotaShouldWorkOnUsers() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        assertThat(sieveRepository().getQuota(USERNAME)).isEqualTo(USER_QUOTA);
+    }
+
+    @Test
+    default void hasQuotaShouldReturnFalseWhenRepositoryDoesNotHaveQuota() throws Exception {
+        assertThat(sieveRepository().hasDefaultQuota()).isFalse();
+    }
+
+    @Test
+    default void hasQuotaShouldReturnTrueWhenRepositoryHaveQuota() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        assertThat(sieveRepository().hasDefaultQuota()).isTrue();
+    }
+
+    @Test
+    default void hasQuotaShouldReturnFalseWhenUserDoesNotHaveQuota() throws Exception {
+        assertThat(sieveRepository().hasDefaultQuota()).isFalse();
+    }
+
+    @Test
+    default void hasQuotaShouldReturnTrueWhenUserHaveQuota() throws Exception {
+        sieveRepository().setQuota(USERNAME, DEFAULT_QUOTA);
+        assertThat(sieveRepository().hasQuota(USERNAME)).isTrue();
+    }
+
+    @Test
+    default void removeQuotaShouldNotThrowIfRepositoryDoesNotHaveQuota() throws Exception {
+        sieveRepository().removeQuota();
+    }
+
+    @Test
+    default void removeUserQuotaShouldNotThrowWhenAbsent() throws Exception {
+        sieveRepository().removeQuota(USERNAME);
+    }
+
+    @Test
+    default void removeQuotaShouldWorkOnRepositories() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        sieveRepository().removeQuota();
+        assertThat(sieveRepository().hasDefaultQuota()).isFalse();
+    }
+
+    @Test
+    default void removeQuotaShouldWorkOnUsers() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().removeQuota(USERNAME);
+        assertThat(sieveRepository().hasQuota(USERNAME)).isFalse();
+    }
+
+    @Test
+    default void removeQuotaShouldWorkOnUsersWithGlobalQuota() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().removeQuota(USERNAME);
+        assertThatThrownBy(() -> sieveRepository().getQuota(USERNAME))
+            .isInstanceOf(QuotaNotFoundException.class);
+    }
+
+    @Test
+    default void setQuotaShouldWork() throws Exception {
+        sieveRepository().setDefaultQuota(DEFAULT_QUOTA);
+        assertThat(sieveRepository().getDefaultQuota()).isEqualTo(DEFAULT_QUOTA);
+    }
+
+    @Test
+    default void setQuotaShouldWorkOnUsers() throws Exception {
+        sieveRepository().setQuota(USERNAME, DEFAULT_QUOTA);
+        assertThat(sieveRepository().getQuota(USERNAME)).isEqualTo(DEFAULT_QUOTA);
+    }
+
+    @Test
+    default void setQuotaShouldOverrideExistingQuota() throws Exception {
+        sieveRepository().setQuota(USERNAME, USER_QUOTA);
+        sieveRepository().setQuota(USERNAME, QuotaSizeLimit.size(USER_QUOTA.asLong() - 1));
+        assertThat(sieveRepository().getQuota(USERNAME)).isEqualTo(QuotaSizeLimit.size(USER_QUOTA.asLong() - 1));
+    }
+
+    default ScriptContent getScriptContent(InputStream inputStream) throws IOException {
+        return new ScriptContent(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
+    }
+}


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


[james-project] 24/26: [Refactoring] Migrate AbstractDomainListTest to DomainListContract JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e8d9cff379583fb67e98642282d2da9a803edc53
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 16:42:37 2020 +0700

    [Refactoring] Migrate AbstractDomainListTest to DomainListContract JUnit5
---
 .../cassandra/CassandraDomainListTest.java         |  41 ++---
 .../james/domainlist/jpa/JPADomainListTest.java    |  28 ++--
 .../domainlist/lib/AbstractDomainListTest.java     | 168 ---------------------
 .../james/domainlist/lib/DomainListContract.java   | 159 +++++++++++++++++++
 .../domainlist/memory/MemoryDomainListTest.java    |  24 ++-
 5 files changed, 201 insertions(+), 219 deletions(-)

diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CassandraDomainListTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CassandraDomainListTest.java
index 9e869fb..3fa2c61 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CassandraDomainListTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CassandraDomainListTest.java
@@ -20,38 +20,27 @@
 package org.apache.james.domainlist.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.lib.AbstractDomainListTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.domainlist.lib.DomainListContract;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraDomainListTest extends AbstractDomainListTest {
+class CassandraDomainListTest implements DomainListContract {
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraDomainListModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    CassandraDomainList domainList;
 
-    private CassandraCluster cassandra;
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(CassandraDomainListModule.MODULE, cassandraServer.getHost());
-        super.setUp();
-    }
-
-    @After
-    public void tearDown() {
-        cassandra.close();
+    @BeforeEach
+    public void setUp(CassandraCluster cassandra) throws Exception {
+        domainList = new CassandraDomainList(getDNSServer("localhost"), cassandra.getConf());
+        domainList.setAutoDetect(false);
+        domainList.setAutoDetectIP(false);
     }
 
     @Override
-    protected DomainList createDomainList() throws Exception {
-        CassandraDomainList testee = new CassandraDomainList(getDNSServer("localhost"), cassandra.getConf());
-        testee.setAutoDetect(false);
-        testee.setAutoDetectIP(false);
-        return testee;
+    public DomainList domainList() {
+        return domainList;
     }
-
 }
diff --git a/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java b/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java
index 0126bb1..1faac7c 100644
--- a/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java
+++ b/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java
@@ -22,24 +22,25 @@ import org.apache.james.backends.jpa.JpaTestCluster;
 import org.apache.james.core.Domain;
 import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.jpa.model.JPADomain;
-import org.apache.james.domainlist.lib.AbstractDomainListTest;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.james.domainlist.lib.DomainListContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
 /**
  * Test the JPA implementation of the DomainList.
  */
-public class JPADomainListTest extends AbstractDomainListTest {
+class JPADomainListTest implements DomainListContract {
 
-    private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPADomain.class);
+    static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPADomain.class);
 
-    @Override
-    @Before
+    JPADomainList jpaDomainList;
+
+    @BeforeEach
     public void setUp() throws Exception {
-        super.setUp();
+        jpaDomainList = createDomainList();
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         DomainList domainList = createDomainList();
         for (Domain domain: domainList.getDomains()) {
@@ -48,13 +49,16 @@ public class JPADomainListTest extends AbstractDomainListTest {
     }
 
     @Override
-    protected DomainList createDomainList() throws Exception {
+    public DomainList domainList() {
+        return jpaDomainList;
+    }
+
+    private JPADomainList createDomainList() throws Exception {
         JPADomainList jpaDomainList = new JPADomainList(getDNSServer("localhost"),
             JPA_TEST_CLUSTER.getEntityManagerFactory());
         jpaDomainList.setAutoDetect(false);
         jpaDomainList.setAutoDetectIP(false);
-        
+
         return jpaDomainList;
     }
-
 }
diff --git a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
deleted file mode 100644
index e54cc05..0000000
--- a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
+++ /dev/null
@@ -1,168 +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.domainlist.lib;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Fail.fail;
-
-import java.net.UnknownHostException;
-
-import org.apache.james.core.Domain;
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.dnsservice.api.InMemoryDNSService;
-import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.api.DomainListException;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractDomainListTest {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDomainListTest.class);
-
-    private static final Domain DOMAIN_1 = Domain.of("domain1.tld");
-    private static final Domain DOMAIN_2 = Domain.of("domain2.tld");
-    private static final Domain DOMAIN_3 = Domain.of("domain3.tld");
-    private static final Domain DOMAIN_4 = Domain.of("domain4.tld");
-    private static final Domain DOMAIN_5 = Domain.of("domain5.tld");
-    private static final Domain DOMAIN_UPPER_5 = Domain.of("Domain5.tld");
-
-    private DomainList domainList;
-
-    public void setUp() throws Exception {
-        domainList = createDomainList();
-    }
-
-    @Test
-    public void createListDomains() throws DomainListException {
-        domainList.addDomain(DOMAIN_3);
-        domainList.addDomain(DOMAIN_4);
-        domainList.addDomain(DOMAIN_5);
-        assertThat(domainList.getDomains()).containsOnly(DOMAIN_3, DOMAIN_4, DOMAIN_5);
-    }
-
-    @Test
-    public void domainsShouldBeListedInLowerCase() throws DomainListException {
-        domainList.addDomain(DOMAIN_UPPER_5);
-        assertThat(domainList.getDomains()).containsOnly(DOMAIN_5);
-    }
-
-    @Test
-    public void containShouldReturnTrueWhenThereIsADomain() throws DomainListException {
-        domainList.addDomain(DOMAIN_2);
-        assertThat(domainList.containsDomain(DOMAIN_2)).isTrue();
-    }
-
-    @Test
-    public void containShouldBeCaseSensitive() throws DomainListException {
-        domainList.addDomain(DOMAIN_5);
-        assertThat(domainList.containsDomain(DOMAIN_UPPER_5)).isTrue();
-    }
-
-    @Test
-    public void listDomainsShouldReturnNullWhenThereIsNoDomains() throws DomainListException {
-        assertThat(domainList.getDomains()).isEmpty();
-    }
-
-    @Test
-    public void testAddRemoveContainsSameDomain() throws DomainListException {
-        domainList.addDomain(DOMAIN_1);
-        domainList.removeDomain(DOMAIN_1);
-        assertThat(domainList.getDomains()).isEmpty();
-    }
-
-    @Test(expected = DomainListException.class)
-    public void addShouldBeCaseSensitive() throws DomainListException {
-        try {
-            domainList.addDomain(DOMAIN_5);
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
-        domainList.addDomain(DOMAIN_UPPER_5);
-    }
-
-    @Test
-    public void deletingADomainShouldNotDeleteOtherDomains() throws DomainListException {
-        domainList.addDomain(DOMAIN_1);
-        try {
-            domainList.removeDomain(DOMAIN_2);
-        } catch (DomainListException e) {
-            LOGGER.info("Ignored error", e);
-        }
-        assertThat(domainList.getDomains()).containsOnly(DOMAIN_1);
-    }
-
-    @Test
-    public void containShouldReturnFalseWhenThereIsNoDomain() throws DomainListException {
-        assertThat(domainList.containsDomain(DOMAIN_1)).isFalse();
-    }
-
-    @Test
-    public void containsShouldReturnFalseWhenDomainIsRemoved() throws DomainListException {
-        domainList.addDomain(DOMAIN_1);
-        domainList.removeDomain(DOMAIN_1);
-        assertThat(domainList.containsDomain(DOMAIN_1)).isFalse();
-    }
-
-    @Test
-    public void removeShouldRemoveDomainsUsingUpperCases() throws DomainListException {
-        domainList.addDomain(DOMAIN_UPPER_5);
-        domainList.removeDomain(DOMAIN_UPPER_5);
-        assertThat(domainList.containsDomain(DOMAIN_UPPER_5)).isFalse();
-    }
-
-    @Test
-    public void removeShouldRemoveDomainsUsingLowerCases() throws DomainListException {
-        domainList.addDomain(DOMAIN_UPPER_5);
-        domainList.removeDomain(DOMAIN_5);
-        assertThat(domainList.containsDomain(DOMAIN_UPPER_5)).isFalse();
-    }
-
-    @Test(expected = DomainListException.class)
-    public void addDomainShouldThrowIfWeAddTwoTimesTheSameDomain() throws DomainListException {
-        try {
-            domainList.addDomain(DOMAIN_1);
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
-        domainList.addDomain(DOMAIN_1);
-    }
-
-    @Test(expected = DomainListException.class)
-    public void removeDomainShouldThrowIfTheDomainIsAbsent() throws DomainListException {
-        domainList.removeDomain(DOMAIN_1);
-    }
-
-    /**
-     * Return a fake DNSServer.
-     */
-    protected DNSService getDNSServer(final String hostName) throws UnknownHostException {
-        return new InMemoryDNSService()
-            .registerMxRecord(hostName, "127.0.0.1")
-            .registerMxRecord("127.0.0.1", "127.0.0.1");
-    }
-
-    /**
-     * Implementing test classes must provide the corresponding implement
-     * of the DomainList interface.
-     * 
-     * @return an implementation of DomainList
-     */
-    protected abstract DomainList createDomainList() throws Exception;
-}
diff --git a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListContract.java b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListContract.java
new file mode 100644
index 0000000..9388bea
--- /dev/null
+++ b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListContract.java
@@ -0,0 +1,159 @@
+/****************************************************************
+ * 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.domainlist.lib;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Fail.fail;
+
+import java.net.UnknownHostException;
+
+import org.apache.james.core.Domain;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.dnsservice.api.InMemoryDNSService;
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.james.domainlist.api.DomainListException;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public interface DomainListContract {
+    Logger LOGGER = LoggerFactory.getLogger(DomainListContract.class);
+
+    Domain DOMAIN_1 = Domain.of("domain1.tld");
+    Domain DOMAIN_2 = Domain.of("domain2.tld");
+    Domain DOMAIN_3 = Domain.of("domain3.tld");
+    Domain DOMAIN_4 = Domain.of("domain4.tld");
+    Domain DOMAIN_5 = Domain.of("domain5.tld");
+    Domain DOMAIN_UPPER_5 = Domain.of("Domain5.tld");
+
+    DomainList domainList();
+
+    @Test
+    default void createListDomains() throws DomainListException {
+        domainList().addDomain(DOMAIN_3);
+        domainList().addDomain(DOMAIN_4);
+        domainList().addDomain(DOMAIN_5);
+        assertThat(domainList().getDomains()).containsOnly(DOMAIN_3, DOMAIN_4, DOMAIN_5);
+    }
+
+    @Test
+    default void domainsShouldBeListedInLowerCase() throws DomainListException {
+        domainList().addDomain(DOMAIN_UPPER_5);
+        assertThat(domainList().getDomains()).containsOnly(DOMAIN_5);
+    }
+
+    @Test
+    default void containShouldReturnTrueWhenThereIsADomain() throws DomainListException {
+        domainList().addDomain(DOMAIN_2);
+        assertThat(domainList().containsDomain(DOMAIN_2)).isTrue();
+    }
+
+    @Test
+    default void containShouldBeCaseSensitive() throws DomainListException {
+        domainList().addDomain(DOMAIN_5);
+        assertThat(domainList().containsDomain(DOMAIN_UPPER_5)).isTrue();
+    }
+
+    @Test
+    default void listDomainsShouldReturnNullWhenThereIsNoDomains() throws DomainListException {
+        assertThat(domainList().getDomains()).isEmpty();
+    }
+
+    @Test
+    default void testAddRemoveContainsSameDomain() throws DomainListException {
+        domainList().addDomain(DOMAIN_1);
+        domainList().removeDomain(DOMAIN_1);
+        assertThat(domainList().getDomains()).isEmpty();
+    }
+
+    @Test
+    default void addShouldBeCaseSensitive() {
+        try {
+            domainList().addDomain(DOMAIN_5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        assertThatThrownBy(() -> domainList().addDomain(DOMAIN_UPPER_5))
+            .isInstanceOf(DomainListException.class);
+    }
+
+    @Test
+    default void deletingADomainShouldNotDeleteOtherDomains() throws DomainListException {
+        domainList().addDomain(DOMAIN_1);
+        try {
+            domainList().removeDomain(DOMAIN_2);
+        } catch (DomainListException e) {
+            LOGGER.info("Ignored error", e);
+        }
+        assertThat(domainList().getDomains()).containsOnly(DOMAIN_1);
+    }
+
+    @Test
+    default void containShouldReturnFalseWhenThereIsNoDomain() throws DomainListException {
+        assertThat(domainList().containsDomain(DOMAIN_1)).isFalse();
+    }
+
+    @Test
+    default void containsShouldReturnFalseWhenDomainIsRemoved() throws DomainListException {
+        domainList().addDomain(DOMAIN_1);
+        domainList().removeDomain(DOMAIN_1);
+        assertThat(domainList().containsDomain(DOMAIN_1)).isFalse();
+    }
+
+    @Test
+    default void removeShouldRemoveDomainsUsingUpperCases() throws DomainListException {
+        domainList().addDomain(DOMAIN_UPPER_5);
+        domainList().removeDomain(DOMAIN_UPPER_5);
+        assertThat(domainList().containsDomain(DOMAIN_UPPER_5)).isFalse();
+    }
+
+    @Test
+    default void removeShouldRemoveDomainsUsingLowerCases() throws DomainListException {
+        domainList().addDomain(DOMAIN_UPPER_5);
+        domainList().removeDomain(DOMAIN_5);
+        assertThat(domainList().containsDomain(DOMAIN_UPPER_5)).isFalse();
+    }
+
+    @Test
+    default void addDomainShouldThrowIfWeAddTwoTimesTheSameDomain() {
+        try {
+            domainList().addDomain(DOMAIN_1);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        assertThatThrownBy(() -> domainList().addDomain(DOMAIN_1))
+            .isInstanceOf(DomainListException.class);
+    }
+
+    @Test
+    default void removeDomainShouldThrowIfTheDomainIsAbsent() {
+        assertThatThrownBy(() -> domainList().removeDomain(DOMAIN_1))
+            .isInstanceOf(DomainListException.class);
+    }
+
+    /**
+     * Return a fake DNSServer.
+     */
+    default DNSService getDNSServer(final String hostName) throws UnknownHostException {
+        return new InMemoryDNSService()
+            .registerMxRecord(hostName, "127.0.0.1")
+            .registerMxRecord("127.0.0.1", "127.0.0.1");
+    }
+}
diff --git a/server/data/data-memory/src/test/java/org/apache/james/domainlist/memory/MemoryDomainListTest.java b/server/data/data-memory/src/test/java/org/apache/james/domainlist/memory/MemoryDomainListTest.java
index 2095aa5..42ee644 100644
--- a/server/data/data-memory/src/test/java/org/apache/james/domainlist/memory/MemoryDomainListTest.java
+++ b/server/data/data-memory/src/test/java/org/apache/james/domainlist/memory/MemoryDomainListTest.java
@@ -20,23 +20,21 @@
 package org.apache.james.domainlist.memory;
 
 import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.lib.AbstractDomainListTest;
-import org.junit.Before;
+import org.apache.james.domainlist.lib.DomainListContract;
+import org.junit.jupiter.api.BeforeEach;
 
-public class MemoryDomainListTest extends AbstractDomainListTest {
+class MemoryDomainListTest implements DomainListContract {
+    MemoryDomainList domainList;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
+    @BeforeEach
+    void setUp() throws Exception {
+        domainList = new MemoryDomainList(getDNSServer("localhost"));
+        domainList.setAutoDetect(false);
+        domainList.setAutoDetectIP(false);
     }
 
     @Override
-    protected DomainList createDomainList() throws Exception {
-        MemoryDomainList testee = new MemoryDomainList(getDNSServer("localhost"));
-        testee.setAutoDetect(false);
-        testee.setAutoDetectIP(false);
-        return testee;
+    public DomainList domainList() {
+        return domainList;
     }
-
 }


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


[james-project] 03/26: [Refactoring] Migrate TestScriptedUserAdder to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 00139201c977ed1088f9340a31145a71a70b4d5a
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 31 17:02:53 2020 +0700

    [Refactoring] Migrate TestScriptedUserAdder to JUnit5
---
 .../apache/james/mpt/TestScriptedUserAdder.java    | 23 +++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java b/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java
index b490e3d..e7b4b60 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java
@@ -23,32 +23,33 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.core.Username;
 import org.apache.james.mpt.user.ScriptedUserAdder;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class TestScriptedUserAdder {
+class TestScriptedUserAdder {
     
-    private DiscardProtocol protocol;
+    DiscardProtocol protocol;
     
-    private DiscardProtocol.Record record;
+    DiscardProtocol.Record record;
     
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         protocol = new DiscardProtocol();
         protocol.start();
         record = protocol.recordNext();
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterEach
+    void tearDown() {
         protocol.stop();
     }
 
     @Test
-    public void testShouldExecuteScriptAgainstPort() throws Exception {
+    void testShouldExecuteScriptAgainstPort() throws Exception {
         ScriptedUserAdder adder = new ScriptedUserAdder("localhost", protocol.getPort(), "C: USER='${user}' password='${password}'");
         adder.addUser(Username.of("user"), "Some Password");
+
         assertThat(record.complete()).isEqualTo("USER='user' password='Some Password'\r\n");
     }
 }


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


[james-project] 06/26: [Refactoring] Migrate SieveQuotaTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f76deb6cea45013edd4d720b898cb7cedb365fbc
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Aug 12 15:39:49 2020 +0700

    [Refactoring] Migrate SieveQuotaTest to JUnit5
---
 .../sieve/cassandra/model/SieveQuotaTest.java      | 42 ++++++++++++----------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/SieveQuotaTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/SieveQuotaTest.java
index 213add4..99e2a75 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/SieveQuotaTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/SieveQuotaTest.java
@@ -19,42 +19,46 @@
 
 package org.apache.james.sieve.cassandra.model;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import java.util.Optional;
 
 import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.sieverepository.api.exception.QuotaExceededException;
-import org.junit.Test;
-
-public class SieveQuotaTest {
+import org.junit.jupiter.api.Test;
 
-    public static final long INVALID_VALUE = -1L;
-    public static final QuotaSizeLimit LIMIT_LOW_VALUE = QuotaSizeLimit.size(10L);
-    public static final long SIZE_DIFFERENCE = 20L;
-    public static final int CURRENT_USAGE = 0;
-    public static final QuotaSizeLimit LIMIT_HIGH_VALUE = QuotaSizeLimit.size(100L);
+class SieveQuotaTest {
+    static final long INVALID_VALUE = -1L;
+    static final QuotaSizeLimit LIMIT_LOW_VALUE = QuotaSizeLimit.size(10L);
+    static final long SIZE_DIFFERENCE = 20L;
+    static final int CURRENT_USAGE = 0;
+    static final QuotaSizeLimit LIMIT_HIGH_VALUE = QuotaSizeLimit.size(100L);
 
-    @Test(expected = IllegalArgumentException.class)
-    public void sieveQuotaShouldThrowOnNegativeCurrentValue() {
-        new SieveQuota(INVALID_VALUE, Optional.empty());
+    @Test
+    void sieveQuotaShouldThrowOnNegativeCurrentValue() {
+        assertThatThrownBy(() -> new SieveQuota(INVALID_VALUE, Optional.empty()))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void sieveQuotaShouldThrowOnNegativeLimitValue() {
-        new SieveQuota(0, Optional.of(QuotaSizeLimit.size(INVALID_VALUE)));
+    @Test
+    void sieveQuotaShouldThrowOnNegativeLimitValue() {
+        assertThatThrownBy(() -> new SieveQuota(0, Optional.of(QuotaSizeLimit.size(INVALID_VALUE))))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
-    @Test(expected = QuotaExceededException.class)
-    public void checkOverQuotaUponModificationShouldThrowIfLimitExceeded() throws Exception {
-        new SieveQuota(CURRENT_USAGE, Optional.of(LIMIT_LOW_VALUE)).checkOverQuotaUponModification(SIZE_DIFFERENCE);
+    @Test
+    void checkOverQuotaUponModificationShouldThrowIfLimitExceeded() {
+        assertThatThrownBy(() -> new SieveQuota(CURRENT_USAGE, Optional.of(LIMIT_LOW_VALUE)).checkOverQuotaUponModification(SIZE_DIFFERENCE))
+            .isInstanceOf(QuotaExceededException.class);
     }
 
     @Test
-    public void checkOverQuotaShouldNotThrowWhenNoLimit() throws Exception {
+    void checkOverQuotaShouldNotThrowWhenNoLimit() throws Exception {
         new SieveQuota(CURRENT_USAGE, Optional.empty()).checkOverQuotaUponModification(SIZE_DIFFERENCE);
     }
 
     @Test
-    public void checkOverQuotaUponModificationShouldNotThrowIfLimitNotExceeded() throws Exception {
+    void checkOverQuotaUponModificationShouldNotThrowIfLimitNotExceeded() throws Exception {
         new SieveQuota(CURRENT_USAGE, Optional.of(LIMIT_HIGH_VALUE)).checkOverQuotaUponModification(SIZE_DIFFERENCE);
     }
 }


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


[james-project] 09/26: [Refactoring] Migrate AccessTokenRepositoryTest to AccessTokenRepositoryContract in JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0306f81e1d0fb704886167cd84524eac2908d288
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:02:05 2020 +0700

    [Refactoring] Migrate AccessTokenRepositoryTest to AccessTokenRepositoryContract in JUnit5
---
 .../access/CassandraAccessTokenRepositoryTest.java | 37 ++++-----
 .../api/access/AccessTokenRepositoryContract.java  | 85 ++++++++++++++++++++
 .../jmap/api/access/AccessTokenRepositoryTest.java | 91 ----------------------
 .../access/MemoryAccessTokenRepositoryTest.java    | 20 ++---
 4 files changed, 109 insertions(+), 124 deletions(-)

diff --git a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenRepositoryTest.java b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenRepositoryTest.java
index 5e2c7b3..66640e9 100644
--- a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenRepositoryTest.java
+++ b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenRepositoryTest.java
@@ -20,36 +20,27 @@
 package org.apache.james.jmap.cassandra.access;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.jmap.api.access.AccessTokenRepository;
-import org.apache.james.jmap.api.access.AccessTokenRepositoryTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.jmap.api.access.AccessTokenRepositoryContract;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraAccessTokenRepositoryTest extends AccessTokenRepositoryTest {
+class CassandraAccessTokenRepositoryTest implements AccessTokenRepositoryContract {
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraAccessModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule();
-    
-    private CassandraCluster cassandra;
+    AccessTokenRepository accessTokenRepository;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(CassandraAccessModule.MODULE, cassandraServer.getHost());
-        super.setUp();
-    }
-    
-    @After
-    public void tearDown() {
-        cassandra.close();
+    @BeforeEach
+    void setUp(CassandraCluster cassandra) {
+        accessTokenRepository = new CassandraAccessTokenRepository(
+            new CassandraAccessTokenDAO(cassandra.getConf(), AccessTokenRepositoryContract.TTL_IN_MS));
     }
 
     @Override
-    protected AccessTokenRepository provideAccessTokenRepository() {
-        return new CassandraAccessTokenRepository(
-            new CassandraAccessTokenDAO(cassandra.getConf(), AccessTokenRepositoryTest.TTL_IN_MS));
+    public AccessTokenRepository accessTokenRepository() {
+        return accessTokenRepository;
     }
 
 }
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryContract.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryContract.java
new file mode 100644
index 0000000..87e11cf
--- /dev/null
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryContract.java
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.jmap.api.access;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.core.Username;
+import org.apache.james.jmap.api.access.exceptions.InvalidAccessToken;
+import org.junit.jupiter.api.Test;
+
+public interface AccessTokenRepositoryContract {
+    AccessToken TOKEN = AccessToken.generate();
+    Username USERNAME = Username.of("username");
+    long TTL_IN_MS = 1000;
+
+    AccessTokenRepository accessTokenRepository();
+
+    @Test
+    default void validTokenMustBeRetrieved() {
+        accessTokenRepository().addToken(USERNAME, TOKEN).block();
+        assertThat(accessTokenRepository().getUsernameFromToken(TOKEN).block()).isEqualTo(USERNAME);
+    }
+
+    @Test
+    default void absentTokensMustBeInvalid() {
+        assertThatThrownBy(() -> accessTokenRepository().getUsernameFromToken(TOKEN).block()).isExactlyInstanceOf(InvalidAccessToken.class);
+    }
+
+    @Test
+    default void removedTokensMustBeInvalid() {
+        accessTokenRepository().addToken(USERNAME, TOKEN).block();
+        accessTokenRepository().removeToken(TOKEN).block();
+        assertThatThrownBy(() -> accessTokenRepository().getUsernameFromToken(TOKEN).block()).isExactlyInstanceOf(InvalidAccessToken.class);
+    }
+
+    @Test
+    default void outDatedTokenMustBeInvalid() throws Exception {
+        accessTokenRepository().addToken(USERNAME, TOKEN).block();
+        Thread.sleep(2 * TTL_IN_MS);
+        assertThatThrownBy(() -> accessTokenRepository().getUsernameFromToken(TOKEN).block()).isExactlyInstanceOf(InvalidAccessToken.class);
+    }
+
+    @Test
+    default void addTokenMustThrowWhenUsernameIsNull() {
+        assertThatThrownBy(() -> accessTokenRepository().addToken(null, TOKEN))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    default void addTokenMustThrowWhenTokenIsNull() {
+        assertThatThrownBy(() -> accessTokenRepository().addToken(USERNAME, null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    default void removeTokenTokenMustThrowWhenTokenIsNull() {
+        assertThatThrownBy(() -> accessTokenRepository().removeToken(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    default void getUsernameFromTokenMustThrowWhenTokenIsNull() {
+        assertThatThrownBy(() -> accessTokenRepository().getUsernameFromToken(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+}
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryTest.java
deleted file mode 100644
index 4d9ec04..0000000
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AccessTokenRepositoryTest.java
+++ /dev/null
@@ -1,91 +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.jmap.api.access;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import org.apache.james.core.Username;
-import org.apache.james.jmap.api.access.exceptions.InvalidAccessToken;
-import org.junit.Test;
-
-public abstract class AccessTokenRepositoryTest {
-    private static final AccessToken TOKEN = AccessToken.generate();
-    private static final Username USERNAME = Username.of("username");
-    public static final long TTL_IN_MS = 1000;
-
-    private AccessTokenRepository accessTokenRepository;
-
-    protected abstract AccessTokenRepository provideAccessTokenRepository();
-
-    public void setUp() throws Exception {
-        this.accessTokenRepository = provideAccessTokenRepository();
-    }
-
-    @Test
-    public void validTokenMustBeRetrieved() throws Throwable {
-        accessTokenRepository.addToken(USERNAME, TOKEN).block();
-        assertThat(accessTokenRepository.getUsernameFromToken(TOKEN).block()).isEqualTo(USERNAME);
-    }
-
-    @Test
-    public void absentTokensMustBeInvalid() throws Exception {
-        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(TOKEN).block()).isExactlyInstanceOf(InvalidAccessToken.class);
-    }
-
-    @Test
-    public void removedTokensMustBeInvalid() throws Exception {
-        accessTokenRepository.addToken(USERNAME, TOKEN).block();
-        accessTokenRepository.removeToken(TOKEN).block();
-        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(TOKEN).block()).isExactlyInstanceOf(InvalidAccessToken.class);
-    }
-
-    @Test
-    public void outDatedTokenMustBeInvalid() throws Exception {
-        accessTokenRepository.addToken(USERNAME, TOKEN).block();
-        Thread.sleep(2 * TTL_IN_MS);
-        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(TOKEN).block()).isExactlyInstanceOf(InvalidAccessToken.class);
-    }
-
-    @Test
-    public void addTokenMustThrowWhenUsernameIsNull() throws Exception {
-        assertThatThrownBy(() -> accessTokenRepository.addToken(null, TOKEN))
-            .isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void addTokenMustThrowWhenTokenIsNull() throws Exception {
-        assertThatThrownBy(() -> accessTokenRepository.addToken(USERNAME, null))
-            .isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void removeTokenTokenMustThrowWhenTokenIsNull() throws Exception {
-        assertThatThrownBy(() -> accessTokenRepository.removeToken(null))
-            .isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void getUsernameFromTokenMustThrowWhenTokenIsNull() throws Exception {
-        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(null))
-            .isInstanceOf(NullPointerException.class);
-    }
-
-}
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/access/MemoryAccessTokenRepositoryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/access/MemoryAccessTokenRepositoryTest.java
index c63b460..4c868f1 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/access/MemoryAccessTokenRepositoryTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/access/MemoryAccessTokenRepositoryTest.java
@@ -20,19 +20,19 @@
 package org.apache.james.jmap.memory.access;
 
 import org.apache.james.jmap.api.access.AccessTokenRepository;
-import org.apache.james.jmap.api.access.AccessTokenRepositoryTest;
-import org.junit.Before;
+import org.apache.james.jmap.api.access.AccessTokenRepositoryContract;
+import org.junit.jupiter.api.BeforeEach;
 
-public class MemoryAccessTokenRepositoryTest extends AccessTokenRepositoryTest {
-    
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
+class MemoryAccessTokenRepositoryTest implements AccessTokenRepositoryContract {
+    AccessTokenRepository accessTokenRepository;
+
+    @BeforeEach
+    void setUp() {
+        accessTokenRepository = new MemoryAccessTokenRepository(AccessTokenRepositoryContract.TTL_IN_MS);
     }
     
     @Override
-    protected AccessTokenRepository provideAccessTokenRepository() {
-        return new MemoryAccessTokenRepository(AccessTokenRepositoryTest.TTL_IN_MS);
+    public AccessTokenRepository accessTokenRepository() {
+        return accessTokenRepository;
     }
 }


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


[james-project] 15/26: [Refactoring] Migrate DLPAggregateIdTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8fadbc57b4a8e32257dd39a6c3492ea58ff755d0
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:35:00 2020 +0700

    [Refactoring] Migrate DLPAggregateIdTest to JUnit5
---
 .../dlp/eventsourcing/aggregates/DLPAggregateIdTest.java      | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
index a5f740b..d74b8f6 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
@@ -23,26 +23,25 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.core.Domain;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class DLPAggregateIdTest {
-
+class DLPAggregateIdTest {
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(DLPAggregateId.class)
             .verify();
     }
 
     @Test
-    public void constructorShouldThrowWhenNullDomain() {
+    void constructorShouldThrowWhenNullDomain() {
         assertThatThrownBy(() -> new DLPAggregateId(null))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void asAggregateKeyShouldReturnAStringContainingThePrefixAndTheDomain() {
+    void asAggregateKeyShouldReturnAStringContainingThePrefixAndTheDomain() {
         assertThat(new DLPAggregateId(Domain.LOCALHOST).asAggregateKey())
             .isEqualTo("DLPRule/localhost");
     }


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


[james-project] 02/26: [Refactoring] Migrate TestFileProtocolSessionBuilder to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 57c11aae7018f5c249553c179b1497a41840263c
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 31 17:01:13 2020 +0700

    [Refactoring] Migrate TestFileProtocolSessionBuilder to JUnit5
---
 .../james/mpt/TestFileProtocolSessionBuilder.java  | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/mpt/core/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java b/mpt/core/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java
index bacb76c..47676b8 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java
@@ -28,26 +28,26 @@ import java.io.StringReader;
 
 import org.apache.james.mpt.api.ProtocolInteractor;
 import org.apache.james.mpt.protocol.ProtocolSessionBuilder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class TestFileProtocolSessionBuilder {
+class TestFileProtocolSessionBuilder {
 
-    private static final String SCRIPT_WITH_VARIABLES = "HELLO ${not} ${foo} WORLD ${bar}";
-    private static final String SCRIPT_WITH_FOO_REPLACED_BY_WHATEVER = "HELLO ${not} whatever WORLD ${bar}";
-    private static final String SCRIPT_WITH_VARIABLES_INLINED = "HELLO not foo WORLD bar";
+    static final String SCRIPT_WITH_VARIABLES = "HELLO ${not} ${foo} WORLD ${bar}";
+    static final String SCRIPT_WITH_FOO_REPLACED_BY_WHATEVER = "HELLO ${not} whatever WORLD ${bar}";
+    static final String SCRIPT_WITH_VARIABLES_INLINED = "HELLO not foo WORLD bar";
     
     ProtocolSessionBuilder builder;
     ProtocolInteractor session;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() {
         builder = new ProtocolSessionBuilder();
         session = mock(ProtocolInteractor.class);
     }
 
     @Test
-    public void testShouldPreserveContentsWhenNoVariablesSet() throws Exception {
+    void testShouldPreserveContentsWhenNoVariablesSet() throws Exception {
         builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + SCRIPT_WITH_VARIABLES), session);
 
         verify(session, times(1)).cl(-1, SCRIPT_WITH_VARIABLES);
@@ -55,7 +55,7 @@ public class TestFileProtocolSessionBuilder {
     }
 
     @Test
-    public void testShouldReplaceVariableWhenSet() throws Exception {
+    void testShouldReplaceVariableWhenSet() throws Exception {
         builder.setVariable("foo", "whatever");
         builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + SCRIPT_WITH_VARIABLES), session);
 
@@ -64,7 +64,7 @@ public class TestFileProtocolSessionBuilder {
     }
 
     @Test
-    public void testShouldReplaceAllVariablesWhenSet() throws Exception {
+    void testShouldReplaceAllVariablesWhenSet() throws Exception {
         builder.setVariable("bar", "bar");
         builder.setVariable("foo", "foo");
         builder.setVariable("not", "not");
@@ -75,7 +75,7 @@ public class TestFileProtocolSessionBuilder {
     }
 
     @Test
-    public void testShouldReplaceVariableAtBeginningAndEnd() throws Exception {
+    void testShouldReplaceVariableAtBeginningAndEnd() throws Exception {
         builder.setVariable("foo", "whatever");
         builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + "${foo} Some Other Script${foo}${foo}"), session);
 
@@ -84,7 +84,7 @@ public class TestFileProtocolSessionBuilder {
     }
 
     @Test
-    public void testShouldIgnoreNotQuiteVariables() throws Exception {
+    void testShouldIgnoreNotQuiteVariables() throws Exception {
         final String NEARLY = "{foo}${}${foo Some Other Script${foo}";
         builder.setVariable("foo", "whatever");
         builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + NEARLY), session);


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


[james-project] 21/26: [Refactoring] Migrate AbstractNotificationRegistryTest to NotificationRegistryContract JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7ff2ac7e114ee18da66c9fd3c58c4af0b82011c3
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:56:25 2020 +0700

    [Refactoring] Migrate AbstractNotificationRegistryTest to NotificationRegistryContract JUnit5
---
 .../CassandraNotificationRegistryTest.java         |  49 +++++----
 .../vacation/AbstractNotificationRegistryTest.java | 114 ---------------------
 .../api/vacation/NotificationRegistryContract.java | 103 +++++++++++++++++++
 .../vacation/MemoryNotificationRegistryTest.java   |  25 ++++-
 4 files changed, 146 insertions(+), 145 deletions(-)

diff --git a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraNotificationRegistryTest.java b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraNotificationRegistryTest.java
index d22d048..27f32f7 100644
--- a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraNotificationRegistryTest.java
+++ b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraNotificationRegistryTest.java
@@ -20,36 +20,33 @@
 package org.apache.james.jmap.cassandra.vacation;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
-import org.apache.james.jmap.api.vacation.AbstractNotificationRegistryTest;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
+import org.apache.james.core.MailAddress;
 import org.apache.james.jmap.api.vacation.NotificationRegistry;
-import org.apache.james.util.date.ZonedDateTimeProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-
-public class CassandraNotificationRegistryTest extends AbstractNotificationRegistryTest {
-
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule();
-    
-    private CassandraCluster cassandra;
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(CassandraNotificationRegistryModule.MODULE, cassandraServer.getHost());
-        super.setUp();
+import org.apache.james.jmap.api.vacation.NotificationRegistryContract;
+import org.apache.james.jmap.api.vacation.RecipientId;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class CassandraNotificationRegistryTest implements NotificationRegistryContract {
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraNotificationRegistryModule.MODULE);
+
+    NotificationRegistry notificationRegistry;
+    RecipientId recipientId;
+
+    @BeforeEach
+    public void setUp(CassandraCluster cassandra) throws Exception {
+        notificationRegistry = new CassandraNotificationRegistry(zonedDateTimeProvider, new CassandraNotificationRegistryDAO(cassandra.getConf()));;
+        recipientId = RecipientId.fromMailAddress(new MailAddress("benwa@apache.org"));
     }
-
-    @After
-    public void tearDown() {
-        cassandra.close();
+    @Override
+    public NotificationRegistry notificationRegistry() {
+        return notificationRegistry;
     }
 
     @Override
-    protected NotificationRegistry createNotificationRegistry(ZonedDateTimeProvider zonedDateTimeProvider) {
-        return new CassandraNotificationRegistry(zonedDateTimeProvider, new CassandraNotificationRegistryDAO(cassandra.getConf()));
+    public RecipientId recipientId() {
+        return recipientId;
     }
-
 }
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractNotificationRegistryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractNotificationRegistryTest.java
deleted file mode 100644
index c1c27bb..0000000
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractNotificationRegistryTest.java
+++ /dev/null
@@ -1,114 +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.jmap.api.vacation;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.time.ZonedDateTime;
-import java.util.Optional;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.james.core.MailAddress;
-import org.apache.james.util.date.ZonedDateTimeProvider;
-import org.junit.Before;
-import org.junit.Test;
-
-public abstract class AbstractNotificationRegistryTest {
-
-    public static final ZonedDateTime ZONED_DATE_TIME = ZonedDateTime.parse("2016-04-03T02:01:01+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime ZONED_DATE_TIME_PLUS_4_SECONDS = ZonedDateTime.parse("2016-04-03T02:01:05+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime ZONED_DATE_TIME_PLUS_8_SECONDS = ZonedDateTime.parse("2016-04-03T02:01:09+07:00[Asia/Vientiane]");
-    public static final AccountId ACCOUNT_ID = AccountId.fromString("id");
-
-    private NotificationRegistry notificationRegistry;
-    private ZonedDateTimeProvider zonedDateTimeProvider;
-    private RecipientId recipientId;
-
-    protected abstract NotificationRegistry createNotificationRegistry(ZonedDateTimeProvider zonedDateTimeProvider);
-
-    @Before
-    public void setUp() throws Exception {
-        zonedDateTimeProvider = mock(ZonedDateTimeProvider.class);
-        notificationRegistry = createNotificationRegistry(zonedDateTimeProvider);
-        recipientId = RecipientId.fromMailAddress(new MailAddress("benwa@apache.org"));
-    }
-
-    @Test
-    public void isRegisterShouldReturnFalseByDefault() {
-        assertThat(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block()).isFalse();
-    }
-
-    @Test
-    public void registerShouldWork() {
-        notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.empty()).block();
-
-        assertThat(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block()).isTrue();
-    }
-
-    @Test
-    public void registerShouldWorkWithExpiracyDate() {
-        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
-        notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.of(ZONED_DATE_TIME_PLUS_4_SECONDS)).block();
-
-        assertThat(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block()).isTrue();
-    }
-
-    @Test
-    public void registerShouldExpireAfterExpiracyDate() {
-        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
-
-        notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.of(ZONED_DATE_TIME_PLUS_4_SECONDS)).block();
-
-        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_PLUS_8_SECONDS);
-
-        await().atMost(20, TimeUnit.SECONDS).until(() -> !notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block());
-    }
-
-    @Test
-    public void flushShouldWork() {
-        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
-        notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.empty()).block();
-
-        notificationRegistry.flush(ACCOUNT_ID).block();
-
-        assertThat(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block()).isFalse();
-    }
-
-    @Test
-    public void registerShouldNotPersistWhenExpiryDateIsPast() {
-        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_PLUS_4_SECONDS);
-
-        notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.of(ZONED_DATE_TIME)).block();
-
-        assertThat(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block()).isFalse();
-    }
-
-    @Test
-    public void registerShouldNotPersistWhenExpiryDateIsPresent() {
-        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
-
-        notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.of(ZONED_DATE_TIME)).block();
-
-        assertThat(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId).block()).isTrue();
-    }
-}
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/NotificationRegistryContract.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/NotificationRegistryContract.java
new file mode 100644
index 0000000..afd2c64
--- /dev/null
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/NotificationRegistryContract.java
@@ -0,0 +1,103 @@
+/****************************************************************
+ * 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.jmap.api.vacation;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.time.ZonedDateTime;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.util.date.ZonedDateTimeProvider;
+import org.junit.jupiter.api.Test;
+
+public interface NotificationRegistryContract {
+    ZonedDateTime ZONED_DATE_TIME = ZonedDateTime.parse("2016-04-03T02:01:01+07:00[Asia/Vientiane]");
+    ZonedDateTime ZONED_DATE_TIME_PLUS_4_SECONDS = ZonedDateTime.parse("2016-04-03T02:01:05+07:00[Asia/Vientiane]");
+    ZonedDateTime ZONED_DATE_TIME_PLUS_8_SECONDS = ZonedDateTime.parse("2016-04-03T02:01:09+07:00[Asia/Vientiane]");
+    AccountId ACCOUNT_ID = AccountId.fromString("id");
+
+    ZonedDateTimeProvider zonedDateTimeProvider = mock(ZonedDateTimeProvider.class);
+    
+    NotificationRegistry notificationRegistry();
+    RecipientId recipientId();
+
+    @Test
+    default void isRegisterShouldReturnFalseByDefault() {
+        assertThat(notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block()).isFalse();
+    }
+
+    @Test
+    default void registerShouldWork() {
+        notificationRegistry().register(ACCOUNT_ID, recipientId(), Optional.empty()).block();
+
+        assertThat(notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block()).isTrue();
+    }
+
+    @Test
+    default void registerShouldWorkWithExpiracyDate() {
+        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
+        notificationRegistry().register(ACCOUNT_ID, recipientId(), Optional.of(ZONED_DATE_TIME_PLUS_4_SECONDS)).block();
+
+        assertThat(notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block()).isTrue();
+    }
+
+    @Test
+    default void registerShouldExpireAfterExpiracyDate() {
+        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
+
+        notificationRegistry().register(ACCOUNT_ID, recipientId(), Optional.of(ZONED_DATE_TIME_PLUS_4_SECONDS)).block();
+
+        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_PLUS_8_SECONDS);
+
+        await().atMost(20, TimeUnit.SECONDS).until(() -> !notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block());
+    }
+
+    @Test
+    default void flushShouldWork() {
+        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
+        notificationRegistry().register(ACCOUNT_ID, recipientId(), Optional.empty()).block();
+
+        notificationRegistry().flush(ACCOUNT_ID).block();
+
+        assertThat(notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block()).isFalse();
+    }
+
+    @Test
+    default void registerShouldNotPersistWhenExpiryDateIsPast() {
+        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_PLUS_4_SECONDS);
+
+        notificationRegistry().register(ACCOUNT_ID, recipientId(), Optional.of(ZONED_DATE_TIME)).block();
+
+        assertThat(notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block()).isFalse();
+    }
+
+    @Test
+    default void registerShouldNotPersistWhenExpiryDateIsPresent() {
+        when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME);
+
+        notificationRegistry().register(ACCOUNT_ID, recipientId(), Optional.of(ZONED_DATE_TIME)).block();
+
+        assertThat(notificationRegistry().isRegistered(ACCOUNT_ID, recipientId()).block()).isTrue();
+    }
+}
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryNotificationRegistryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryNotificationRegistryTest.java
index 1d6bbc6..ade6ff7 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryNotificationRegistryTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryNotificationRegistryTest.java
@@ -19,14 +19,29 @@
 
 package org.apache.james.jmap.memory.vacation;
 
-import org.apache.james.jmap.api.vacation.AbstractNotificationRegistryTest;
+import org.apache.james.core.MailAddress;
 import org.apache.james.jmap.api.vacation.NotificationRegistry;
-import org.apache.james.util.date.ZonedDateTimeProvider;
+import org.apache.james.jmap.api.vacation.NotificationRegistryContract;
+import org.apache.james.jmap.api.vacation.RecipientId;
+import org.junit.jupiter.api.BeforeEach;
 
-public class MemoryNotificationRegistryTest extends AbstractNotificationRegistryTest {
+class MemoryNotificationRegistryTest implements NotificationRegistryContract {
+    NotificationRegistry notificationRegistry;
+    RecipientId recipientId;
+
+    @BeforeEach
+    void setup() throws Exception {
+        notificationRegistry = new MemoryNotificationRegistry(zonedDateTimeProvider);
+        recipientId = RecipientId.fromMailAddress(new MailAddress("benwa@apache.org"));
+    }
+
+    @Override
+    public NotificationRegistry notificationRegistry() {
+        return notificationRegistry;
+    }
 
     @Override
-    protected NotificationRegistry createNotificationRegistry(ZonedDateTimeProvider zonedDateTimeProvider) {
-        return new MemoryNotificationRegistry(zonedDateTimeProvider);
+    public RecipientId recipientId() {
+        return recipientId;
     }
 }


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


[james-project] 12/26: [Refactoring] Migrate VacationPatchTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5f6e21ffbc62783595514d5862c10efe523065fa
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:28:07 2020 +0700

    [Refactoring] Migrate VacationPatchTest to JUnit5
---
 .../james/jmap/api/vacation/VacationPatchTest.java | 56 +++++++++++-----------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java
index 4006dee..7526e98 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java
@@ -26,14 +26,14 @@ import java.time.ZonedDateTime;
 import java.util.Optional;
 
 import org.apache.james.util.ValuePatch;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class VacationPatchTest {
+class VacationPatchTest {
 
-    public static final ZonedDateTime DATE_2014 = ZonedDateTime.parse("2014-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_2015 = ZonedDateTime.parse("2015-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_2017 = ZonedDateTime.parse("2017-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final Vacation VACATION = Vacation.builder()
+    static final ZonedDateTime DATE_2014 = ZonedDateTime.parse("2014-04-03T02:01+07:00[Asia/Vientiane]");
+    static final ZonedDateTime DATE_2015 = ZonedDateTime.parse("2015-04-03T02:01+07:00[Asia/Vientiane]");
+    static final ZonedDateTime DATE_2017 = ZonedDateTime.parse("2017-04-03T02:01+07:00[Asia/Vientiane]");
+    static final Vacation VACATION = Vacation.builder()
         .fromDate(Optional.of(DATE_2014))
         .toDate(Optional.of(DATE_2015))
         .enabled(true)
@@ -43,37 +43,37 @@ public class VacationPatchTest {
         .build();
 
     @Test
-    public void fromDateShouldThrowNPEOnNullInput() {
+    void fromDateShouldThrowNPEOnNullInput() {
         assertThatThrownBy(() -> VacationPatch.builder().fromDate((ValuePatch<ZonedDateTime>) null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void toDateShouldThrowNPEOnNullInput() {
+    void toDateShouldThrowNPEOnNullInput() {
         assertThatThrownBy(() -> VacationPatch.builder().toDate((ValuePatch<ZonedDateTime>) null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void textBodyShouldThrowNPEOnNullInput() {
+    void textBodyShouldThrowNPEOnNullInput() {
         assertThatThrownBy(() -> VacationPatch.builder().textBody((ValuePatch<String>) null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void htmlBodyShouldThrowNPEOnNullInput() {
+    void htmlBodyShouldThrowNPEOnNullInput() {
         assertThatThrownBy(() -> VacationPatch.builder().htmlBody((ValuePatch<String>) null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void subjectShouldThrowNPEOnNullInput() {
+    void subjectShouldThrowNPEOnNullInput() {
         assertThatThrownBy(() -> VacationPatch.builder().subject((ValuePatch<String>) null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void isEnabledShouldThrowNPEOnNullInput() {
+    void isEnabledShouldThrowNPEOnNullInput() {
         assertThatThrownBy(() -> VacationPatch.builder().isEnabled((ValuePatch<Boolean>) null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void isIdentityShouldBeTrueWhenUpdateIsEmpty() {
+    void isIdentityShouldBeTrueWhenUpdateIsEmpty() {
         assertThat(
             VacationPatch.builder()
                 .build()
@@ -82,7 +82,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void isIdentityShouldBeFalseWhenUpdateIsNotEmpty() {
+    void isIdentityShouldBeFalseWhenUpdateIsNotEmpty() {
         assertThat(
             VacationPatch.builder()
                 .subject(ValuePatch.modifyTo("any subject"))
@@ -92,7 +92,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void builderShouldWellSetFields() {
+    void builderShouldWellSetFields() {
         ValuePatch<String> subject = ValuePatch.modifyTo("subject");
         ValuePatch<String> htmlBody = ValuePatch.modifyTo("html text");
         ValuePatch<String> textBody = ValuePatch.modifyTo("simple text");
@@ -116,7 +116,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldUpdateEnabled() {
+    void patchVacationShouldUpdateEnabled() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .isEnabled(ValuePatch.modifyTo(true))
             .build();
@@ -128,7 +128,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldUpdateFromDate() {
+    void patchVacationShouldUpdateFromDate() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .fromDate(ValuePatch.modifyTo(DATE_2014))
             .build();
@@ -141,7 +141,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldUpdateToDate() {
+    void patchVacationShouldUpdateToDate() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .toDate(ValuePatch.modifyTo(DATE_2017))
             .build();
@@ -154,7 +154,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldUpdateSubject() {
+    void patchVacationShouldUpdateSubject() {
         String newSubject = "new subject";
         VacationPatch vacationPatch = VacationPatch.builder()
             .subject(ValuePatch.modifyTo(newSubject))
@@ -168,7 +168,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldUpdateTextBody() {
+    void patchVacationShouldUpdateTextBody() {
         String newTextBody = "new text body";
         VacationPatch vacationPatch = VacationPatch.builder()
             .textBody(ValuePatch.modifyTo(newTextBody))
@@ -182,7 +182,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldUpdateHtmlBody() {
+    void patchVacationShouldUpdateHtmlBody() {
         String newHtmlBody = "new <b>html</b> body";
         VacationPatch vacationPatch = VacationPatch.builder()
             .htmlBody(ValuePatch.modifyTo(newHtmlBody))
@@ -196,7 +196,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void patchVacationShouldAllowToUpdateAllFieldsAtOnce() {
+    void patchVacationShouldAllowToUpdateAllFieldsAtOnce() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .subject(ValuePatch.ofOptional(VACATION.getSubject()))
             .textBody(ValuePatch.ofOptional(VACATION.getTextBody()))
@@ -211,7 +211,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void emptyPatchesShouldNotChangeExistingVacations() {
+    void emptyPatchesShouldNotChangeExistingVacations() {
         assertThat(VacationPatch.builder()
             .build()
             .patch(VACATION))
@@ -219,7 +219,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void nullUpdateShouldResetSubject() {
+    void nullUpdateShouldResetSubject() {
         Vacation vacation = VacationPatch.builderFrom(VACATION)
             .subject(ValuePatch.remove())
             .build()
@@ -237,7 +237,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void nullUpdateShouldResetText() {
+    void nullUpdateShouldResetText() {
         Vacation vacation = VacationPatch.builderFrom(VACATION)
             .textBody(ValuePatch.remove())
             .build()
@@ -255,7 +255,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void nullUpdateShouldResetHtml() {
+    void nullUpdateShouldResetHtml() {
         Vacation vacation = VacationPatch.builderFrom(VACATION)
             .htmlBody(ValuePatch.remove())
             .build()
@@ -273,7 +273,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void nullUpdateShouldResetToDate() {
+    void nullUpdateShouldResetToDate() {
         Vacation vacation = VacationPatch.builderFrom(VACATION)
             .toDate(ValuePatch.remove())
             .build()
@@ -291,7 +291,7 @@ public class VacationPatchTest {
     }
 
     @Test
-    public void nullUpdateShouldResetFromDate() {
+    void nullUpdateShouldResetFromDate() {
         Vacation vacation = VacationPatch.builderFrom(VACATION)
             .fromDate(ValuePatch.remove())
             .build()


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


[james-project] 22/26: [Refactoring] Migrate AbstractVacationRepositoryTest to VacationRepositoryContract JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0b85634d2f0e1092bdacecc8bc36900ac9e145c7
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 16:13:45 2020 +0700

    [Refactoring] Migrate AbstractVacationRepositoryTest to VacationRepositoryContract JUnit5
---
 .../vacation/CassandraVacationRepositoryTest.java  |  44 +++---
 ...ryTest.java => VacationRepositoryContract.java} | 148 ++++++++++-----------
 .../vacation/MemoryVacationRepositoryTest.java     |  15 ++-
 3 files changed, 100 insertions(+), 107 deletions(-)

diff --git a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationRepositoryTest.java b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationRepositoryTest.java
index c45e956..e0c9e40 100644
--- a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationRepositoryTest.java
+++ b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationRepositoryTest.java
@@ -20,43 +20,33 @@
 package org.apache.james.jmap.cassandra.vacation;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.init.CassandraZonedDateTimeModule;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
-import org.apache.james.jmap.api.vacation.AbstractVacationRepositoryTest;
 import org.apache.james.jmap.api.vacation.VacationRepository;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.jmap.api.vacation.VacationRepositoryContract;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraVacationRepositoryTest extends AbstractVacationRepositoryTest {
+class CassandraVacationRepositoryTest implements VacationRepositoryContract {
+    static final CassandraModule MODULE = CassandraModule.aggregateModules(
+        CassandraSchemaVersionModule.MODULE,
+        CassandraVacationModule.MODULE,
+        CassandraZonedDateTimeModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule();
-    
-    private CassandraCluster cassandra;
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MODULE);
 
+    VacationRepository vacationRepository;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        CassandraModule module = CassandraModule.aggregateModules(
-            CassandraSchemaVersionModule.MODULE,
-            CassandraVacationModule.MODULE,
-            CassandraZonedDateTimeModule.MODULE);
-        cassandra = CassandraCluster.create(module, cassandraServer.getHost());
-        super.setUp();
-    }
-
-    @After
-    public void tearDown() {
-        cassandra.close();
+    @BeforeEach
+    public void setUp(CassandraCluster cassandra) throws Exception {
+        vacationRepository = new CassandraVacationRepository(new CassandraVacationDAO(cassandra.getConf(), cassandra.getTypesProvider()));
     }
 
     @Override
-    protected VacationRepository createVacationRepository() {
-        return new CassandraVacationRepository(new CassandraVacationDAO(cassandra.getConf(), cassandra.getTypesProvider()));
+    public VacationRepository vacationRepository() {
+        return vacationRepository;
     }
-
 }
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationRepositoryContract.java
similarity index 59%
rename from server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
rename to server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationRepositoryContract.java
index 133143e..436e13a 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationRepositoryContract.java
@@ -20,22 +20,22 @@
 package org.apache.james.jmap.api.vacation;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.time.ZonedDateTime;
 import java.util.Optional;
 
 import org.apache.james.util.ValuePatch;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public abstract class AbstractVacationRepositoryTest {
+public interface VacationRepositoryContract {
 
-    public static final AccountId ACCOUNT_ID = AccountId.fromString("identifier");
-    public static final ZonedDateTime DATE_2014 = ZonedDateTime.parse("2014-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_2015 = ZonedDateTime.parse("2015-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_2016 = ZonedDateTime.parse("2016-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_2017 = ZonedDateTime.parse("2017-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final Vacation VACATION = Vacation.builder()
+    AccountId ACCOUNT_ID = AccountId.fromString("identifier");
+    ZonedDateTime DATE_2014 = ZonedDateTime.parse("2014-04-03T02:01+07:00[Asia/Vientiane]");
+    ZonedDateTime DATE_2015 = ZonedDateTime.parse("2015-04-03T02:01+07:00[Asia/Vientiane]");
+    ZonedDateTime DATE_2016 = ZonedDateTime.parse("2016-04-03T02:01+07:00[Asia/Vientiane]");
+    ZonedDateTime DATE_2017 = ZonedDateTime.parse("2017-04-03T02:01+07:00[Asia/Vientiane]");
+    Vacation VACATION = Vacation.builder()
         .fromDate(Optional.of(DATE_2015))
         .toDate(Optional.of(DATE_2016))
         .enabled(true)
@@ -45,43 +45,36 @@ public abstract class AbstractVacationRepositoryTest {
         .build();
 
 
-    private VacationRepository vacationRepository;
-
-    protected abstract VacationRepository createVacationRepository();
-
-    @Before
-    public void setUp() throws Exception {
-        vacationRepository = createVacationRepository();
-    }
+    VacationRepository vacationRepository();
 
     @Test
-    public void retrieveVacationShouldReturnDefaultValueByDefault() {
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block()).isEqualTo(VacationRepository.DEFAULT_VACATION);
+    default void retrieveVacationShouldReturnDefaultValueByDefault() {
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block()).isEqualTo(VacationRepository.DEFAULT_VACATION);
     }
 
     @Test
-    public void modifyVacationShouldUpdateEnabled() {
+    default void modifyVacationShouldUpdateEnabled() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .isEnabled(true)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(Vacation.builder()
                 .enabled(true)
                 .build());
     }
 
     @Test
-    public void modifyVacationShouldUpdateFromDate() {
+    default void modifyVacationShouldUpdateFromDate() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .fromDate(DATE_2014)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(Vacation.builder()
                 .fromDate(Optional.of(DATE_2014))
                 .enabled(false)
@@ -89,14 +82,14 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void modifyVacationShouldUpdateToDate() {
+    default void modifyVacationShouldUpdateToDate() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .toDate(DATE_2017)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(Vacation.builder()
                 .toDate(Optional.of(DATE_2017))
                 .enabled(false)
@@ -104,15 +97,15 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void modifyVacationShouldUpdateSubject() {
+    default void modifyVacationShouldUpdateSubject() {
         String newSubject = "new subject";
         VacationPatch vacationPatch = VacationPatch.builder()
             .subject(newSubject)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(Vacation.builder()
                 .subject(Optional.of(newSubject))
                 .enabled(false)
@@ -120,15 +113,15 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void modifyVacationShouldUpdateTextBody() {
+    default void modifyVacationShouldUpdateTextBody() {
         String newTextBody = "new text body";
         VacationPatch vacationPatch = VacationPatch.builder()
             .textBody(newTextBody)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(Vacation.builder()
                 .textBody(newTextBody)
                 .enabled(false)
@@ -136,15 +129,15 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void modifyVacationShouldUpdateHtmlBody() {
+    default void modifyVacationShouldUpdateHtmlBody() {
         String newHtmlBody = "new <b>html</b> body";
         VacationPatch vacationPatch = VacationPatch.builder()
             .htmlBody(newHtmlBody)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(Vacation.builder()
                 .enabled(false)
                 .htmlBody(newHtmlBody)
@@ -152,61 +145,61 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void modifyVacationShouldAllowToUpdateAllFieldsAtOnce() {
+    default void modifyVacationShouldAllowToUpdateAllFieldsAtOnce() {
         VacationPatch vacationPatch = VacationPatch.builderFrom(VACATION)
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(VACATION);
     }
 
     @Test
-    public void modifyVacationShouldAllowEmptyUpdates() {
+    default void modifyVacationShouldAllowEmptyUpdates() {
         VacationPatch vacationPatch = VacationPatch.builder()
             .build();
 
-        vacationRepository.modifyVacation(ACCOUNT_ID, vacationPatch).block();
+        vacationRepository().modifyVacation(ACCOUNT_ID, vacationPatch).block();
 
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(VacationRepository.DEFAULT_VACATION);
     }
 
     @Test
-    public void emptyUpdatesShouldNotChangeExistingVacations() {
+    default void emptyUpdatesShouldNotChangeExistingVacations() {
         // Given
-        vacationRepository.modifyVacation(ACCOUNT_ID,
+        vacationRepository().modifyVacation(ACCOUNT_ID,
             VacationPatch.builderFrom(VACATION)
                 .build())
             .block();
 
         // When
-        vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder()
+        vacationRepository().modifyVacation(ACCOUNT_ID, VacationPatch.builder()
             .build())
             .block();
 
         // Then
-        assertThat(vacationRepository.retrieveVacation(ACCOUNT_ID).block())
+        assertThat(vacationRepository().retrieveVacation(ACCOUNT_ID).block())
             .isEqualTo(VACATION);
     }
 
     @Test
-    public void nullUpdateShouldResetSubject() {
+    default void nullUpdateShouldResetSubject() {
         // Given
-        vacationRepository.modifyVacation(ACCOUNT_ID,
+        vacationRepository().modifyVacation(ACCOUNT_ID,
             VacationPatch.builderFrom(VACATION)
                 .build())
             .block();
 
         // When
-        vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder()
+        vacationRepository().modifyVacation(ACCOUNT_ID, VacationPatch.builder()
             .subject(ValuePatch.remove())
             .build())
             .block();
 
         // Then
-        Vacation vacation = vacationRepository.retrieveVacation(ACCOUNT_ID).block();
+        Vacation vacation = vacationRepository().retrieveVacation(ACCOUNT_ID).block();
         assertThat(vacation.getSubject()).isEmpty();
         assertThat(vacation)
             .isEqualTo(Vacation.builder()
@@ -219,21 +212,21 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void nullUpdateShouldResetText() {
+    default void nullUpdateShouldResetText() {
         // Given
-        vacationRepository.modifyVacation(ACCOUNT_ID,
+        vacationRepository().modifyVacation(ACCOUNT_ID,
             VacationPatch.builderFrom(VACATION)
                 .build())
             .block();
 
         // When
-        vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder()
+        vacationRepository().modifyVacation(ACCOUNT_ID, VacationPatch.builder()
             .textBody(ValuePatch.remove())
             .build())
             .block();
 
         // Then
-        Vacation vacation = vacationRepository.retrieveVacation(ACCOUNT_ID).block();
+        Vacation vacation = vacationRepository().retrieveVacation(ACCOUNT_ID).block();
         assertThat(vacation.getTextBody()).isEmpty();
         assertThat(vacation)
             .isEqualTo(Vacation.builder()
@@ -246,21 +239,21 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void nullUpdateShouldResetHtml() {
+    default void nullUpdateShouldResetHtml() {
         // Given
-        vacationRepository.modifyVacation(ACCOUNT_ID,
+        vacationRepository().modifyVacation(ACCOUNT_ID,
             VacationPatch.builderFrom(VACATION)
                 .build())
             .block();
 
         // When
-        vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder()
+        vacationRepository().modifyVacation(ACCOUNT_ID, VacationPatch.builder()
             .htmlBody(ValuePatch.remove())
             .build())
             .block();
 
         // Then
-        Vacation vacation = vacationRepository.retrieveVacation(ACCOUNT_ID).block();
+        Vacation vacation = vacationRepository().retrieveVacation(ACCOUNT_ID).block();
         assertThat(vacation.getHtmlBody()).isEmpty();
         assertThat(vacation)
             .isEqualTo(Vacation.builder()
@@ -273,21 +266,21 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void nullUpdateShouldResetToDate() {
+    default void nullUpdateShouldResetToDate() {
         // Given
-        vacationRepository.modifyVacation(ACCOUNT_ID,
+        vacationRepository().modifyVacation(ACCOUNT_ID,
             VacationPatch.builderFrom(VACATION)
                 .build())
             .block();
 
         // When
-        vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder()
+        vacationRepository().modifyVacation(ACCOUNT_ID, VacationPatch.builder()
             .toDate(ValuePatch.remove())
             .build())
             .block();
 
         // Then
-        Vacation vacation = vacationRepository.retrieveVacation(ACCOUNT_ID).block();
+        Vacation vacation = vacationRepository().retrieveVacation(ACCOUNT_ID).block();
         assertThat(vacation.getToDate()).isEmpty();
         assertThat(vacation)
             .isEqualTo(Vacation.builder()
@@ -300,21 +293,21 @@ public abstract class AbstractVacationRepositoryTest {
     }
 
     @Test
-    public void nullUpdateShouldResetFromDate() {
+    default void nullUpdateShouldResetFromDate() {
         // Given
-        vacationRepository.modifyVacation(ACCOUNT_ID,
+        vacationRepository().modifyVacation(ACCOUNT_ID,
             VacationPatch.builderFrom(VACATION)
                 .build())
             .block();
 
         // When
-        vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder()
+        vacationRepository().modifyVacation(ACCOUNT_ID, VacationPatch.builder()
             .fromDate(ValuePatch.remove())
             .build())
             .block();
 
         // Then
-        Vacation vacation = vacationRepository.retrieveVacation(ACCOUNT_ID).block();
+        Vacation vacation = vacationRepository().retrieveVacation(ACCOUNT_ID).block();
         assertThat(vacation.getFromDate()).isEmpty();
         assertThat(vacation)
             .isEqualTo(Vacation.builder()
@@ -326,19 +319,22 @@ public abstract class AbstractVacationRepositoryTest {
                 .build());
     }
 
-    @Test(expected = NullPointerException.class)
-    public void retrieveVacationShouldThrowOnNullAccountId() {
-        vacationRepository.retrieveVacation(null);
+    @Test
+    default void retrieveVacationShouldThrowOnNullAccountId() {
+        assertThatThrownBy(() -> vacationRepository().retrieveVacation(null))
+            .isInstanceOf(NullPointerException.class);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void modifyVacationShouldThrowOnNullAccountId() {
-        vacationRepository.modifyVacation(null, VacationPatch.builder().build());
+    @Test
+    default void modifyVacationShouldThrowOnNullAccountId() {
+        assertThatThrownBy(() -> vacationRepository().modifyVacation(null, VacationPatch.builder().build()))
+            .isInstanceOf(NullPointerException.class);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void modifyVacationShouldThrowOnNullVacation() {
-        vacationRepository.modifyVacation(ACCOUNT_ID, null);
+    @Test
+    default void modifyVacationShouldThrowOnNullVacation() {
+        assertThatThrownBy(() -> vacationRepository().modifyVacation(ACCOUNT_ID, null))
+            .isInstanceOf(NullPointerException.class);
     }
 
 }
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryVacationRepositoryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryVacationRepositoryTest.java
index 0ec2d99..4fbb273 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryVacationRepositoryTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/vacation/MemoryVacationRepositoryTest.java
@@ -19,13 +19,20 @@
 
 package org.apache.james.jmap.memory.vacation;
 
-import org.apache.james.jmap.api.vacation.AbstractVacationRepositoryTest;
 import org.apache.james.jmap.api.vacation.VacationRepository;
+import org.apache.james.jmap.api.vacation.VacationRepositoryContract;
+import org.junit.jupiter.api.BeforeEach;
 
-public class MemoryVacationRepositoryTest extends AbstractVacationRepositoryTest {
+class MemoryVacationRepositoryTest implements VacationRepositoryContract {
+    VacationRepository vacationRepository;
+
+    @BeforeEach
+    void setup() {
+        vacationRepository = new MemoryVacationRepository();
+    }
 
     @Override
-    protected VacationRepository createVacationRepository() {
-        return new MemoryVacationRepository();
+    public VacationRepository vacationRepository() {
+        return vacationRepository;
     }
 }


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


[james-project] 08/26: [Refactoring] Migrate AbstractRecipientRewriteTableTest to RecipientRewriteTableContract in JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8b3a128a8525282390dbfafdeed8cba66ec2ea6c
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 14:50:40 2020 +0700

    [Refactoring] Migrate AbstractRecipientRewriteTableTest to RecipientRewriteTableContract in JUnit5
---
 .../CassandraRecipientRewriteTableV6Test.java      |  62 +-
 ...ndraRecipientRewriteTableV7BeforeStartTest.java |  63 +-
 .../CassandraRecipientRewriteTableV7Test.java      |  64 +-
 .../rrt/file/XMLRecipientRewriteTableTest.java     | 109 ++--
 .../rrt/jpa/JPARecipientRewriteTableTest.java      |  35 +-
 .../rrt/lib/AbstractRecipientRewriteTableTest.java | 643 ---------------------
 .../rrt/lib/RecipientRewriteTableContract.java     | 636 ++++++++++++++++++++
 .../memory/MemoryRecipientRewriteTableTest.java    |  31 +-
 8 files changed, 831 insertions(+), 812 deletions(-)

diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV6Test.java b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV6Test.java
index 525eacb..8ef69ef 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV6Test.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV6Test.java
@@ -20,7 +20,7 @@
 package org.apache.james.rrt.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
@@ -28,46 +28,50 @@ import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManage
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
 import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.rrt.lib.RecipientRewriteTableContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraRecipientRewriteTableV6Test extends AbstractRecipientRewriteTableTest {
-    private static final SchemaVersion SCHEMA_VERSION_V6 = new SchemaVersion(6);
+class CassandraRecipientRewriteTableV6Test implements RecipientRewriteTableContract {
+    static final SchemaVersion SCHEMA_VERSION_V6 = new SchemaVersion(6);
 
-    private static final CassandraModule MODULE = CassandraModule.aggregateModules(
+    static final CassandraModule MODULE = CassandraModule.aggregateModules(
         CassandraRRTModule.MODULE,
         CassandraSchemaVersionModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart();
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MODULE);
 
-    protected CassandraCluster cassandra;
+    AbstractRecipientRewriteTable recipientRewriteTable;
+    CassandraRecipientRewriteTableDAO recipientRewriteTableDAO;
+    CassandraMappingsSourcesDAO mappingsSourcesDAO;
+    CassandraSchemaVersionManager schemaVersionManager;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(MODULE, cassandraServer.getHost());
-        super.setUp();
+    @BeforeEach
+    void setup(CassandraCluster cassandra) throws Exception {
+        CassandraSchemaVersionDAO cassandraSchemaVersionDAO = new CassandraSchemaVersionDAO(cassandra.getConf());
+        cassandraSchemaVersionDAO.updateVersion(SCHEMA_VERSION_V6).block();
+
+        recipientRewriteTableDAO = new CassandraRecipientRewriteTableDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
+        mappingsSourcesDAO = new CassandraMappingsSourcesDAO(cassandra.getConf());
+        schemaVersionManager = new CassandraSchemaVersionManager(cassandraSchemaVersionDAO);
+
+        setUp();
     }
 
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-        cassandra.close();
+    @AfterEach
+    void teardown() throws Exception {
+        tearDown();
     }
 
     @Override
-    protected AbstractRecipientRewriteTable getRecipientRewriteTable() {
-        CassandraSchemaVersionDAO cassandraSchemaVersionDAO = new CassandraSchemaVersionDAO(
-            cassandra.getConf());
-        cassandraSchemaVersionDAO.updateVersion(SCHEMA_VERSION_V6).block();
+    public void createRecipientRewriteTable() {
+        recipientRewriteTable = new CassandraRecipientRewriteTable(recipientRewriteTableDAO, mappingsSourcesDAO, schemaVersionManager);
+    }
 
-        return new CassandraRecipientRewriteTable(
-            new CassandraRecipientRewriteTableDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION),
-            new CassandraMappingsSourcesDAO(cassandra.getConf()),
-            new CassandraSchemaVersionManager(cassandraSchemaVersionDAO));
+    @Override
+    public AbstractRecipientRewriteTable virtualUserTable() {
+        return recipientRewriteTable;
     }
 }
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7BeforeStartTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7BeforeStartTest.java
index 8510f4e..91d48a9 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7BeforeStartTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7BeforeStartTest.java
@@ -20,7 +20,7 @@
 package org.apache.james.rrt.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
@@ -28,47 +28,50 @@ import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManage
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
 import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.rrt.lib.RecipientRewriteTableContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraRecipientRewriteTableV7BeforeStartTest extends AbstractRecipientRewriteTableTest {
-    private static final SchemaVersion SCHEMA_VERSION_V7 = new SchemaVersion(7);
+class CassandraRecipientRewriteTableV7BeforeStartTest implements RecipientRewriteTableContract {
+    static final SchemaVersion SCHEMA_VERSION_V7 = new SchemaVersion(7);
 
-    private static final CassandraModule MODULE = CassandraModule.aggregateModules(
+    static final CassandraModule MODULE = CassandraModule.aggregateModules(
         CassandraRRTModule.MODULE,
         CassandraSchemaVersionModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart();
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MODULE);
 
-    protected CassandraCluster cassandra;
+    AbstractRecipientRewriteTable recipientRewriteTable;
+    CassandraRecipientRewriteTableDAO recipientRewriteTableDAO;
+    CassandraMappingsSourcesDAO mappingsSourcesDAO;
+    CassandraSchemaVersionManager schemaVersionManager;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(MODULE, cassandraServer.getHost());
-        super.setUp();
+    @BeforeEach
+    void setup(CassandraCluster cassandra) throws Exception {
+        CassandraSchemaVersionDAO cassandraSchemaVersionDAO = new CassandraSchemaVersionDAO(cassandra.getConf());
+        cassandraSchemaVersionDAO.updateVersion(SCHEMA_VERSION_V7).block();
+
+        recipientRewriteTableDAO = new CassandraRecipientRewriteTableDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
+        mappingsSourcesDAO = new CassandraMappingsSourcesDAO(cassandra.getConf());
+        schemaVersionManager = new CassandraSchemaVersionManager(cassandraSchemaVersionDAO);
+
+        setUp();
     }
 
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-        cassandra.close();
+    @AfterEach
+    void teardown() throws Exception {
+        tearDown();
     }
 
     @Override
-    protected AbstractRecipientRewriteTable getRecipientRewriteTable() {
-        CassandraSchemaVersionDAO cassandraSchemaVersionDAO = new CassandraSchemaVersionDAO(
-            cassandra.getConf());
-
-        cassandraSchemaVersionDAO.updateVersion(SCHEMA_VERSION_V7).block();
+    public void createRecipientRewriteTable() {
+        recipientRewriteTable = new CassandraRecipientRewriteTable(recipientRewriteTableDAO, mappingsSourcesDAO, schemaVersionManager);
+    }
 
-        return new CassandraRecipientRewriteTable(
-            new CassandraRecipientRewriteTableDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION),
-            new CassandraMappingsSourcesDAO(cassandra.getConf()),
-            new CassandraSchemaVersionManager(cassandraSchemaVersionDAO));
+    @Override
+    public AbstractRecipientRewriteTable virtualUserTable() {
+        return recipientRewriteTable;
     }
 }
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7Test.java b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7Test.java
index 35246b9..1340785 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7Test.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableV7Test.java
@@ -20,7 +20,7 @@
 package org.apache.james.rrt.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
@@ -28,49 +28,53 @@ import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManage
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
 import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
+import org.apache.james.rrt.lib.RecipientRewriteTableContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraRecipientRewriteTableV7Test extends AbstractRecipientRewriteTableTest {
-    private static final SchemaVersion SCHEMA_VERSION_V7 = new SchemaVersion(7);
+class CassandraRecipientRewriteTableV7Test implements RecipientRewriteTableContract {
+    static final SchemaVersion SCHEMA_VERSION_V7 = new SchemaVersion(7);
 
-    private static final CassandraModule MODULE = CassandraModule.aggregateModules(
+    static final CassandraModule MODULE = CassandraModule.aggregateModules(
         CassandraRRTModule.MODULE,
         CassandraSchemaVersionModule.MODULE);
 
-    @Rule
-    public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart();
+    @RegisterExtension
+    static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MODULE);
 
-    protected CassandraCluster cassandra;
+    AbstractRecipientRewriteTable recipientRewriteTable;
+    CassandraRecipientRewriteTableDAO recipientRewriteTableDAO;
+    CassandraMappingsSourcesDAO mappingsSourcesDAO;
+    CassandraSchemaVersionManager schemaVersionManager;
+    CassandraSchemaVersionDAO cassandraSchemaVersionDAO;
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        cassandra = CassandraCluster.create(MODULE, cassandraServer.getHost());
-        super.setUp();
+    @BeforeEach
+    void setup(CassandraCluster cassandra) throws Exception {
+        cassandraSchemaVersionDAO = new CassandraSchemaVersionDAO(cassandra.getConf());
+        recipientRewriteTableDAO = new CassandraRecipientRewriteTableDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
+        mappingsSourcesDAO = new CassandraMappingsSourcesDAO(cassandra.getConf());
+        schemaVersionManager = new CassandraSchemaVersionManager(cassandraSchemaVersionDAO);
+
+        setUp();
     }
 
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-        cassandra.close();
+    @AfterEach
+    void teardown() throws Exception {
+        tearDown();
     }
 
     @Override
-    protected AbstractRecipientRewriteTable getRecipientRewriteTable() {
-        CassandraSchemaVersionDAO cassandraSchemaVersionDAO = new CassandraSchemaVersionDAO(
-            cassandra.getConf());
-
-        CassandraRecipientRewriteTable rrt = new CassandraRecipientRewriteTable(
-            new CassandraRecipientRewriteTableDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION),
-            new CassandraMappingsSourcesDAO(cassandra.getConf()),
-            new CassandraSchemaVersionManager(cassandraSchemaVersionDAO));
+    public void createRecipientRewriteTable() {
+        CassandraRecipientRewriteTable rrt = new CassandraRecipientRewriteTable(recipientRewriteTableDAO, mappingsSourcesDAO, schemaVersionManager);
 
         cassandraSchemaVersionDAO.updateVersion(SCHEMA_VERSION_V7).block();
 
-        return rrt;
+        recipientRewriteTable = rrt;
+    }
+
+    @Override
+    public AbstractRecipientRewriteTable virtualUserTable() {
+        return recipientRewriteTable;
     }
 }
diff --git a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
index 7ef0a37..d3bd13a 100644
--- a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
@@ -21,222 +21,227 @@ package org.apache.james.rrt.file;
 import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
 import org.apache.commons.configuration2.convert.DisabledListDelimiterHandler;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.apache.james.rrt.lib.RecipientRewriteTableContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
-public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableTest {
+class XMLRecipientRewriteTableTest implements RecipientRewriteTableContract {
 
-    private final BaseHierarchicalConfiguration defaultConfiguration = new BaseHierarchicalConfiguration();
+    final BaseHierarchicalConfiguration defaultConfiguration = new BaseHierarchicalConfiguration();
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
+    AbstractRecipientRewriteTable recipientRewriteTable;
+
+    @BeforeEach
+    void setup() throws Exception {
         defaultConfiguration.setListDelimiterHandler(new DisabledListDelimiterHandler());
-        super.setUp();
+        setUp();
+    }
+
+    @AfterEach
+    void teardown() throws Exception {
+        tearDown();
     }
 
     @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
+    public void createRecipientRewriteTable() {
+        recipientRewriteTable = new XMLRecipientRewriteTable();
     }
 
     @Override
-    protected AbstractRecipientRewriteTable getRecipientRewriteTable() {
-        return new XMLRecipientRewriteTable();
+    public AbstractRecipientRewriteTable virtualUserTable() {
+        return recipientRewriteTable;
     }
 
     @Test
-    @Ignore("addMapping doesn't handle checking for domain existence in this test implementation")
+    @Disabled("addMapping doesn't handle checking for domain existence in this test implementation")
     @Override
     public void addAddressMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
     }
 
     @Test
-    @Ignore("addMapping doesn't handle checking for duplicate in this test implementation")
+    @Disabled("addMapping doesn't handle checking for duplicate in this test implementation")
     @Override
     public void addMappingShouldThrowWhenMappingAlreadyExists() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testStoreAndGetMappings() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testStoreAndRetrieveRegexMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getAllMappingsShouldListAllEntries() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testStoreAndRetrieveAddressMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testStoreAndRetrieveErrorMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testStoreAndRetrieveWildCardAddressMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testNonRecursiveMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void testAliasDomainMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void addMappingShouldNotThrowWhenMappingAlreadyExistsWithAnOtherType() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void addForwardMappingShouldStore() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void removeForwardMappingShouldDelete() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void addGroupMappingShouldStore() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void removeGroupMappingShouldDelete() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void addAliasMappingShouldStore() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void removeAliasMappingShouldDelete() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldReturnWhenHasMapping() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldReturnWhenMultipleSourceMapping() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldReturnWhenHasForwardMapping() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldReturnAliasMappings() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldReturnWhenHasAddressMapping() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldThrowExceptionWhenHasRegexMapping() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldHandleDomainMapping() {
 
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldHandleDomainSource() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldHandleDomainSources() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldThrowExceptionWhenHasErrorMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void listSourcesShouldReturnEmptyWhenMappingDoesNotExist() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getSourcesForTypeShouldReturnEmptyWhenNoMatchingMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getSourcesForTypeShouldReturnMatchingMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getSourcesForTypeShouldNotReturnDuplicatedSources() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getSourcesForTypeShouldReturnSortedStream() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getMappingsForTypeShouldReturnEmptyWhenNoMatchingMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getMappingsForTypeShouldReturnMatchingMapping() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getMappingsForTypeShouldNotReturnDuplicatedDestinations() {
     }
 
     @Test
-    @Ignore("XMLRecipientRewriteTable is read only")
+    @Disabled("XMLRecipientRewriteTable is read only")
     public void getMappingsForTypeShouldReturnSortedStream() {
     }
 }
diff --git a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java
index 7a54550..777ebf7 100644
--- a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java
+++ b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java
@@ -21,30 +21,35 @@ package org.apache.james.rrt.jpa;
 import org.apache.james.backends.jpa.JpaTestCluster;
 import org.apache.james.rrt.jpa.model.JPARecipientRewrite;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.james.rrt.lib.RecipientRewriteTableContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class JPARecipientRewriteTableTest extends AbstractRecipientRewriteTableTest {
+class JPARecipientRewriteTableTest implements RecipientRewriteTableContract {
 
-    private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPARecipientRewrite.class);
+    static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPARecipientRewrite.class);
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
+    AbstractRecipientRewriteTable recipientRewriteTable;
+
+    @BeforeEach
+    void setup() throws Exception {
+        setUp();
     }
 
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
+    @AfterEach
+    void teardown() throws Exception {
+        tearDown();
     }
 
     @Override
-    protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception {
+    public void createRecipientRewriteTable() {
         JPARecipientRewriteTable localVirtualUserTable = new JPARecipientRewriteTable();
         localVirtualUserTable.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory());
-        return localVirtualUserTable;
+        recipientRewriteTable = localVirtualUserTable;
+    }
+
+    @Override
+    public AbstractRecipientRewriteTable virtualUserTable() {
+        return recipientRewriteTable;
     }
 }
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
deleted file mode 100644
index c837815..0000000
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
+++ /dev/null
@@ -1,643 +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.rrt.lib;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.Map;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.james.core.Domain;
-import org.apache.james.domainlist.api.mock.SimpleDomainList;
-import org.apache.james.lifecycle.api.LifecycleUtil;
-import org.apache.james.rrt.api.RecipientRewriteTable.ErrorMappingException;
-import org.apache.james.rrt.api.RecipientRewriteTableConfiguration;
-import org.apache.james.rrt.api.RecipientRewriteTableException;
-import org.apache.james.rrt.api.SourceDomainIsNotInDomainListException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import com.github.fge.lambdas.Throwing;
-
-/**
- * The abstract test for the virtual user table. Contains tests related to
- * simple, regexp, wildcard, error,... Extend this and instantiate the needed
- * virtualUserTable implementation.
- */
-public abstract class AbstractRecipientRewriteTableTest {
-
-    private static final String USER = "test";
-    private static final String ADDRESS = "test@localhost2";
-    private static final String ADDRESS_2 = "test@james";
-    private static final Domain SUPPORTED_DOMAIN = Domain.LOCALHOST;
-    private static final MappingSource SOURCE = MappingSource.fromUser(USER, SUPPORTED_DOMAIN);
-    private static final Domain NOT_SUPPORTED_DOMAIN = Domain.of("notAManagedDomain");
-    private static final MappingSource SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST = MappingSource.fromUser(USER, NOT_SUPPORTED_DOMAIN);
-
-    protected abstract AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception;
-
-    @Rule public ExpectedException expectedException = ExpectedException.none();
-
-    protected AbstractRecipientRewriteTable virtualUserTable;
-
-    public void setUp() throws Exception {
-        setRecursiveRecipientRewriteTable();
-    }
-
-    private void setRecursiveRecipientRewriteTable() throws Exception {
-        setNotConfiguredRecipientRewriteTable();
-        virtualUserTable.setConfiguration(new RecipientRewriteTableConfiguration(true, 10));
-    }
-
-    private void setNonRecursiveRecipientRewriteTable() throws Exception {
-        setNotConfiguredRecipientRewriteTable();
-        virtualUserTable.setConfiguration(new RecipientRewriteTableConfiguration(false, 0));
-    }
-
-    private void setNotConfiguredRecipientRewriteTable() throws Exception {
-        virtualUserTable = getRecipientRewriteTable();
-
-        SimpleDomainList domainList = new SimpleDomainList();
-        domainList.addDomain(SUPPORTED_DOMAIN);
-        virtualUserTable.setDomainList(domainList);
-    }
-
-    public void tearDown() throws Exception {
-        Map<MappingSource, Mappings> mappings = virtualUserTable.getAllMappings();
-
-        if (mappings != null) {
-            for (MappingSource key : virtualUserTable.getAllMappings().keySet()) {
-                Mappings map = mappings.get(key);
-
-                map.asStream()
-                    .forEach(Throwing.consumer(mapping ->
-                        virtualUserTable.removeMapping(key, mapping)));
-            }
-        }
-
-        LifecycleUtil.dispose(virtualUserTable);
-    }
-
-    @Test
-    public void testStoreAndGetMappings() throws Exception {
-        Domain domain = Domain.of("test");
-        virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.regex("prefix_.*:admin@test"));
-        assertThat(virtualUserTable.getResolvedMappings("prefix_abc", domain)).isNotEmpty();
-    }
-
-    @Test
-    public void notConfiguredResolutionShouldThrow() throws Exception {
-        setNotConfiguredRecipientRewriteTable();
-        assertThatCode(() -> virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST))
-            .isInstanceOf(IllegalStateException.class);
-    }
-
-    @Test
-    public void configuringTwiceShouldThrow() {
-        assertThatCode(() -> virtualUserTable.setConfiguration(new RecipientRewriteTableConfiguration(true, 10)))
-            .isInstanceOf(IllegalStateException.class);
-    }
-
-    @Test
-    public void testStoreAndRetrieveRegexMapping() throws Exception {
-        String regex = "(.*)@localhost";
-        String regex2 = "(.+)@test";
-        String invalidRegex = ".*):";
-
-        Mapping mappingRegex = Mapping.regex(regex);
-        Mapping mappingRegex2 = Mapping.regex(regex2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
-
-        virtualUserTable.addMapping(SOURCE, mappingRegex);
-        virtualUserTable.addMapping(SOURCE, mappingRegex2);
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).describedAs("Two mappings")
-            .containsOnly(mappingRegex, mappingRegex2);
-        assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
-        virtualUserTable.removeMapping(SOURCE, mappingRegex);
-
-        assertThatThrownBy(() -> virtualUserTable.addRegexMapping(SOURCE, invalidRegex))
-            .describedAs("Invalid Mapping throw exception")
-            .isInstanceOf(RecipientRewriteTableException.class);
-
-
-        virtualUserTable.removeMapping(SOURCE, mappingRegex2);
-
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
-    }
-
-    @Test
-    public void getAllMappingsShouldListAllEntries() throws Exception {
-        String user2 = "test2";
-        String regex = "(.*)@localhost";
-        String regex2 = "(.+)@test";
-
-        Mapping mappingAddress = Mapping.address(USER + "@" + Domain.LOCALHOST.asString());
-        Mapping mappingRegex = Mapping.regex(regex);
-        Mapping mappingRegex2 = Mapping.regex(regex2);
-        MappingSource source2 = MappingSource.fromUser(user2, Domain.LOCALHOST);
-
-        virtualUserTable.addMapping(SOURCE, mappingRegex);
-        virtualUserTable.addMapping(SOURCE, mappingRegex2);
-        virtualUserTable.addMapping(source2, mappingAddress);
-
-        assertThat(virtualUserTable.getAllMappings())
-            .describedAs("One mappingline")
-            .containsOnly(
-                Pair.of(SOURCE, MappingsImpl.builder()
-                    .add(mappingRegex)
-                    .add(mappingRegex2)
-                    .build()),
-                Pair.of(source2, MappingsImpl.builder()
-                    .add(mappingAddress)
-                    .build()));
-    }
-
-    @Test
-    public void testStoreAndRetrieveAddressMapping() throws Exception {
-        Mapping mappingAddress = Mapping.address(ADDRESS);
-        Mapping mappingAddress2 = Mapping.address(ADDRESS_2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
-
-        virtualUserTable.addMapping(SOURCE, mappingAddress);
-        virtualUserTable.addMapping(SOURCE, mappingAddress2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).describedAs("Two mappings")
-            .containsOnly(mappingAddress, mappingAddress2);
-        assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
-
-        virtualUserTable.removeMapping(SOURCE, mappingAddress);
-        virtualUserTable.removeMapping(SOURCE, mappingAddress2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
-    }
-
-    @Test
-    public void testStoreAndRetrieveErrorMapping() throws Exception {
-        String error = "bounce!";
-
-        assertThat(virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
-
-        virtualUserTable.addMapping(SOURCE, Mapping.error(error));
-        assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
-
-        assertThatThrownBy(() ->
-            virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST))
-            .describedAs("Exception thrown on to many mappings")
-            .isInstanceOf(ErrorMappingException.class);
-
-        virtualUserTable.removeMapping(SOURCE, Mapping.error(error));
-
-        assertThat(virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
-    }
-
-    @Test
-    public void testStoreAndRetrieveWildCardAddressMapping() throws Exception {
-        String user2 = "test2";
-
-        Mapping mappingAddress = Mapping.address(ADDRESS);
-        Mapping mappingAddress2 = Mapping.address(ADDRESS_2);
-
-        assertThat(virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
-
-        virtualUserTable.addMapping(MappingSource.fromDomain(Domain.LOCALHOST), mappingAddress);
-        virtualUserTable.addMapping(SOURCE, mappingAddress2);
-
-        assertThat(virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("One mappings")
-            .containsOnly(mappingAddress2);
-        assertThat(virtualUserTable.getResolvedMappings(user2, Domain.LOCALHOST)).describedAs("One mappings")
-            .containsOnly(mappingAddress);
-
-        virtualUserTable.removeMapping(SOURCE, mappingAddress2);
-        virtualUserTable.removeMapping(MappingSource.fromDomain(Domain.LOCALHOST), mappingAddress);
-
-        assertThat(virtualUserTable.getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
-        assertThat(virtualUserTable.getResolvedMappings(user2, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
-    }
-
-    @Test
-    public void testNonRecursiveMapping() throws Exception {
-        String user1 = "user1";
-        String user2 = "user2";
-        String user3 = "user3";
-        Domain domain1 = Domain.of("domain1");
-        Domain domain2 = Domain.of("domain2");
-        Domain domain3 = Domain.of("domain3");
-        MappingSource source1 = MappingSource.fromUser(user1, domain1);
-        MappingSource source2 = MappingSource.fromUser(user2, domain2);
-
-        setNonRecursiveRecipientRewriteTable();
-
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
-
-        virtualUserTable.addMapping(source1, Mapping.address(user2 + "@" + domain2.asString()));
-        virtualUserTable.addMapping(source2, Mapping.address(user3 + "@" + domain3.asString()));
-        assertThatThrownBy(() ->
-            virtualUserTable.getResolvedMappings(user1, domain1))
-            .describedAs("Exception thrown on too many mappings")
-            .isInstanceOf(ErrorMappingException.class);
-    }
-
-    @Test
-    public void testAliasDomainMapping() throws Exception {
-        String domain = "realdomain";
-        Domain aliasDomain = Domain.of("aliasdomain");
-        String user = "user";
-        String user2 = "user2";
-
-        Mapping mappingAddress = Mapping.address(user2 + "@" + domain);
-        Mapping mappingDomain = Mapping.domain(Domain.of(domain));
-
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mappings").isEmpty();
-
-        virtualUserTable.addMapping(MappingSource.fromDomain(aliasDomain), mappingAddress);
-        virtualUserTable.addMapping(MappingSource.fromDomain(aliasDomain), mappingDomain);
-
-        assertThat(virtualUserTable.getResolvedMappings(user, aliasDomain))
-            .describedAs("Domain mapped as first, Address mapped as second")
-            .isEqualTo(MappingsImpl.builder()
-                .add(Mapping.address(user + "@" + domain))
-                .add(mappingAddress)
-                .build());
-
-        virtualUserTable.removeMapping(MappingSource.fromDomain(aliasDomain), mappingAddress);
-        virtualUserTable.removeMapping(MappingSource.fromDomain(aliasDomain), mappingDomain);
-    }
-
-    @Test
-    public void addMappingShouldThrowWhenMappingAlreadyExists() throws Exception {
-        expectedException.expect(RecipientRewriteTableException.class);
-
-        virtualUserTable.addAddressMapping(SOURCE, ADDRESS);
-        virtualUserTable.addAddressMapping(SOURCE, ADDRESS);
-    }
-
-    @Test
-    public void addMappingShouldNotThrowWhenMappingAlreadyExistsWithAnOtherType() throws Exception {
-        Mapping mappingAddress = Mapping.address(ADDRESS);
-        Mapping mappingRegex = Mapping.regex(ADDRESS);
-
-        virtualUserTable.addMapping(SOURCE, mappingAddress);
-        virtualUserTable.addMapping(SOURCE, mappingRegex);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).containsOnly(mappingAddress, mappingRegex);
-    }
-
-    @Test
-    public void addForwardMappingShouldStore() throws Exception {
-        Mapping mappingForward = Mapping.forward(ADDRESS);
-        Mapping mappingForward2 = Mapping.forward(ADDRESS_2);
-
-        virtualUserTable.addMapping(SOURCE, mappingForward);
-        virtualUserTable.addMapping(SOURCE, mappingForward2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).containsOnly(mappingForward, mappingForward2);
-    }
-
-    @Test
-    public void removeForwardMappingShouldDelete() throws Exception {
-        Mapping mappingForward = Mapping.forward(ADDRESS);
-        Mapping mappingForward2 = Mapping.forward(ADDRESS_2);
-        MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
-
-        virtualUserTable.addMapping(source, mappingForward);
-        virtualUserTable.addMapping(source, mappingForward2);
-
-        virtualUserTable.removeMapping(source, mappingForward);
-        virtualUserTable.removeMapping(source, mappingForward2);
-
-        assertThat(virtualUserTable.getStoredMappings(source)).isEmpty();
-    }
-
-    @Test
-    public void addGroupMappingShouldStore() throws Exception {
-        Mapping mappingGroup = Mapping.group(ADDRESS);
-        Mapping mappingGroup2 = Mapping.group(ADDRESS_2);
-
-        virtualUserTable.addMapping(SOURCE, mappingGroup);
-        virtualUserTable.addMapping(SOURCE, mappingGroup2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).containsOnly(mappingGroup, mappingGroup2);
-    }
-
-    @Test
-    public void removeGroupMappingShouldDelete() throws Exception {
-        Mapping mappingGroup = Mapping.group(ADDRESS);
-        Mapping mappingGroup2 = Mapping.group(ADDRESS_2);
-
-        virtualUserTable.addMapping(SOURCE, mappingGroup);
-        virtualUserTable.addMapping(SOURCE, mappingGroup2);
-
-        virtualUserTable.removeMapping(SOURCE, mappingGroup);
-        virtualUserTable.removeMapping(SOURCE, mappingGroup2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).isEmpty();
-    }
-
-    @Test
-    public void addAliasMappingShouldStore() throws Exception {
-        Mapping mappingAlias = Mapping.alias(ADDRESS);
-        Mapping mappingAlias2 = Mapping.alias(ADDRESS_2);
-
-        virtualUserTable.addMapping(SOURCE, mappingAlias);
-        virtualUserTable.addMapping(SOURCE, mappingAlias2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).containsOnly(mappingAlias, mappingAlias2);
-    }
-
-    @Test
-    public void removeAliasMappingShouldDelete() throws Exception {
-        Mapping mappingAlias = Mapping.alias(ADDRESS);
-        Mapping mappingAlias2 = Mapping.alias(ADDRESS_2);
-
-        virtualUserTable.addMapping(SOURCE, mappingAlias);
-        virtualUserTable.addMapping(SOURCE, mappingAlias2);
-
-        virtualUserTable.removeMapping(SOURCE, mappingAlias);
-        virtualUserTable.removeMapping(SOURCE, mappingAlias2);
-
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).isEmpty();
-    }
-
-    @Test
-    public void getUserDomainMappingShouldBeEmptyByDefault() throws Exception {
-        assertThat(virtualUserTable.getStoredMappings(SOURCE)).isEmpty();
-    }
-
-    @Test
-    public void listSourcesShouldReturnWhenHasMapping() throws Exception {
-        Mapping mapping = Mapping.group(ADDRESS);
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping)).contains(SOURCE);
-    }
-
-    @Test
-    public void listSourcesShouldReturnWhenMultipleSourceMapping() throws Exception {
-        MappingSource source = MappingSource.fromUser(USER, Domain.of("james"));
-        MappingSource source2 = MappingSource.fromDomain(Domain.LOCALHOST);
-        Mapping mapping = Mapping.group(ADDRESS);
-
-        virtualUserTable.addMapping(source, mapping);
-        virtualUserTable.addMapping(source2, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping)).contains(source, source2);
-    }
-
-    @Test
-    public void listSourcesShouldReturnWhenHasForwardMapping() throws Exception {
-        Mapping mapping = Mapping.forward("forward");
-
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping)).contains(SOURCE);
-    }
-
-    @Test
-    public void listSourcesShouldReturnAliasMappings() throws Exception {
-        Mapping mapping = Mapping.alias("alias");
-
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping)).contains(SOURCE);
-    }
-
-    @Test
-    public void listSourcesShouldReturnWhenHasAddressMapping() throws Exception {
-        Mapping mapping = Mapping.address("address");
-
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping)).contains(SOURCE);
-    }
-
-    @Test
-    public void listSourcesShouldThrowExceptionWhenHasRegexMapping() throws Exception {
-        Mapping mapping = Mapping.regex("regex");
-
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThatThrownBy(() -> virtualUserTable.listSources(mapping))
-            .isInstanceOf(IllegalArgumentException.class);
-    }
-
-    @Test
-    public void listSourcesShouldHandleDomainMapping() throws Exception {
-        Mapping mapping = Mapping.domain(Domain.of("domain"));
-
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping))
-            .containsExactly(SOURCE);
-    }
-
-    @Test
-    public void listSourcesShouldReturnEmptyWhenNoDomainAlias() throws Exception {
-        Mapping mapping = Mapping.domain(Domain.of("domain"));
-
-        assertThat(virtualUserTable.listSources(mapping)).isEmpty();
-    }
-
-    @Test
-    public void listSourcesShouldHandleDomainSource() throws Exception {
-        Mapping mapping = Mapping.domain(Domain.of("domain"));
-
-        MappingSource source = MappingSource.fromDomain(Domain.of("source.org"));
-        virtualUserTable.addMapping(source, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping))
-            .containsExactly(source);
-    }
-
-    @Test
-    public void listSourcesShouldHandleDomainSources() throws Exception {
-        Mapping mapping = Mapping.domain(Domain.of("domain"));
-
-        MappingSource source1 = MappingSource.fromDomain(Domain.of("source1.org"));
-        MappingSource source2 = MappingSource.fromDomain(Domain.of("source2.org"));
-        virtualUserTable.addMapping(source1, mapping);
-        virtualUserTable.addMapping(source2, mapping);
-
-        assertThat(virtualUserTable.listSources(mapping))
-            .containsExactlyInAnyOrder(source1, source2);
-    }
-
-    @Test
-    public void listSourcesShouldThrowExceptionWhenHasErrorMapping() throws Exception {
-        Mapping mapping = Mapping.error("error");
-
-        virtualUserTable.addMapping(SOURCE, mapping);
-
-        assertThatThrownBy(() -> virtualUserTable.listSources(mapping))
-            .isInstanceOf(IllegalArgumentException.class);
-    }
-
-    @Test
-    public void listSourcesShouldReturnEmptyWhenMappingDoesNotExist() throws Exception {
-        Mapping domainMapping = Mapping.domain(Domain.of("domain"));
-        Mapping groupMapping = Mapping.group("group");
-
-        virtualUserTable.addMapping(SOURCE, domainMapping);
-
-        assertThat(virtualUserTable.listSources(groupMapping)).isEmpty();
-    }
-
-    @Test
-    public void getSourcesForTypeShouldReturnEmptyWhenNoMapping() throws Exception {
-        assertThat(virtualUserTable.getSourcesForType(Mapping.Type.Alias)).isEmpty();
-    }
-
-    @Test
-    public void getSourcesForTypeShouldReturnEmptyWhenNoMatchingMapping() throws Exception {
-        virtualUserTable.addForwardMapping(SOURCE, ADDRESS);
-
-        assertThat(virtualUserTable.getSourcesForType(Mapping.Type.Alias)).isEmpty();
-    }
-
-    @Test
-    public void getSourcesForTypeShouldReturnMatchingMapping() throws Exception {
-        virtualUserTable.addAliasMapping(SOURCE, ADDRESS);
-
-        assertThat(virtualUserTable.getSourcesForType(Mapping.Type.Alias)).containsOnly(SOURCE);
-    }
-
-    @Test
-    public void getSourcesForTypeShouldNotReturnDuplicatedSources() throws Exception {
-        virtualUserTable.addAliasMapping(SOURCE, ADDRESS);
-        virtualUserTable.addAliasMapping(SOURCE, ADDRESS_2);
-
-        assertThat(virtualUserTable.getSourcesForType(Mapping.Type.Alias)).containsExactly(SOURCE);
-    }
-
-    @Test
-    public void getSourcesForTypeShouldReturnSortedStream() throws Exception {
-        MappingSource source1 = MappingSource.fromUser("alice", Domain.LOCALHOST);
-        MappingSource source2 = MappingSource.fromUser("bob", Domain.LOCALHOST);
-        MappingSource source3 = MappingSource.fromUser("cedric", Domain.LOCALHOST);
-
-        virtualUserTable.addAliasMapping(source1, ADDRESS);
-        virtualUserTable.addAliasMapping(source3, ADDRESS);
-        virtualUserTable.addAliasMapping(source2, ADDRESS);
-
-        assertThat(virtualUserTable.getSourcesForType(Mapping.Type.Alias))
-            .containsExactly(source1, source2, source3);
-    }
-
-    @Test
-    public void getMappingsForTypeShouldReturnEmptyWhenNoMapping() throws Exception {
-        assertThat(virtualUserTable.getMappingsForType(Mapping.Type.Alias)).isEmpty();
-    }
-
-    @Test
-    public void getMappingsForTypeShouldReturnEmptyWhenNoMatchingMapping() throws Exception {
-        virtualUserTable.addForwardMapping(SOURCE, ADDRESS);
-
-        assertThat(virtualUserTable.getMappingsForType(Mapping.Type.Alias)).isEmpty();
-    }
-
-    @Test
-    public void getMappingsForTypeShouldReturnMatchingMapping() throws Exception {
-        virtualUserTable.addAliasMapping(SOURCE, ADDRESS);
-
-        assertThat(virtualUserTable.getMappingsForType(Mapping.Type.Alias)).containsOnly(Mapping.alias(ADDRESS));
-    }
-
-    @Test
-    public void getMappingsForTypeShouldNotReturnDuplicatedDestinations() throws Exception {
-        MappingSource source2 = MappingSource.fromUser("bob", Domain.LOCALHOST);
-
-        virtualUserTable.addAliasMapping(SOURCE, ADDRESS);
-        virtualUserTable.addAliasMapping(source2, ADDRESS);
-
-        assertThat(virtualUserTable.getMappingsForType(Mapping.Type.Alias)).containsExactly(Mapping.alias(ADDRESS));
-    }
-
-    @Test
-    public void getMappingsForTypeShouldReturnSortedStream() throws Exception {
-        String address1 = "alice@domain.com";
-        String address2 = "bob@domain.com";
-        String address3 = "cedric@domain.com";
-        Mapping mapping1 = Mapping.alias(address1);
-        Mapping mapping2 = Mapping.alias(address2);
-        Mapping mapping3 = Mapping.alias(address3);
-
-        virtualUserTable.addAliasMapping(SOURCE, address1);
-        virtualUserTable.addAliasMapping(SOURCE, address3);
-        virtualUserTable.addAliasMapping(SOURCE, address2);
-
-        assertThat(virtualUserTable.getMappingsForType(Mapping.Type.Alias))
-            .containsExactly(mapping1, mapping2, mapping3);
-    }
-
-    @Test
-    public void addRegexMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addRegexMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ".*@localhost"))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addAddressMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addAddressMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addErrorMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addErrorMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, "error"))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addDomainMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addDomainMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, SUPPORTED_DOMAIN))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addDomainAliasShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addDomainAliasMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, SUPPORTED_DOMAIN))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addForwardMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addForwardMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addGroupMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addGroupMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-
-    @Test
-    public void addAliasMappingShouldThrowWhenDomainIsNotInDomainList() {
-        assertThatThrownBy(() -> virtualUserTable.addAliasMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
-            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
-    }
-}
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableContract.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableContract.java
new file mode 100644
index 0000000..6d41abd
--- /dev/null
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableContract.java
@@ -0,0 +1,636 @@
+/****************************************************************
+ * 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.rrt.lib;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.james.core.Domain;
+import org.apache.james.domainlist.api.mock.SimpleDomainList;
+import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.rrt.api.RecipientRewriteTable.ErrorMappingException;
+import org.apache.james.rrt.api.RecipientRewriteTableConfiguration;
+import org.apache.james.rrt.api.RecipientRewriteTableException;
+import org.apache.james.rrt.api.SourceDomainIsNotInDomainListException;
+import org.junit.jupiter.api.Test;
+
+import com.github.fge.lambdas.Throwing;
+
+/**
+ * The abstract test for the virtual user table. Contains tests related to
+ * simple, regexp, wildcard, error,... Extend this and instantiate the needed
+ * virtualUserTable implementation.
+ */
+public interface RecipientRewriteTableContract {
+
+    String USER = "test";
+    String ADDRESS = "test@localhost2";
+    String ADDRESS_2 = "test@james";
+    Domain SUPPORTED_DOMAIN = Domain.LOCALHOST;
+    MappingSource SOURCE = MappingSource.fromUser(USER, SUPPORTED_DOMAIN);
+    Domain NOT_SUPPORTED_DOMAIN = Domain.of("notAManagedDomain");
+    MappingSource SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST = MappingSource.fromUser(USER, NOT_SUPPORTED_DOMAIN);
+
+    void createRecipientRewriteTable();
+    AbstractRecipientRewriteTable virtualUserTable();
+
+    default void setUp() throws Exception {
+        setRecursiveRecipientRewriteTable();
+    }
+
+    private void setRecursiveRecipientRewriteTable() throws Exception {
+        setNotConfiguredRecipientRewriteTable();
+        virtualUserTable().setConfiguration(new RecipientRewriteTableConfiguration(true, 10));
+    }
+
+    private void setNonRecursiveRecipientRewriteTable() throws Exception {
+        setNotConfiguredRecipientRewriteTable();
+        virtualUserTable().setConfiguration(new RecipientRewriteTableConfiguration(false, 0));
+    }
+
+    private void setNotConfiguredRecipientRewriteTable() throws Exception {
+        createRecipientRewriteTable();
+
+        SimpleDomainList domainList = new SimpleDomainList();
+        domainList.addDomain(SUPPORTED_DOMAIN);
+        virtualUserTable().setDomainList(domainList);
+    }
+
+    default void tearDown() throws Exception {
+        Map<MappingSource, Mappings> mappings = virtualUserTable().getAllMappings();
+
+        if (mappings != null) {
+            for (MappingSource key : virtualUserTable().getAllMappings().keySet()) {
+                Mappings map = mappings.get(key);
+
+                map.asStream()
+                    .forEach(Throwing.consumer(mapping ->
+                        virtualUserTable().removeMapping(key, mapping)));
+            }
+        }
+
+        LifecycleUtil.dispose(virtualUserTable());
+    }
+
+    @Test
+    default void testStoreAndGetMappings() throws Exception {
+        Domain domain = Domain.of("test");
+        virtualUserTable().addMapping(MappingSource.fromDomain(domain), Mapping.regex("prefix_.*:admin@test"));
+        assertThat(virtualUserTable().getResolvedMappings("prefix_abc", domain)).isNotEmpty();
+    }
+
+    @Test
+    default void notConfiguredResolutionShouldThrow() throws Exception {
+        setNotConfiguredRecipientRewriteTable();
+        assertThatCode(() -> virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST))
+            .isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
+    default void configuringTwiceShouldThrow() {
+        assertThatCode(() -> virtualUserTable().setConfiguration(new RecipientRewriteTableConfiguration(true, 10)))
+            .isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
+    default void testStoreAndRetrieveRegexMapping() throws Exception {
+        String regex = "(.*)@localhost";
+        String regex2 = "(.+)@test";
+        String invalidRegex = ".*):";
+
+        Mapping mappingRegex = Mapping.regex(regex);
+        Mapping mappingRegex2 = Mapping.regex(regex2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
+
+        virtualUserTable().addMapping(SOURCE, mappingRegex);
+        virtualUserTable().addMapping(SOURCE, mappingRegex2);
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).describedAs("Two mappings")
+            .containsOnly(mappingRegex, mappingRegex2);
+        assertThat(virtualUserTable().getAllMappings()).describedAs("One mappingline").hasSize(1);
+        virtualUserTable().removeMapping(SOURCE, mappingRegex);
+
+        assertThatThrownBy(() -> virtualUserTable().addRegexMapping(SOURCE, invalidRegex))
+            .describedAs("Invalid Mapping throw exception")
+            .isInstanceOf(RecipientRewriteTableException.class);
+        
+        virtualUserTable().removeMapping(SOURCE, mappingRegex2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
+        assertThat(virtualUserTable().getAllMappings()).describedAs("No mapping").isEmpty();
+    }
+
+    @Test
+    default void getAllMappingsShouldListAllEntries() throws Exception {
+        String user2 = "test2";
+        String regex = "(.*)@localhost";
+        String regex2 = "(.+)@test";
+
+        Mapping mappingAddress = Mapping.address(USER + "@" + Domain.LOCALHOST.asString());
+        Mapping mappingRegex = Mapping.regex(regex);
+        Mapping mappingRegex2 = Mapping.regex(regex2);
+        MappingSource source2 = MappingSource.fromUser(user2, Domain.LOCALHOST);
+
+        virtualUserTable().addMapping(SOURCE, mappingRegex);
+        virtualUserTable().addMapping(SOURCE, mappingRegex2);
+        virtualUserTable().addMapping(source2, mappingAddress);
+
+        assertThat(virtualUserTable().getAllMappings())
+            .describedAs("One mappingline")
+            .containsOnly(
+                Pair.of(SOURCE, MappingsImpl.builder()
+                    .add(mappingRegex)
+                    .add(mappingRegex2)
+                    .build()),
+                Pair.of(source2, MappingsImpl.builder()
+                    .add(mappingAddress)
+                    .build()));
+    }
+
+    @Test
+    default void testStoreAndRetrieveAddressMapping() throws Exception {
+        Mapping mappingAddress = Mapping.address(ADDRESS);
+        Mapping mappingAddress2 = Mapping.address(ADDRESS_2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
+
+        virtualUserTable().addMapping(SOURCE, mappingAddress);
+        virtualUserTable().addMapping(SOURCE, mappingAddress2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).describedAs("Two mappings")
+            .containsOnly(mappingAddress, mappingAddress2);
+        assertThat(virtualUserTable().getAllMappings()).describedAs("One mappingline").hasSize(1);
+
+        virtualUserTable().removeMapping(SOURCE, mappingAddress);
+        virtualUserTable().removeMapping(SOURCE, mappingAddress2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).describedAs("No mapping").isEmpty();
+        assertThat(virtualUserTable().getAllMappings()).describedAs("No mapping").isEmpty();
+    }
+
+    @Test
+    default void testStoreAndRetrieveErrorMapping() throws Exception {
+        String error = "bounce!";
+
+        assertThat(virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
+
+        virtualUserTable().addMapping(SOURCE, Mapping.error(error));
+        assertThat(virtualUserTable().getAllMappings()).describedAs("One mappingline").hasSize(1);
+
+        assertThatThrownBy(() ->
+            virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST))
+            .describedAs("Exception thrown on to many mappings")
+            .isInstanceOf(ErrorMappingException.class);
+
+        virtualUserTable().removeMapping(SOURCE, Mapping.error(error));
+
+        assertThat(virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
+        assertThat(virtualUserTable().getAllMappings()).describedAs("No mapping").isEmpty();
+    }
+
+    @Test
+    default void testStoreAndRetrieveWildCardAddressMapping() throws Exception {
+        String user2 = "test2";
+
+        Mapping mappingAddress = Mapping.address(ADDRESS);
+        Mapping mappingAddress2 = Mapping.address(ADDRESS_2);
+
+        assertThat(virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
+
+        virtualUserTable().addMapping(MappingSource.fromDomain(Domain.LOCALHOST), mappingAddress);
+        virtualUserTable().addMapping(SOURCE, mappingAddress2);
+
+        assertThat(virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("One mappings")
+            .containsOnly(mappingAddress2);
+        assertThat(virtualUserTable().getResolvedMappings(user2, Domain.LOCALHOST)).describedAs("One mappings")
+            .containsOnly(mappingAddress);
+
+        virtualUserTable().removeMapping(SOURCE, mappingAddress2);
+        virtualUserTable().removeMapping(MappingSource.fromDomain(Domain.LOCALHOST), mappingAddress);
+
+        assertThat(virtualUserTable().getResolvedMappings(USER, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
+        assertThat(virtualUserTable().getResolvedMappings(user2, Domain.LOCALHOST)).describedAs("No mapping").isEmpty();
+    }
+
+    @Test
+    default void testNonRecursiveMapping() throws Exception {
+        String user1 = "user1";
+        String user2 = "user2";
+        String user3 = "user3";
+        Domain domain1 = Domain.of("domain1");
+        Domain domain2 = Domain.of("domain2");
+        Domain domain3 = Domain.of("domain3");
+        MappingSource source1 = MappingSource.fromUser(user1, domain1);
+        MappingSource source2 = MappingSource.fromUser(user2, domain2);
+
+        setNonRecursiveRecipientRewriteTable();
+
+        assertThat(virtualUserTable().getAllMappings()).describedAs("No mapping").isEmpty();
+
+        virtualUserTable().addMapping(source1, Mapping.address(user2 + "@" + domain2.asString()));
+        virtualUserTable().addMapping(source2, Mapping.address(user3 + "@" + domain3.asString()));
+        assertThatThrownBy(() ->
+            virtualUserTable().getResolvedMappings(user1, domain1))
+            .describedAs("Exception thrown on too many mappings")
+            .isInstanceOf(ErrorMappingException.class);
+    }
+
+    @Test
+    default void testAliasDomainMapping() throws Exception {
+        String domain = "realdomain";
+        Domain aliasDomain = Domain.of("aliasdomain");
+        String user = "user";
+        String user2 = "user2";
+
+        Mapping mappingAddress = Mapping.address(user2 + "@" + domain);
+        Mapping mappingDomain = Mapping.domain(Domain.of(domain));
+
+        assertThat(virtualUserTable().getAllMappings()).describedAs("No mappings").isEmpty();
+
+        virtualUserTable().addMapping(MappingSource.fromDomain(aliasDomain), mappingAddress);
+        virtualUserTable().addMapping(MappingSource.fromDomain(aliasDomain), mappingDomain);
+
+        assertThat(virtualUserTable().getResolvedMappings(user, aliasDomain))
+            .describedAs("Domain mapped as first, Address mapped as second")
+            .isEqualTo(MappingsImpl.builder()
+                .add(Mapping.address(user + "@" + domain))
+                .add(mappingAddress)
+                .build());
+
+        virtualUserTable().removeMapping(MappingSource.fromDomain(aliasDomain), mappingAddress);
+        virtualUserTable().removeMapping(MappingSource.fromDomain(aliasDomain), mappingDomain);
+    }
+
+    @Test
+    default void addMappingShouldThrowWhenMappingAlreadyExists() throws Exception {
+        virtualUserTable().addAddressMapping(SOURCE, ADDRESS);
+
+        assertThatThrownBy(() -> virtualUserTable().addAddressMapping(SOURCE, ADDRESS))
+            .isInstanceOf(RecipientRewriteTableException.class);
+    }
+
+    @Test
+    default void addMappingShouldNotThrowWhenMappingAlreadyExistsWithAnOtherType() throws Exception {
+        Mapping mappingAddress = Mapping.address(ADDRESS);
+        Mapping mappingRegex = Mapping.regex(ADDRESS);
+
+        virtualUserTable().addMapping(SOURCE, mappingAddress);
+        virtualUserTable().addMapping(SOURCE, mappingRegex);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).containsOnly(mappingAddress, mappingRegex);
+    }
+
+    @Test
+    default void addForwardMappingShouldStore() throws Exception {
+        Mapping mappingForward = Mapping.forward(ADDRESS);
+        Mapping mappingForward2 = Mapping.forward(ADDRESS_2);
+
+        virtualUserTable().addMapping(SOURCE, mappingForward);
+        virtualUserTable().addMapping(SOURCE, mappingForward2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).containsOnly(mappingForward, mappingForward2);
+    }
+
+    @Test
+    default void removeForwardMappingShouldDelete() throws Exception {
+        Mapping mappingForward = Mapping.forward(ADDRESS);
+        Mapping mappingForward2 = Mapping.forward(ADDRESS_2);
+        MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+
+        virtualUserTable().addMapping(source, mappingForward);
+        virtualUserTable().addMapping(source, mappingForward2);
+
+        virtualUserTable().removeMapping(source, mappingForward);
+        virtualUserTable().removeMapping(source, mappingForward2);
+
+        assertThat(virtualUserTable().getStoredMappings(source)).isEmpty();
+    }
+
+    @Test
+    default void addGroupMappingShouldStore() throws Exception {
+        Mapping mappingGroup = Mapping.group(ADDRESS);
+        Mapping mappingGroup2 = Mapping.group(ADDRESS_2);
+
+        virtualUserTable().addMapping(SOURCE, mappingGroup);
+        virtualUserTable().addMapping(SOURCE, mappingGroup2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).containsOnly(mappingGroup, mappingGroup2);
+    }
+
+    @Test
+    default void removeGroupMappingShouldDelete() throws Exception {
+        Mapping mappingGroup = Mapping.group(ADDRESS);
+        Mapping mappingGroup2 = Mapping.group(ADDRESS_2);
+
+        virtualUserTable().addMapping(SOURCE, mappingGroup);
+        virtualUserTable().addMapping(SOURCE, mappingGroup2);
+
+        virtualUserTable().removeMapping(SOURCE, mappingGroup);
+        virtualUserTable().removeMapping(SOURCE, mappingGroup2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).isEmpty();
+    }
+
+    @Test
+    default void addAliasMappingShouldStore() throws Exception {
+        Mapping mappingAlias = Mapping.alias(ADDRESS);
+        Mapping mappingAlias2 = Mapping.alias(ADDRESS_2);
+
+        virtualUserTable().addMapping(SOURCE, mappingAlias);
+        virtualUserTable().addMapping(SOURCE, mappingAlias2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).containsOnly(mappingAlias, mappingAlias2);
+    }
+
+    @Test
+    default void removeAliasMappingShouldDelete() throws Exception {
+        Mapping mappingAlias = Mapping.alias(ADDRESS);
+        Mapping mappingAlias2 = Mapping.alias(ADDRESS_2);
+
+        virtualUserTable().addMapping(SOURCE, mappingAlias);
+        virtualUserTable().addMapping(SOURCE, mappingAlias2);
+
+        virtualUserTable().removeMapping(SOURCE, mappingAlias);
+        virtualUserTable().removeMapping(SOURCE, mappingAlias2);
+
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).isEmpty();
+    }
+
+    @Test
+    default void getUserDomainMappingShouldBeEmptyByDefault() throws Exception {
+        assertThat(virtualUserTable().getStoredMappings(SOURCE)).isEmpty();
+    }
+
+    @Test
+    default void listSourcesShouldReturnWhenHasMapping() throws Exception {
+        Mapping mapping = Mapping.group(ADDRESS);
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping)).contains(SOURCE);
+    }
+
+    @Test
+    default void listSourcesShouldReturnWhenMultipleSourceMapping() throws Exception {
+        MappingSource source = MappingSource.fromUser(USER, Domain.of("james"));
+        MappingSource source2 = MappingSource.fromDomain(Domain.LOCALHOST);
+        Mapping mapping = Mapping.group(ADDRESS);
+
+        virtualUserTable().addMapping(source, mapping);
+        virtualUserTable().addMapping(source2, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping)).contains(source, source2);
+    }
+
+    @Test
+    default void listSourcesShouldReturnWhenHasForwardMapping() throws Exception {
+        Mapping mapping = Mapping.forward("forward");
+
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping)).contains(SOURCE);
+    }
+
+    @Test
+    default void listSourcesShouldReturnAliasMappings() throws Exception {
+        Mapping mapping = Mapping.alias("alias");
+
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping)).contains(SOURCE);
+    }
+
+    @Test
+    default void listSourcesShouldReturnWhenHasAddressMapping() throws Exception {
+        Mapping mapping = Mapping.address("address");
+
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping)).contains(SOURCE);
+    }
+
+    @Test
+    default void listSourcesShouldThrowExceptionWhenHasRegexMapping() throws Exception {
+        Mapping mapping = Mapping.regex("regex");
+
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThatThrownBy(() -> virtualUserTable().listSources(mapping))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    default void listSourcesShouldHandleDomainMapping() throws Exception {
+        Mapping mapping = Mapping.domain(Domain.of("domain"));
+
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping))
+            .containsExactly(SOURCE);
+    }
+
+    @Test
+    default void listSourcesShouldReturnEmptyWhenNoDomainAlias() throws Exception {
+        Mapping mapping = Mapping.domain(Domain.of("domain"));
+
+        assertThat(virtualUserTable().listSources(mapping)).isEmpty();
+    }
+
+    @Test
+    default void listSourcesShouldHandleDomainSource() throws Exception {
+        Mapping mapping = Mapping.domain(Domain.of("domain"));
+
+        MappingSource source = MappingSource.fromDomain(Domain.of("source.org"));
+        virtualUserTable().addMapping(source, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping))
+            .containsExactly(source);
+    }
+
+    @Test
+    default void listSourcesShouldHandleDomainSources() throws Exception {
+        Mapping mapping = Mapping.domain(Domain.of("domain"));
+
+        MappingSource source1 = MappingSource.fromDomain(Domain.of("source1.org"));
+        MappingSource source2 = MappingSource.fromDomain(Domain.of("source2.org"));
+        virtualUserTable().addMapping(source1, mapping);
+        virtualUserTable().addMapping(source2, mapping);
+
+        assertThat(virtualUserTable().listSources(mapping))
+            .containsExactlyInAnyOrder(source1, source2);
+    }
+
+    @Test
+    default void listSourcesShouldThrowExceptionWhenHasErrorMapping() throws Exception {
+        Mapping mapping = Mapping.error("error");
+
+        virtualUserTable().addMapping(SOURCE, mapping);
+
+        assertThatThrownBy(() -> virtualUserTable().listSources(mapping))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    default void listSourcesShouldReturnEmptyWhenMappingDoesNotExist() throws Exception {
+        Mapping domainMapping = Mapping.domain(Domain.of("domain"));
+        Mapping groupMapping = Mapping.group("group");
+
+        virtualUserTable().addMapping(SOURCE, domainMapping);
+
+        assertThat(virtualUserTable().listSources(groupMapping)).isEmpty();
+    }
+
+    @Test
+    default void getSourcesForTypeShouldReturnEmptyWhenNoMapping() throws Exception {
+        assertThat(virtualUserTable().getSourcesForType(Mapping.Type.Alias)).isEmpty();
+    }
+
+    @Test
+    default void getSourcesForTypeShouldReturnEmptyWhenNoMatchingMapping() throws Exception {
+        virtualUserTable().addForwardMapping(SOURCE, ADDRESS);
+
+        assertThat(virtualUserTable().getSourcesForType(Mapping.Type.Alias)).isEmpty();
+    }
+
+    @Test
+    default void getSourcesForTypeShouldReturnMatchingMapping() throws Exception {
+        virtualUserTable().addAliasMapping(SOURCE, ADDRESS);
+
+        assertThat(virtualUserTable().getSourcesForType(Mapping.Type.Alias)).containsOnly(SOURCE);
+    }
+
+    @Test
+    default void getSourcesForTypeShouldNotReturnDuplicatedSources() throws Exception {
+        virtualUserTable().addAliasMapping(SOURCE, ADDRESS);
+        virtualUserTable().addAliasMapping(SOURCE, ADDRESS_2);
+
+        assertThat(virtualUserTable().getSourcesForType(Mapping.Type.Alias)).containsExactly(SOURCE);
+    }
+
+    @Test
+    default void getSourcesForTypeShouldReturnSortedStream() throws Exception {
+        MappingSource source1 = MappingSource.fromUser("alice", Domain.LOCALHOST);
+        MappingSource source2 = MappingSource.fromUser("bob", Domain.LOCALHOST);
+        MappingSource source3 = MappingSource.fromUser("cedric", Domain.LOCALHOST);
+
+        virtualUserTable().addAliasMapping(source1, ADDRESS);
+        virtualUserTable().addAliasMapping(source3, ADDRESS);
+        virtualUserTable().addAliasMapping(source2, ADDRESS);
+
+        assertThat(virtualUserTable().getSourcesForType(Mapping.Type.Alias))
+            .containsExactly(source1, source2, source3);
+    }
+
+    @Test
+    default void getMappingsForTypeShouldReturnEmptyWhenNoMapping() throws Exception {
+        assertThat(virtualUserTable().getMappingsForType(Mapping.Type.Alias)).isEmpty();
+    }
+
+    @Test
+    default void getMappingsForTypeShouldReturnEmptyWhenNoMatchingMapping() throws Exception {
+        virtualUserTable().addForwardMapping(SOURCE, ADDRESS);
+
+        assertThat(virtualUserTable().getMappingsForType(Mapping.Type.Alias)).isEmpty();
+    }
+
+    @Test
+    default void getMappingsForTypeShouldReturnMatchingMapping() throws Exception {
+        virtualUserTable().addAliasMapping(SOURCE, ADDRESS);
+
+        assertThat(virtualUserTable().getMappingsForType(Mapping.Type.Alias)).containsOnly(Mapping.alias(ADDRESS));
+    }
+
+    @Test
+    default void getMappingsForTypeShouldNotReturnDuplicatedDestinations() throws Exception {
+        MappingSource source2 = MappingSource.fromUser("bob", Domain.LOCALHOST);
+
+        virtualUserTable().addAliasMapping(SOURCE, ADDRESS);
+        virtualUserTable().addAliasMapping(source2, ADDRESS);
+
+        assertThat(virtualUserTable().getMappingsForType(Mapping.Type.Alias)).containsExactly(Mapping.alias(ADDRESS));
+    }
+
+    @Test
+    default void getMappingsForTypeShouldReturnSortedStream() throws Exception {
+        String address1 = "alice@domain.com";
+        String address2 = "bob@domain.com";
+        String address3 = "cedric@domain.com";
+        Mapping mapping1 = Mapping.alias(address1);
+        Mapping mapping2 = Mapping.alias(address2);
+        Mapping mapping3 = Mapping.alias(address3);
+
+        virtualUserTable().addAliasMapping(SOURCE, address1);
+        virtualUserTable().addAliasMapping(SOURCE, address3);
+        virtualUserTable().addAliasMapping(SOURCE, address2);
+
+        assertThat(virtualUserTable().getMappingsForType(Mapping.Type.Alias))
+            .containsExactly(mapping1, mapping2, mapping3);
+    }
+
+    @Test
+    default void addRegexMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addRegexMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ".*@localhost"))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addAddressMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addAddressMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addErrorMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addErrorMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, "error"))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addDomainMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addDomainMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, SUPPORTED_DOMAIN))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addDomainAliasShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addDomainAliasMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, SUPPORTED_DOMAIN))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addForwardMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addForwardMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addGroupMappingShouldThrowWhenSourceDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addGroupMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+
+    @Test
+    default void addAliasMappingShouldThrowWhenDomainIsNotInDomainList() {
+        assertThatThrownBy(() -> virtualUserTable().addAliasMapping(SOURCE_WITH_DOMAIN_NOT_IN_DOMAIN_LIST, ADDRESS))
+            .isInstanceOf(SourceDomainIsNotInDomainListException.class);
+    }
+}
diff --git a/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTableTest.java b/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTableTest.java
index 7725797..76aff5e 100644
--- a/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTableTest.java
+++ b/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTableTest.java
@@ -20,26 +20,31 @@
 package org.apache.james.rrt.memory;
 
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.james.rrt.lib.RecipientRewriteTableContract;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class MemoryRecipientRewriteTableTest extends AbstractRecipientRewriteTableTest {
+class MemoryRecipientRewriteTableTest implements RecipientRewriteTableContract {
 
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
+    AbstractRecipientRewriteTable recipientRewriteTable;
+
+    @BeforeEach
+    void setup() throws Exception {
+        setUp();
+    }
+
+    @AfterEach
+    void teardown() throws Exception {
+        tearDown();
     }
 
     @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
+    public void createRecipientRewriteTable() {
+        recipientRewriteTable = new MemoryRecipientRewriteTable();
     }
 
     @Override
-    protected AbstractRecipientRewriteTable getRecipientRewriteTable() {
-        return new MemoryRecipientRewriteTable();
+    public AbstractRecipientRewriteTable virtualUserTable() {
+        return recipientRewriteTable;
     }
 }


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


[james-project] 20/26: [Refactoring] Migrate SieveRepositoryManagementTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit deb799632a5653815805fdfe2e6e0346ce5a46a0
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:42:15 2020 +0700

    [Refactoring] Migrate SieveRepositoryManagementTest to JUnit5
---
 .../lib/SieveRepositoryManagementTest.java           | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryManagementTest.java b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryManagementTest.java
index 94597a4..392e370 100644
--- a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryManagementTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/SieveRepositoryManagementTest.java
@@ -29,28 +29,26 @@ import org.apache.james.core.Username;
 import org.apache.james.sieverepository.api.ScriptContent;
 import org.apache.james.sieverepository.api.ScriptName;
 import org.apache.james.sieverepository.api.SieveRepository;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-public class SieveRepositoryManagementTest {
-
+class SieveRepositoryManagementTest {
     @Mock
-    private SieveRepository sieveRepository;
+    SieveRepository sieveRepository;
 
-    private SieveRepositoryManagement sieveRepositoryManagement;
+    SieveRepositoryManagement sieveRepositoryManagement;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         sieveRepositoryManagement = new SieveRepositoryManagement();
         sieveRepositoryManagement.setSieveRepository(sieveRepository);
     }
 
-
     @Test
-    public void importSieveScriptFileToRepositoryShouldStoreContentAndActivateScript() throws Exception {
+    void importSieveScriptFileToRepositoryShouldStoreContentAndActivateScript() throws Exception {
         String userName = "user@domain";
         String script = "user_script";
         URL sieveResource = ClassLoader.getSystemResource("sieve/my_sieve");
@@ -67,7 +65,7 @@ public class SieveRepositoryManagementTest {
     }
 
     @Test
-    public void importSieveScriptFileToRepositoryShouldNotImportFileWithWrongPathToRepistory() throws Exception {
+    void importSieveScriptFileToRepositoryShouldNotImportFileWithWrongPathToRepistory() throws Exception {
         String userName = "user@domain";
         String script = "user_script";
         URL sieveResource = ClassLoader.getSystemResource("sieve/my_sieve");


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


[james-project] 19/26: [Refactoring] Migrate ConfigurationItemsRemovedTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 03aa79d8b5039f5b8253b7ec425e52b29968b268
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:39:13 2020 +0700

    [Refactoring] Migrate ConfigurationItemsRemovedTest to JUnit5
---
 .../events/ConfigurationItemsRemovedTest.java              | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
index a6d4ecc..486d13c 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
@@ -25,40 +25,40 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import org.apache.james.core.Domain;
 import org.apache.james.dlp.eventsourcing.aggregates.DLPAggregateId;
 import org.apache.james.eventsourcing.EventId;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class ConfigurationItemsRemovedTest {
+class ConfigurationItemsRemovedTest {
 
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(ConfigurationItemsRemoved.class)
             .verify();
     }
 
     @Test
-    public void constructorShouldThrowWhenNullAggregateId() {
+    void constructorShouldThrowWhenNullAggregateId() {
         assertThatThrownBy(() -> new ConfigurationItemsRemoved(null, EventId.first(), ImmutableList.of(RULE)))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenNullEventId() {
+    void constructorShouldThrowWhenNullEventId() {
         assertThatThrownBy(() -> new ConfigurationItemsRemoved(new DLPAggregateId(Domain.LOCALHOST), null, ImmutableList.of()))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenEmptyRulesList() {
+    void constructorShouldThrowWhenEmptyRulesList() {
         assertThatThrownBy(() -> new ConfigurationItemsRemoved(new DLPAggregateId(Domain.LOCALHOST), EventId.first(), ImmutableList.of()))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenNullRulesList() {
+    void constructorShouldThrowWhenNullRulesList() {
         assertThatThrownBy(() -> new ConfigurationItemsRemoved(new DLPAggregateId(Domain.LOCALHOST), EventId.first(), null))
             .isInstanceOf(NullPointerException.class);
     }


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


[james-project] 17/26: [Refactoring] Migrate StoreCommandTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 43cbb29acb84397572b802170fc76d610fa8a6e8
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:38:01 2020 +0700

    [Refactoring] Migrate StoreCommandTest to JUnit5
---
 .../james/dlp/eventsourcing/commands/StoreCommandTest.java     | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
index f327caf..2f8e03c 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
@@ -24,28 +24,28 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.core.Domain;
 import org.apache.james.dlp.api.DLPRules;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class StoreCommandTest {
+class StoreCommandTest {
 
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(StoreCommand.class)
             .verify();
     }
 
     @Test
-    public void constructorShouldThrowWhenNullDomain() {
+    void constructorShouldThrowWhenNullDomain() {
         assertThatThrownBy(() -> new StoreCommand(null, new DLPRules(ImmutableList.of(RULE))))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenNullRules() {
+    void constructorShouldThrowWhenNullRules() {
         assertThatThrownBy(() -> new StoreCommand(Domain.LOCALHOST, null))
             .isInstanceOf(NullPointerException.class);
     }


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


[james-project] 26/26: [Refactoring] Remove useless @Rule in JPAHealthCheckTest

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9e4f7083e1df407c9aa09575806364f979b60cd3
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 17:14:58 2020 +0700

    [Refactoring] Remove useless @Rule in JPAHealthCheckTest
---
 .../org/apache/james/jpa/healthcheck/JPAHealthCheckTest.java   | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/server/data/data-jpa/src/test/java/org/apache/james/jpa/healthcheck/JPAHealthCheckTest.java b/server/data/data-jpa/src/test/java/org/apache/james/jpa/healthcheck/JPAHealthCheckTest.java
index 38e8326..16f880b 100644
--- a/server/data/data-jpa/src/test/java/org/apache/james/jpa/healthcheck/JPAHealthCheckTest.java
+++ b/server/data/data-jpa/src/test/java/org/apache/james/jpa/healthcheck/JPAHealthCheckTest.java
@@ -25,18 +25,12 @@ import org.apache.james.backends.jpa.JpaTestCluster;
 import org.apache.james.core.healthcheck.Result;
 import org.apache.james.core.healthcheck.ResultStatus;
 import org.apache.james.mailrepository.jpa.JPAUrl;
-import org.junit.Rule;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.rules.ExpectedException;
 
 class JPAHealthCheckTest {
-
-    private JPAHealthCheck jpaHealthCheck;
-    private JpaTestCluster jpaTestCluster;
-
-    @Rule
-    ExpectedException expectedException = ExpectedException.none();
+    JPAHealthCheck jpaHealthCheck;
+    JpaTestCluster jpaTestCluster;
 
     @BeforeEach
     void setUp() {


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


[james-project] 07/26: [Refactoring] Migrate XMLDomainListTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4d50f065ef9428cf3a4f4622b99768fed285e369
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Aug 12 16:39:35 2020 +0700

    [Refactoring] Migrate XMLDomainListTest to JUnit5
---
 .../james/domainlist/xml/XMLDomainListTest.java    | 39 +++++++++-------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java b/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
index 366dfe2..c3b93e9 100644
--- a/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
@@ -19,6 +19,7 @@
 package org.apache.james.domainlist.xml;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -29,19 +30,13 @@ import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.mock.MockDNSService;
 import org.apache.james.domainlist.api.DomainListException;
 import org.apache.james.domainlist.lib.DomainListConfiguration;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
-public class XMLDomainListTest {
-
-    public static final Domain DEFAULT_DOMAIN = Domain.of("default.domain");
-    public static final Domain DOMAIN_1 = Domain.of("domain1");
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+class XMLDomainListTest {
+    static final Domain DEFAULT_DOMAIN = Domain.of("default.domain");
+    static final Domain DOMAIN_1 = Domain.of("domain1");
 
     private DNSService setUpDNSServer(final String hostName) {
         return new MockDNSService() {
@@ -65,7 +60,7 @@ public class XMLDomainListTest {
 
     // See https://issues.apache.org/jira/browse/JAMES-998
     @Test
-    public void testNoConfiguredDomains() throws Exception {
+    void testNoConfiguredDomains() throws Exception {
         XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost"));
 
         dom.configure(DomainListConfiguration.builder()
@@ -78,7 +73,7 @@ public class XMLDomainListTest {
     }
 
     @Test
-    public void testGetDomains() throws Exception {
+    void testGetDomains() throws Exception {
         XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost"));
         dom.configure(DomainListConfiguration.builder()
             .autoDetect(false)
@@ -90,7 +85,7 @@ public class XMLDomainListTest {
     }
 
     @Test
-    public void testGetDomainsAutoDetectNotLocalHost() throws Exception {
+    void testGetDomainsAutoDetectNotLocalHost() throws Exception {
         XMLDomainList dom = new XMLDomainList(setUpDNSServer("local"));
         dom.configure(DomainListConfiguration.builder()
             .autoDetect(true)
@@ -102,7 +97,7 @@ public class XMLDomainListTest {
     }
 
     @Test
-    public void testGetDomainsAutoDetectLocalHost() throws Exception {
+    void testGetDomainsAutoDetectLocalHost() throws Exception {
         XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost"));
         dom.configure(DomainListConfiguration.builder()
             .autoDetect(false)
@@ -114,9 +109,7 @@ public class XMLDomainListTest {
     }
 
     @Test
-    public void addDomainShouldFailWhenAlreadyConfigured() throws Exception {
-        expectedException.expect(DomainListException.class);
-
+    void addDomainShouldFailWhenAlreadyConfigured() throws Exception {
         XMLDomainList testee = new XMLDomainList(setUpDNSServer("hostname"));
         testee.configure(DomainListConfiguration.builder()
             .autoDetect(true)
@@ -124,24 +117,24 @@ public class XMLDomainListTest {
             .addConfiguredDomain(DOMAIN_1)
             .defaultDomain(DEFAULT_DOMAIN));
 
-        testee.addDomain(Domain.of("newDomain"));
+        assertThatThrownBy(() -> testee.addDomain(Domain.of("newDomain")))
+            .isInstanceOf(DomainListException.class);
     }
 
     @Test
-    public void removeDomainShouldFailWhenAlreadyConfigured() throws Exception {
-        expectedException.expect(DomainListException.class);
-
+    void removeDomainShouldFailWhenAlreadyConfigured() throws Exception {
         XMLDomainList testee = new XMLDomainList(setUpDNSServer("localhost"));
         testee.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(false)
             .addConfiguredDomain(DOMAIN_1));
 
-        testee.removeDomain(Domain.of("newDomain"));
+        assertThatThrownBy(() -> testee.removeDomain(Domain.of("newDomain")))
+            .isInstanceOf(DomainListException.class);
     }
 
     @Test
-    public void configureShouldNotFailWhenConfiguringDefaultDomain() throws Exception {
+    void configureShouldNotFailWhenConfiguringDefaultDomain() throws Exception {
         XMLDomainList testee = new XMLDomainList(setUpDNSServer("localhost"));
         testee.configure(DomainListConfiguration.builder()
             .autoDetect(false)


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


[james-project] 14/26: [Refactoring] Migrate UsersRepositoryManagementTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2026d325ad60e1c754ac36f5c88f94aceb19fcc2
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:30:47 2020 +0700

    [Refactoring] Migrate UsersRepositoryManagementTest to JUnit5
---
 .../user/memory/UsersRepositoryManagementTest.java | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/server/data/data-memory/src/test/java/org/apache/james/user/memory/UsersRepositoryManagementTest.java b/server/data/data-memory/src/test/java/org/apache/james/user/memory/UsersRepositoryManagementTest.java
index fb7fa30..89a998e 100644
--- a/server/data/data-memory/src/test/java/org/apache/james/user/memory/UsersRepositoryManagementTest.java
+++ b/server/data/data-memory/src/test/java/org/apache/james/user/memory/UsersRepositoryManagementTest.java
@@ -28,17 +28,17 @@ import org.apache.james.core.Username;
 import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.lib.UsersRepositoryManagement;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class UsersRepositoryManagementTest {
-    private static final DomainList NO_DOMAIN_LIST = null;
+class UsersRepositoryManagementTest {
+    static final DomainList NO_DOMAIN_LIST = null;
 
-    private UsersRepository usersRepository;
-    private UsersRepositoryManagement userManagement;
+    UsersRepository usersRepository;
+    UsersRepositoryManagement userManagement;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         usersRepository = MemoryUsersRepository.withoutVirtualHosting(NO_DOMAIN_LIST);
 
         userManagement = new UsersRepositoryManagement();
@@ -46,7 +46,7 @@ public class UsersRepositoryManagementTest {
     }
 
     @Test
-    public void testUserCount() throws Exception {
+    void testUserCount() throws Exception {
         assertThat(userManagement.countUsers()).describedAs("no user yet").isEqualTo(0);
         usersRepository.addUser(Username.of("testcount1"), "testCount");
         assertThat(userManagement.countUsers()).describedAs("1 user").isEqualTo(1);
@@ -57,7 +57,7 @@ public class UsersRepositoryManagementTest {
     }
 
     @Test
-    public void testAddUserAndVerify() throws Exception {
+    void testAddUserAndVerify() throws Exception {
         usersRepository.addUser(Username.of("testcount1"), "testCount");
         assertThat(userManagement.verifyExists("testNotAdded")).describedAs("user not there").isFalse();
         assertThat(userManagement.verifyExists("testCount1")).describedAs("user is there").isTrue();
@@ -66,7 +66,7 @@ public class UsersRepositoryManagementTest {
     }
 
     @Test
-    public void testDelUser() throws Exception {
+    void testDelUser() throws Exception {
         usersRepository.addUser(Username.of("testdel"), "test");
         assertThat(userManagement.verifyExists("testNotDeletable")).describedAs("user not there").isFalse();
         assertThat(userManagement.verifyExists("testdel")).describedAs("user is there").isTrue();
@@ -75,7 +75,7 @@ public class UsersRepositoryManagementTest {
     }
 
     @Test
-    public void testListUsers() throws Exception {
+    void testListUsers() throws Exception {
         Username[] usersArray = new Username[]{Username.of("ccc"), Username.of("aaa"), Username.of("dddd"), Username.of("bbbbb")};
         List<Username> users = Arrays.asList(usersArray);
 
@@ -94,7 +94,7 @@ public class UsersRepositoryManagementTest {
     }
 
     @Test
-    public void testSetPassword() throws Exception {
+    void testSetPassword() throws Exception {
         userManagement.addUser("testpwduser", "pwd1");
 
         assertThat(usersRepository.test(Username.of("testpwduser"), "pwd1")).describedAs("initial password").isTrue();


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


[james-project] 18/26: [Refactoring] Migrate ConfigurationItemsAddedTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0572e22f755591732e76572f5b6ec56adc315c0a
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:38:32 2020 +0700

    [Refactoring] Migrate ConfigurationItemsAddedTest to JUnit5
---
 .../eventsourcing/events/ConfigurationItemsAddedTest.java  | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
index 3a62657..192e5b3 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
@@ -25,40 +25,40 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import org.apache.james.core.Domain;
 import org.apache.james.dlp.eventsourcing.aggregates.DLPAggregateId;
 import org.apache.james.eventsourcing.EventId;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class ConfigurationItemsAddedTest {
+class ConfigurationItemsAddedTest {
 
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(ConfigurationItemsAdded.class)
             .verify();
     }
 
     @Test
-    public void constructorShouldThrowWhenNullAggregateId() {
+    void constructorShouldThrowWhenNullAggregateId() {
         assertThatThrownBy(() -> new ConfigurationItemsAdded(null, EventId.first(), ImmutableList.of(RULE)))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenNullEventId() {
+    void constructorShouldThrowWhenNullEventId() {
         assertThatThrownBy(() -> new ConfigurationItemsAdded(new DLPAggregateId(Domain.LOCALHOST), null, ImmutableList.of(RULE)))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenNullRules() {
+    void constructorShouldThrowWhenNullRules() {
         assertThatThrownBy(() -> new ConfigurationItemsAdded(new DLPAggregateId(Domain.LOCALHOST), EventId.first(), null))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void constructorShouldThrowWhenEmptyRulesList() {
+    void constructorShouldThrowWhenEmptyRulesList() {
         assertThatThrownBy(() -> new ConfigurationItemsAdded(new DLPAggregateId(Domain.LOCALHOST), EventId.first(), ImmutableList.of()))
             .isInstanceOf(IllegalArgumentException.class);
     }


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


[james-project] 11/26: [Refactoring] Migrate AccountIdTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5c9da37670fde0cd3b973d25bb147b25d30be9a9
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:21:32 2020 +0700

    [Refactoring] Migrate AccountIdTest to JUnit5
---
 .../james/jmap/api/vacation/AccountIdTest.java     | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AccountIdTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AccountIdTest.java
index 4362273..ac4aa25 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AccountIdTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AccountIdTest.java
@@ -20,25 +20,27 @@
 package org.apache.james.jmap.api.vacation;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class AccountIdTest {
+class AccountIdTest {
+    static final String IDENTIFIER = "id";
 
-    public static final String IDENTIFIER = "id";
-
-    @Test(expected = IllegalArgumentException.class)
-    public void createShouldThrowOnNullIdentifier() {
-        AccountId.fromString(null);
+    @Test
+    void createShouldThrowOnNullIdentifier() {
+        assertThatThrownBy(() -> AccountId.fromString(null))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void createShouldThrowOnEmptyIdentifier() {
-        AccountId.fromString("");
+    @Test
+    void createShouldThrowOnEmptyIdentifier() {
+        assertThatThrownBy(() -> AccountId.fromString(""))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void createShouldWork() {
+    void createShouldWork() {
         assertThat(AccountId.fromString(IDENTIFIER).getIdentifier()).isEqualTo(IDENTIFIER);
     }
 


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


[james-project] 01/26: [Refactoring] Migrate TestExternalHostSystem to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 670fad228dfd6621e027e23366b2691f1c303a89
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 31 16:59:41 2020 +0700

    [Refactoring] Migrate TestExternalHostSystem to JUnit5
---
 .../apache/james/mpt/TestExternalHostSystem.java   | 36 +++++++++++-----------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/mpt/core/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java b/mpt/core/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
index 72360dd..44e501d 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
@@ -34,27 +34,27 @@ import org.apache.james.mpt.api.UserAdder;
 import org.apache.james.mpt.host.ExternalHostSystem;
 import org.apache.james.mpt.monitor.NullMonitor;
 import org.apache.james.mpt.session.ExternalSessionFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class TestExternalHostSystem {
+class TestExternalHostSystem {
     
-    private static final Username USER = Username.of("USERNAME");
+    static final Username USER = Username.of("USERNAME");
 
-    private static final String PASSWORD = "SOME PASSWORD";
+    static final String PASSWORD = "SOME PASSWORD";
 
-    private static final String SHABANG = "This Is The Shabang";
+    static final String SHABANG = "This Is The Shabang";
 
-    private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT);
+    static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT);
 
-    private DiscardProtocol protocol;
-    private DiscardProtocol.Record record;
-    private Continuation continuation;
-    private UserAdder userAdder;
+    DiscardProtocol protocol;
+    DiscardProtocol.Record record;
+    Continuation continuation;
+    UserAdder userAdder;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         protocol = new DiscardProtocol();
         protocol.start();
         record = protocol.recordNext();
@@ -62,13 +62,13 @@ public class TestExternalHostSystem {
         userAdder = mock(UserAdder.class);
     }
 
-    @After
-    public void tearDown() {
+    @AfterEach
+    void tearDown() {
         protocol.stop();
     }
 
     @Test
-    public void testWrite() throws Exception {
+    void testWrite() throws Exception {
         Session session = newSession(SHABANG);
         final String in = "Hello, World";
         session.writeLine(in);
@@ -78,7 +78,7 @@ public class TestExternalHostSystem {
     }
 
     @Test
-    public void testAddUser() throws Exception {
+    void testAddUser() throws Exception {
         ExternalHostSystem system = buildSystem(SHABANG);
         system.addUser(USER, PASSWORD);
         verify(userAdder, times(1)).addUser(USER, PASSWORD);


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


[james-project] 13/26: [Refactoring] Migrate VacationTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 33df080a755fd8f2d465f216ed1ec1937971fc04
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:29:34 2020 +0700

    [Refactoring] Migrate VacationTest to JUnit5
---
 .../james/jmap/api/vacation/VacationTest.java      | 67 +++++++++++-----------
 1 file changed, 34 insertions(+), 33 deletions(-)

diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationTest.java
index ed2e0e0..708dc5d 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationTest.java
@@ -20,23 +20,23 @@
 package org.apache.james.jmap.api.vacation;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.time.ZonedDateTime;
 import java.util.Optional;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class VacationTest {
-
-    public static final ZonedDateTime DATE_TIME_2016 = ZonedDateTime.parse("2016-10-09T08:07:06+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_TIME_2017 = ZonedDateTime.parse("2017-10-09T08:07:06+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_TIME_2017_1MS = ZonedDateTime.parse("2017-10-09T08:07:06.001+07:00[Asia/Vientiane]");
-    public static final ZonedDateTime DATE_TIME_2018 = ZonedDateTime.parse("2018-10-09T08:07:06+07:00[Asia/Vientiane]");
-    public static final String TEXT_BODY = "text is required when enabled";
-    public static final String HTML_BODY = "<b>HTML body</b>";
+class VacationTest {
+    static final ZonedDateTime DATE_TIME_2016 = ZonedDateTime.parse("2016-10-09T08:07:06+07:00[Asia/Vientiane]");
+    static final ZonedDateTime DATE_TIME_2017 = ZonedDateTime.parse("2017-10-09T08:07:06+07:00[Asia/Vientiane]");
+    static final ZonedDateTime DATE_TIME_2017_1MS = ZonedDateTime.parse("2017-10-09T08:07:06.001+07:00[Asia/Vientiane]");
+    static final ZonedDateTime DATE_TIME_2018 = ZonedDateTime.parse("2018-10-09T08:07:06+07:00[Asia/Vientiane]");
+    static final String TEXT_BODY = "text is required when enabled";
+    static final String HTML_BODY = "<b>HTML body</b>";
 
     @Test
-    public void disabledVacationsAreNotActive() {
+    void disabledVacationsAreNotActive() {
         assertThat(
             Vacation.builder()
                 .enabled(false)
@@ -46,7 +46,7 @@ public class VacationTest {
     }
 
     @Test
-    public void enabledVacationWithoutDatesIsActive() {
+    void enabledVacationWithoutDatesIsActive() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -57,7 +57,7 @@ public class VacationTest {
     }
 
     @Test
-    public void rangeShouldBeInclusiveOnFromDate() {
+    void rangeShouldBeInclusiveOnFromDate() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -69,7 +69,7 @@ public class VacationTest {
     }
 
     @Test
-    public void rangeShouldBeInclusiveOnToDate() {
+    void rangeShouldBeInclusiveOnToDate() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -81,7 +81,7 @@ public class VacationTest {
     }
 
     @Test
-    public void vacationShouldBeActiveDuringRange() {
+    void vacationShouldBeActiveDuringRange() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -94,7 +94,7 @@ public class VacationTest {
     }
 
     @Test
-    public void vacationShouldNotBeActiveAfterRange() {
+    void vacationShouldNotBeActiveAfterRange() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -107,7 +107,7 @@ public class VacationTest {
     }
 
     @Test
-    public void vacationShouldNotBeActiveBeforeRange() {
+    void vacationShouldNotBeActiveBeforeRange() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -119,19 +119,20 @@ public class VacationTest {
             .isFalse();
     }
 
-    @Test(expected = NullPointerException.class)
-    public void isActiveAtDateShouldThrowOnNullValue() {
-        Vacation.builder()
-            .enabled(true)
-            .textBody(TEXT_BODY)
-            .fromDate(Optional.of(DATE_TIME_2016))
-            .toDate(Optional.of(DATE_TIME_2016))
-            .build()
-            .isActiveAtDate(null);
+    @Test
+    void isActiveAtDateShouldThrowOnNullValue() {
+        assertThatThrownBy(() -> Vacation.builder()
+                .enabled(true)
+                .textBody(TEXT_BODY)
+                .fromDate(Optional.of(DATE_TIME_2016))
+                .toDate(Optional.of(DATE_TIME_2016))
+                .build()
+                .isActiveAtDate(null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void vacationShouldBeActiveAfterFromDate() {
+    void vacationShouldBeActiveAfterFromDate() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -143,7 +144,7 @@ public class VacationTest {
     }
 
     @Test
-    public void vacationShouldNotBeActiveBeforeFromDate() {
+    void vacationShouldNotBeActiveBeforeFromDate() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -155,7 +156,7 @@ public class VacationTest {
     }
 
     @Test
-    public void vacationShouldNotBeActiveAfterToDate() {
+    void vacationShouldNotBeActiveAfterToDate() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -167,7 +168,7 @@ public class VacationTest {
     }
 
     @Test
-    public void vacationShouldBeActiveBeforeToDate() {
+    void vacationShouldBeActiveBeforeToDate() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -179,7 +180,7 @@ public class VacationTest {
     }
 
     @Test
-    public void isActiveAtDateShouldHaveMillisecondPrecision() {
+    void isActiveAtDateShouldHaveMillisecondPrecision() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -191,7 +192,7 @@ public class VacationTest {
     }
 
     @Test
-    public void textBodyShouldBeEnoughToBuildAnActivatedVacation() {
+    void textBodyShouldBeEnoughToBuildAnActivatedVacation() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -202,7 +203,7 @@ public class VacationTest {
     }
 
     @Test
-    public void htmlBodyShouldBeEnoughToBuildAnActivatedVacation() {
+    void htmlBodyShouldBeEnoughToBuildAnActivatedVacation() {
         assertThat(
             Vacation.builder()
                 .enabled(true)
@@ -213,7 +214,7 @@ public class VacationTest {
     }
 
     @Test
-    public void textOrHtmlBodyShouldNotBeRequiredOnUnactivatedVacation() {
+    void textOrHtmlBodyShouldNotBeRequiredOnUnactivatedVacation() {
         assertThat(
             Vacation.builder()
                 .enabled(false)


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


[james-project] 16/26: [Refactoring] Migrate ClearCommandTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 04f1ad7c04bd9af2018be54f8efb662cc11a1203
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 15:36:43 2020 +0700

    [Refactoring] Migrate ClearCommandTest to JUnit5
---
 .../james/dlp/eventsourcing/commands/ClearCommandTest.java     | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
index 34a1289..b3d7270 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
@@ -21,22 +21,20 @@ package org.apache.james.dlp.eventsourcing.commands;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class ClearCommandTest {
-
+class ClearCommandTest {
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(ClearCommand.class)
             .verify();
     }
 
     @Test
-    public void constructorShouldThrowWhenNullDomain() {
+    void constructorShouldThrowWhenNullDomain() {
         assertThatThrownBy(() -> new ClearCommand(null))
             .isInstanceOf(NullPointerException.class);
     }
-
 }
\ No newline at end of file


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


[james-project] 05/26: [Refactoring] Migrate ScriptTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f52940d38029e16fffc3d0f09c9cb53a8bfcbbdf
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Aug 12 15:36:01 2020 +0700

    [Refactoring] Migrate ScriptTest to JUnit5
---
 .../james/sieve/cassandra/model/ScriptTest.java    | 71 ++++++++++------------
 1 file changed, 32 insertions(+), 39 deletions(-)

diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/ScriptTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/ScriptTest.java
index 718c824..327d8b5 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/ScriptTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/model/ScriptTest.java
@@ -20,60 +20,53 @@
 package org.apache.james.sieve.cassandra.model;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.nio.charset.StandardCharsets;
 
 import org.apache.james.sieverepository.api.ScriptContent;
 import org.apache.james.sieverepository.api.ScriptName;
 import org.apache.james.sieverepository.api.ScriptSummary;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class ScriptTest {
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+class ScriptTest {
 
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(Script.class).verify();
     }
 
     @Test
-    public void buildShouldThrowOnMissingContent() {
-        expectedException.expect(IllegalStateException.class);
-
-        Script.builder()
-            .name("name")
-            .isActive(false)
-            .build();
+    void buildShouldThrowOnMissingContent() {
+        assertThatThrownBy(() -> Script.builder()
+                .name("name")
+                .isActive(false)
+                .build())
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void buildShouldThrowOnMissingActivation() {
-        expectedException.expect(IllegalStateException.class);
-
-        Script.builder()
-            .name("name")
-            .content("content")
-            .build();
+    void buildShouldThrowOnMissingActivation() {
+        assertThatThrownBy(() -> Script.builder()
+                .name("name")
+                .content("content")
+                .build())
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void buildShouldThrowOnMissingName() {
-        expectedException.expect(IllegalStateException.class);
-
-        Script.builder()
-            .content("content")
-            .isActive(false)
-            .build();
+    void buildShouldThrowOnMissingName() {
+        assertThatThrownBy(() -> Script.builder()
+                .content("content")
+                .isActive(false)
+                .build())
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void buildShouldPreserveName() {
+    void buildShouldPreserveName() {
         ScriptName name = new ScriptName("name");
         assertThat(
             Script.builder()
@@ -86,7 +79,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void buildShouldPreserveContent() {
+    void buildShouldPreserveContent() {
         ScriptContent content = new ScriptContent("content");
         assertThat(
             Script.builder()
@@ -99,7 +92,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void buildShouldPreserveActiveWhenFalse() {
+    void buildShouldPreserveActiveWhenFalse() {
         assertThat(
             Script.builder()
                 .name("name")
@@ -111,7 +104,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void buildShouldPreserveActiveWhenTrue() {
+    void buildShouldPreserveActiveWhenTrue() {
         assertThat(
             Script.builder()
                 .name("name")
@@ -123,7 +116,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void buildShouldComputeSizeWhenAbsent() {
+    void buildShouldComputeSizeWhenAbsent() {
         String content = "content";
         assertThat(
             Script.builder()
@@ -136,7 +129,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void buildShouldPreserveSize() {
+    void buildShouldPreserveSize() {
         long size = 48L;
         assertThat(
             Script.builder()
@@ -150,7 +143,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void toSummaryShouldWork() {
+    void toSummaryShouldWork() {
         String name = "name";
         boolean isActive = true;
         assertThat(
@@ -165,7 +158,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void copyOfShouldAllowModifyingName() {
+    void copyOfShouldAllowModifyingName() {
         String content = "content";
         String newName = "newName";
 
@@ -188,7 +181,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void copyOfShouldAllowModifyingActivation() {
+    void copyOfShouldAllowModifyingActivation() {
         String content = "content";
         String name = "name";
 
@@ -211,7 +204,7 @@ public class ScriptTest {
     }
 
     @Test
-    public void copyOfShouldAllowModifyingContent() {
+    void copyOfShouldAllowModifyingContent() {
         String name = "name";
         String content = "content";
 


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


[james-project] 23/26: [Refactoring] Migrate AbstractDomainListPrivateMethodsTest to JUnit5

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 666c3afdc67bda0d5f1a87f66bbeab04e53f5074
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Aug 13 16:16:15 2020 +0700

    [Refactoring] Migrate AbstractDomainListPrivateMethodsTest to JUnit5
---
 .../lib/AbstractDomainListPrivateMethodsTest.java  | 64 +++++++++++-----------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListPrivateMethodsTest.java b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListPrivateMethodsTest.java
index 9c48401..8dfe84f 100644
--- a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListPrivateMethodsTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListPrivateMethodsTest.java
@@ -32,19 +32,19 @@ import java.util.List;
 import org.apache.james.core.Domain;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.domainlist.api.AutoDetectedDomainRemovalException;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
-public class AbstractDomainListPrivateMethodsTest {
-    private MyDomainList domainList;
-    private DNSService dnsService;
-    private EnvDetector envDetector;
+class AbstractDomainListPrivateMethodsTest {
+    MyDomainList domainList;
+    DNSService dnsService;
+    EnvDetector envDetector;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         dnsService = mock(DNSService.class);
         envDetector = mock(EnvDetector.class);
         domainList = new MyDomainList(dnsService, envDetector);
@@ -81,7 +81,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void setDefaultDomainShouldSetFromConfigurationWhenDifferentFromLocalhost() throws Exception {
+    void setDefaultDomainShouldSetFromConfigurationWhenDifferentFromLocalhost() throws Exception {
         String expectedDefaultDomain = "myDomain.org";
 
         domainList.configureDefaultDomain(Domain.of(expectedDefaultDomain));
@@ -90,7 +90,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void setDefaultDomainShouldSetFromHostnameWhenEqualsToLocalhost() throws Exception {
+    void setDefaultDomainShouldSetFromHostnameWhenEqualsToLocalhost() throws Exception {
         Domain expectedDefaultDomain = Domain.of(InetAddress.getLocalHost().getHostName());
         domainList.configureDefaultDomain(Domain.LOCALHOST);
 
@@ -98,7 +98,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void setDefaultDomainShouldCreateFromHostnameWhenEqualsToLocalhost() throws Exception {
+    void setDefaultDomainShouldCreateFromHostnameWhenEqualsToLocalhost() throws Exception {
         Domain expectedDefaultDomain = Domain.of(InetAddress.getLocalHost().getHostName());
         domainList.configureDefaultDomain(expectedDefaultDomain);
 
@@ -106,7 +106,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void setDefaultDomainShouldNotCreateTwiceWhenCallingTwoTimes() throws Exception {
+    void setDefaultDomainShouldNotCreateTwiceWhenCallingTwoTimes() throws Exception {
         Domain expectedDefaultDomain = Domain.of(InetAddress.getLocalHost().getHostName());
         domainList.configureDefaultDomain(expectedDefaultDomain);
         domainList.configureDefaultDomain(expectedDefaultDomain);
@@ -115,7 +115,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void setDefaultDomainShouldAddDomainWhenNotContained() throws Exception {
+    void setDefaultDomainShouldAddDomainWhenNotContained() throws Exception {
         Domain expectedDefaultDomain = Domain.of("myDomain.org");
 
         domainList.configureDefaultDomain(expectedDefaultDomain);
@@ -124,7 +124,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void setDefaultDomainShouldNotFailWhenDomainContained() throws Exception {
+    void setDefaultDomainShouldNotFailWhenDomainContained() throws Exception {
         Domain expectedDefaultDomain = Domain.of("myDomain.org");
 
         domainList.addDomain(expectedDefaultDomain);
@@ -134,7 +134,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldNotDetectDomainsWhenDisabled() throws Exception {
+    void getDomainsShouldNotDetectDomainsWhenDisabled() throws Exception {
         Domain domain = Domain.of("domain.tld");
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(false)
@@ -145,7 +145,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldNotInteractWithDNSWhenDisabled() throws Exception {
+    void getDomainsShouldNotInteractWithDNSWhenDisabled() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(false)
             .autoDetectIp(false));
@@ -155,7 +155,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldContainDetectedDomains() throws Exception {
+    void getDomainsShouldContainDetectedDomains() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(false));
@@ -168,7 +168,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldContainDetectedDomainsAndIps() throws Exception {
+    void getDomainsShouldContainDetectedDomainsAndIps() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(true));
@@ -185,7 +185,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldContainDetectedDomainsAndIpsOfAddedDomains() throws Exception {
+    void getDomainsShouldContainDetectedDomainsAndIpsOfAddedDomains() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(true));
@@ -210,7 +210,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldNotReturnDuplicates() throws Exception {
+    void getDomainsShouldNotReturnDuplicates() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(true));
@@ -234,7 +234,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void getDomainsShouldListAddedDomain() throws Exception {
+    void getDomainsShouldListAddedDomain() throws Exception {
         Domain defaultDomain = Domain.of("default.tld");
         Domain domain = Domain.of("added.tld");
 
@@ -249,7 +249,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void containsDomainShouldReturnDetectedIp() throws Exception {
+    void containsDomainShouldReturnDetectedIp() throws Exception {
         String detected = "detected.tld";
         String detectedIp = "148.25.32.1";
         when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1"));
@@ -262,7 +262,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void containsDomainShouldReturnTrueWhenDomainIsContained() throws Exception {
+    void containsDomainShouldReturnTrueWhenDomainIsContained() throws Exception {
         Domain domain = Domain.of("added.tld");
         domainList.addDomain(domain);
         domainList.configure(DomainListConfiguration.builder()
@@ -273,7 +273,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void containsDomainShouldReturnFalseWhenDomainIsNotContained() throws Exception {
+    void containsDomainShouldReturnFalseWhenDomainIsNotContained() throws Exception {
         Domain domain = Domain.of("added.tld");
 
         domainList.configure(DomainListConfiguration.builder()
@@ -284,7 +284,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void containsDomainShouldNotInteractWithDNSWhenDisabled() throws Exception {
+    void containsDomainShouldNotInteractWithDNSWhenDisabled() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(false)
             .autoDetectIp(false));
@@ -294,7 +294,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void containsDomainShouldReturnDetectedDomains() throws Exception {
+    void containsDomainShouldReturnDetectedDomains() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(false));
@@ -307,7 +307,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void envDomainShouldBeAddedUponConfiguration() throws Exception {
+    void envDomainShouldBeAddedUponConfiguration() throws Exception {
         String envDomain = "env.tld";
         when(envDetector.getEnv(AbstractDomainList.ENV_DOMAIN)).thenReturn(envDomain);
 
@@ -320,7 +320,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void removeDomainShouldThrowWhenRemovingAutoDetectedDomains() throws Exception {
+    void removeDomainShouldThrowWhenRemovingAutoDetectedDomains() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(true)
             .autoDetectIp(false));
@@ -334,7 +334,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void removeDomainShouldThrowWhenRemovingAutoDetectedIps() throws Exception {
+    void removeDomainShouldThrowWhenRemovingAutoDetectedIps() throws Exception {
         String detected = "detected.tld";
         String detectedIp = "148.25.32.1";
         when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1"));
@@ -348,7 +348,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void removeDomainShouldThrowWhenRemovingDefaultDomain() throws Exception {
+    void removeDomainShouldThrowWhenRemovingDefaultDomain() throws Exception {
         Domain defaultDomain = Domain.of("default.tld");
         domainList.configureDefaultDomain(defaultDomain);
 
@@ -357,7 +357,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void configuredDomainShouldBeAddedUponConfiguration() throws Exception {
+    void configuredDomainShouldBeAddedUponConfiguration() throws Exception {
         Domain domain1 = Domain.of("conf1.tld");
         Domain domain2 = Domain.of("conf2.tld");
 
@@ -370,7 +370,7 @@ public class AbstractDomainListPrivateMethodsTest {
     }
 
     @Test
-    public void configureShouldNotAttemptToChangeLocalHostDefaultDomainWhenNoAutoDetect() throws Exception {
+    void configureShouldNotAttemptToChangeLocalHostDefaultDomainWhenNoAutoDetect() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
             .autoDetect(false)
             .autoDetectIp(false)


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