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 bt...@apache.org on 2019/11/11 08:05:09 UTC

[james-project] 09/09: [Refactoring] Migrate tests in JUnit 4 to JUnit 5 in backends-elasticsearch module

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

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

commit 379a835d6b44d615b25c2bbee2db4345260b911b
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Nov 8 17:35:54 2019 +0700

    [Refactoring] Migrate tests in JUnit 4 to JUnit 5 in backends-elasticsearch module
---
 .../es/ClientProviderImplConnectionTest.java       | 42 ++++++++++----
 .../james/backends/es/ClientProviderTest.java      |  6 +-
 .../backends/es/DockerElasticSearchExtension.java  | 66 ++++++++++++++++++++++
 .../es/ElasticSearchConfigurationTest.java         | 56 +++++++++---------
 .../es/ElasticSearchHealthCheckConnectionTest.java | 20 +++----
 .../backends/es/ElasticSearchHealthCheckTest.java  | 16 +++---
 .../backends/es/ElasticSearchIndexerTest.java      | 50 ++++++++--------
 .../backends/es/IndexCreationFactoryTest.java      | 30 +++++-----
 .../james/backends/es/NodeMappingFactoryTest.java  | 26 ++++-----
 .../backends/es/search/ScrolledSearchTest.java     | 34 +++++------
 10 files changed, 216 insertions(+), 130 deletions(-)

diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
index 042cbfd..db6ae42 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
@@ -30,30 +30,50 @@ import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestHighLevelClient;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ClientProviderImplConnectionTest {
+class ClientProviderImplConnectionTest {
     private static final Logger LOGGER = LoggerFactory.getLogger(ClientProviderImplConnectionTest.class);
     private static final int ES_APPLICATIVE_PORT = 9200;
 
-    @ClassRule
-    public static DockerContainer es1 = DockerContainer.fromName(Images.ELASTICSEARCH_6)
+    static DockerContainer es1 = DockerContainer.fromName(Images.ELASTICSEARCH_6)
         .withEnv("discovery.type", "single-node")
         .withAffinityToContainer()
         .withExposedPorts(ES_APPLICATIVE_PORT);
 
-    @Rule
-    public DockerContainer es2 = DockerContainer.fromName(Images.ELASTICSEARCH_6)
+    DockerContainer es2 = DockerContainer.fromName(Images.ELASTICSEARCH_6)
         .withEnv("discovery.type", "single-node")
         .withAffinityToContainer()
         .withExposedPorts(ES_APPLICATIVE_PORT);
 
+    @BeforeAll
+    static void setUpClass() {
+        es1.start();
+    }
+
+    @BeforeEach
+    void setUp() {
+        es2.start();
+    }
+
+    @AfterEach
+    void tearDown() {
+        es2.stop();
+    }
+
+    @AfterAll
+    static void tearDownClass() {
+        es1.stop();
+    }
+
     @Test
-    public void connectingASingleServerShouldWork() {
+    void connectingASingleServerShouldWork() {
         ElasticSearchConfiguration configuration = ElasticSearchConfiguration.builder()
             .addHost(Host.from(es1.getContainerIp(), ES_APPLICATIVE_PORT))
             .build();
@@ -65,7 +85,7 @@ public class ClientProviderImplConnectionTest {
     }
 
     @Test
-    public void connectingAClusterShouldWork() {
+    void connectingAClusterShouldWork() {
         ElasticSearchConfiguration configuration = ElasticSearchConfiguration.builder()
             .addHost(Host.from(es1.getContainerIp(), ES_APPLICATIVE_PORT))
             .addHost(Host.from(es2.getContainerIp(), ES_APPLICATIVE_PORT))
@@ -78,7 +98,7 @@ public class ClientProviderImplConnectionTest {
     }
 
     @Test
-    public void connectingAClusterWithAFailedNodeShouldWork() {
+    void connectingAClusterWithAFailedNodeShouldWork() {
         String es1Ip = es1.getContainerIp();
         String es2Ip = es2.getContainerIp();
         es2.stop();
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderTest.java
index aef7c35..ca80592 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderTest.java
@@ -21,12 +21,12 @@ package org.apache.james.backends.es;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class ClientProviderTest {
+class ClientProviderTest {
 
     @Test
-    public void constructorShouldThrowOnNull() {
+    void constructorShouldThrowOnNull() {
         assertThatThrownBy(() -> new ClientProvider(null))
                 .isInstanceOf(NullPointerException.class);
     }
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearchExtension.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearchExtension.java
new file mode 100644
index 0000000..b9051a0
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearchExtension.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.backends.es;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+public class DockerElasticSearchExtension implements AfterAllCallback, BeforeAllCallback, AfterEachCallback, ParameterResolver {
+
+    private final DockerElasticSearch elasticSearch = DockerElasticSearchSingleton.INSTANCE;
+
+    @Override
+    public void beforeAll(ExtensionContext context) throws Exception {
+        elasticSearch.start();
+    }
+
+    @Override
+    public void afterEach(ExtensionContext context) throws Exception {
+        elasticSearch.cleanUpData();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext context) throws Exception {
+        elasticSearch.stop();
+    }
+
+    @Override
+    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return (parameterContext.getParameter().getType() == DockerElasticSearch.class);
+    }
+
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return elasticSearch;
+    }
+
+    public void awaitForElasticSearch() {
+        elasticSearch.flushIndices();
+    }
+
+    public DockerElasticSearch getDockerElasticSearch() {
+        return elasticSearch;
+    }
+}
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
index fb2f0e0..befa774 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
@@ -28,22 +28,22 @@ import org.apache.commons.configuration2.PropertiesConfiguration;
 import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.james.util.Host;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class ElasticSearchConfigurationTest {
+class ElasticSearchConfigurationTest {
 
     @Test
-    public void elasticSearchConfigurationShouldRespectBeanContract() {
+    void elasticSearchConfigurationShouldRespectBeanContract() {
         EqualsVerifier.forClass(ElasticSearchConfiguration.class)
             .verify();
     }
 
     @Test
-    public void getNbReplicaShouldReturnConfiguredValue() throws ConfigurationException {
+    void getNbReplicaShouldReturnConfiguredValue() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         int value = 36;
         configuration.addProperty("elasticsearch.nb.replica", value);
@@ -56,7 +56,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getNbReplicaShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+    void getNbReplicaShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
 
@@ -67,7 +67,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getWaitForActiveShardsShouldReturnConfiguredValue() throws ConfigurationException {
+    void getWaitForActiveShardsShouldReturnConfiguredValue() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         int value = 36;
         configuration.addProperty("elasticsearch.index.waitForActiveShards", value);
@@ -80,7 +80,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getWaitForActiveShardsShouldReturnConfiguredValueWhenZero() throws ConfigurationException {
+    void getWaitForActiveShardsShouldReturnConfiguredValueWhenZero() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         int value = 0;
         configuration.addProperty("elasticsearch.index.waitForActiveShards", value);
@@ -93,7 +93,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getWaitForActiveShardsShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+    void getWaitForActiveShardsShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
 
@@ -105,7 +105,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getNbShardsShouldReturnConfiguredValue() throws ConfigurationException {
+    void getNbShardsShouldReturnConfiguredValue() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         int value = 36;
         configuration.addProperty("elasticsearch.nb.shards", value);
@@ -118,7 +118,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getNbShardsShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+    void getNbShardsShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
 
@@ -129,7 +129,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getMaxRetriesShouldReturnConfiguredValue() throws ConfigurationException {
+    void getMaxRetriesShouldReturnConfiguredValue() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         int value = 36;
         configuration.addProperty("elasticsearch.retryConnection.maxRetries", value);
@@ -142,7 +142,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getMaxRetriesShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+    void getMaxRetriesShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
 
@@ -153,7 +153,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getMinDelayShouldReturnConfiguredValue() throws ConfigurationException {
+    void getMinDelayShouldReturnConfiguredValue() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         int value = 36;
         configuration.addProperty("elasticsearch.retryConnection.minDelay", value);
@@ -166,7 +166,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getMinDelayShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+    void getMinDelayShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
 
@@ -177,7 +177,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getHostsShouldReturnConfiguredHostsWhenNoPort() throws ConfigurationException {
+    void getHostsShouldReturnConfiguredHostsWhenNoPort() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         String hostname = "myHost";
         configuration.addProperty("elasticsearch.hosts", hostname);
@@ -189,7 +189,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getHostsShouldReturnConfiguredHostsWhenListIsUsed() throws ConfigurationException {
+    void getHostsShouldReturnConfiguredHostsWhenListIsUsed() throws ConfigurationException {
         String hostname = "myHost";
         String hostname2 = "myOtherHost";
         int port = 2154;
@@ -205,7 +205,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getHostsShouldReturnConfiguredHosts() throws ConfigurationException {
+    void getHostsShouldReturnConfiguredHosts() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         String hostname = "myHost";
         int port = 2154;
@@ -218,7 +218,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void getHostsShouldReturnConfiguredMasterHost() throws ConfigurationException {
+    void getHostsShouldReturnConfiguredMasterHost() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         String hostname = "myHost";
         configuration.addProperty("elasticsearch.masterHost", hostname);
@@ -232,7 +232,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void validateHostsConfigurationOptionsShouldThrowWhenNoHostSpecify() {
+    void validateHostsConfigurationOptionsShouldThrowWhenNoHostSpecify() {
         assertThatThrownBy(() ->
             ElasticSearchConfiguration.validateHostsConfigurationOptions(
                 Optional.empty(),
@@ -245,7 +245,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void validateHostsConfigurationOptionsShouldThrowWhenMonoAndMultiHostSpecified() {
+    void validateHostsConfigurationOptionsShouldThrowWhenMonoAndMultiHostSpecified() {
         assertThatThrownBy(() ->
             ElasticSearchConfiguration.validateHostsConfigurationOptions(
                 Optional.of("localhost"),
@@ -256,7 +256,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutPort() {
+    void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutPort() {
         assertThatThrownBy(() ->
             ElasticSearchConfiguration.validateHostsConfigurationOptions(
                 Optional.of("localhost"),
@@ -268,7 +268,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutAddress() {
+    void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutAddress() {
         assertThatThrownBy(() ->
         ElasticSearchConfiguration.validateHostsConfigurationOptions(
             Optional.empty(),
@@ -280,7 +280,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void validateHostsConfigurationOptionsShouldAcceptMonoHostConfiguration() throws Exception {
+    void validateHostsConfigurationOptionsShouldAcceptMonoHostConfiguration() throws Exception {
         ElasticSearchConfiguration.validateHostsConfigurationOptions(
             Optional.of("localhost"),
             Optional.of(9200),
@@ -288,7 +288,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void validateHostsConfigurationOptionsShouldAcceptMultiHostConfiguration() throws Exception {
+    void validateHostsConfigurationOptionsShouldAcceptMultiHostConfiguration() throws Exception {
         ElasticSearchConfiguration.validateHostsConfigurationOptions(
             Optional.empty(),
             Optional.empty(),
@@ -296,7 +296,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void nbReplicaShouldThrowWhenNegative() {
+    void nbReplicaShouldThrowWhenNegative() {
         assertThatThrownBy(() ->
                 ElasticSearchConfiguration.builder()
                         .nbReplica(-1))
@@ -304,7 +304,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void waitForActiveShardsShouldThrowWhenNegative() {
+    void waitForActiveShardsShouldThrowWhenNegative() {
         assertThatThrownBy(() ->
             ElasticSearchConfiguration.builder()
                 .waitForActiveShards(-1))
@@ -312,7 +312,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void nbShardsShouldThrowWhenNegative() {
+    void nbShardsShouldThrowWhenNegative() {
         assertThatThrownBy(() ->
                 ElasticSearchConfiguration.builder()
                         .nbShards(-1))
@@ -320,7 +320,7 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void nbShardsShouldThrowWhenZero() {
+    void nbShardsShouldThrowWhenZero() {
         assertThatThrownBy(() ->
                 ElasticSearchConfiguration.builder()
                         .nbShards(0))
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckConnectionTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckConnectionTest.java
index 448390f..51e1b2e 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckConnectionTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckConnectionTest.java
@@ -23,33 +23,33 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.time.Duration;
 
 import org.elasticsearch.client.RestHighLevelClient;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.collect.ImmutableSet;
 
-public class ElasticSearchHealthCheckConnectionTest {
+class ElasticSearchHealthCheckConnectionTest {
     private static final Duration REQUEST_TIMEOUT = Duration.ofSeconds(5);
 
-    @Rule
-    public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
+    @RegisterExtension
+    public DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
     private ElasticSearchHealthCheck elasticSearchHealthCheck;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         RestHighLevelClient client = elasticSearch.getDockerElasticSearch().clientProvider(REQUEST_TIMEOUT).get();
 
         elasticSearchHealthCheck = new ElasticSearchHealthCheck(client, ImmutableSet.of());
     }
 
     @Test
-    public void checkShouldSucceedWhenElasticSearchIsRunning() {
+    void checkShouldSucceedWhenElasticSearchIsRunning() {
         assertThat(elasticSearchHealthCheck.check().isHealthy()).isTrue();
     }
 
     @Test
-    public void checkShouldFailWhenElasticSearchIsPaused() {
+    void checkShouldFailWhenElasticSearchIsPaused() {
 
         elasticSearch.getDockerElasticSearch().pause();
 
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckTest.java
index feef5da..2c381d4 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchHealthCheckTest.java
@@ -27,34 +27,34 @@ import org.elasticsearch.cluster.block.ClusterBlocks;
 import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.cluster.node.DiscoveryNodes;
 import org.elasticsearch.cluster.routing.RoutingTable;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
 
-public class ElasticSearchHealthCheckTest {
+class ElasticSearchHealthCheckTest {
     private ElasticSearchHealthCheck healthCheck;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         healthCheck = new ElasticSearchHealthCheck(null, ImmutableSet.of());
     }
 
     @Test
-    public void checkShouldReturnHealthyWhenElasticSearchClusterHealthStatusIsGreen() {
+    void checkShouldReturnHealthyWhenElasticSearchClusterHealthStatusIsGreen() {
         FakeClusterHealthResponse response = new FakeClusterHealthResponse(ClusterHealthStatus.GREEN);
 
         assertThat(healthCheck.toHealthCheckResult(response).isHealthy()).isTrue();
     }
 
     @Test
-    public void checkShouldReturnUnHealthyWhenElasticSearchClusterHealthStatusIsRed() {
+    void checkShouldReturnUnHealthyWhenElasticSearchClusterHealthStatusIsRed() {
         FakeClusterHealthResponse response = new FakeClusterHealthResponse(ClusterHealthStatus.RED);
 
         assertThat(healthCheck.toHealthCheckResult(response).isUnHealthy()).isTrue();
     }
 
     @Test
-    public void checkShouldReturnHealthyWhenElasticSearchClusterHealthStatusIsYellow() {
+    void checkShouldReturnHealthyWhenElasticSearchClusterHealthStatusIsYellow() {
         FakeClusterHealthResponse response = new FakeClusterHealthResponse(ClusterHealthStatus.YELLOW);
 
         assertThat(healthCheck.toHealthCheckResult(response).isHealthy()).isTrue();
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index e8fefbc..c7372a5 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -36,14 +36,14 @@ import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestHighLevelClient;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.collect.ImmutableList;
 
-public class ElasticSearchIndexerTest {
+class ElasticSearchIndexerTest {
     public static RoutingKey useDocumentId(DocumentId documentId) {
         return RoutingKey.fromString(documentId.asString());
     }
@@ -59,14 +59,14 @@ public class ElasticSearchIndexerTest {
     private static final RoutingKey ROUTING = RoutingKey.fromString("routing");
     private static final DocumentId DOCUMENT_ID = DocumentId.fromString("1");
 
-    @Rule
-    public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
+    @RegisterExtension
+    public DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
     private ElasticSearchIndexer testee;
     private RestHighLevelClient client;
 
-    @Before
-    public void setup() {
-        client = elasticSearch.clientProvider().get();
+    @BeforeEach
+    void setup() {
+        client = elasticSearch.getDockerElasticSearch().clientProvider().get();
         new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
             .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
@@ -74,13 +74,13 @@ public class ElasticSearchIndexerTest {
         testee = new ElasticSearchIndexer(client, ALIAS_NAME, MINIMUM_BATCH_SIZE);
     }
 
-    @After
-    public void tearDown() throws IOException {
+    @AfterEach
+    void tearDown() throws IOException {
         client.close();
     }
 
     @Test
-    public void indexMessageShouldWork() throws Exception {
+    void indexMessageShouldWork() throws Exception {
         DocumentId documentId = DocumentId.fromString("1");
         String content = "{\"message\": \"trying out Elasticsearch\"}";
         
@@ -95,13 +95,13 @@ public class ElasticSearchIndexerTest {
     }
     
     @Test
-    public void indexMessageShouldThrowWhenJsonIsNull() {
+    void indexMessageShouldThrowWhenJsonIsNull() {
         assertThatThrownBy(() -> testee.index(DOCUMENT_ID, null, ROUTING))
             .isInstanceOf(IllegalArgumentException.class);
     }
     
     @Test
-    public void updateMessages() throws Exception {
+    void updateMessages() throws Exception {
         String content = "{\"message\": \"trying out Elasticsearch\",\"field\":\"Should be unchanged\"}";
 
         testee.index(DOCUMENT_ID, content, useDocumentId(DOCUMENT_ID));
@@ -125,35 +125,35 @@ public class ElasticSearchIndexerTest {
     }
 
     @Test
-    public void updateMessageShouldThrowWhenJsonIsNull() {
+    void updateMessageShouldThrowWhenJsonIsNull() {
         assertThatThrownBy(() -> testee.update(ImmutableList.of(
                 new UpdatedRepresentation(DOCUMENT_ID, null)), ROUTING))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void updateMessageShouldThrowWhenIdIsNull() {
+    void updateMessageShouldThrowWhenIdIsNull() {
         assertThatThrownBy(() -> testee.update(ImmutableList.of(
                 new UpdatedRepresentation(null, "{\"message\": \"mastering out Elasticsearch\"}")), ROUTING))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void updateMessageShouldThrowWhenJsonIsEmpty() {
+    void updateMessageShouldThrowWhenJsonIsEmpty() {
         assertThatThrownBy(() -> testee.update(ImmutableList.of(
                 new UpdatedRepresentation(DOCUMENT_ID, "")), ROUTING))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void updateMessageShouldThrowWhenRoutingKeyIsNull() {
+    void updateMessageShouldThrowWhenRoutingKeyIsNull() {
         assertThatThrownBy(() -> testee.update(ImmutableList.of(
                 new UpdatedRepresentation(DOCUMENT_ID, "{\"message\": \"mastering out Elasticsearch\"}")), null))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void deleteByQueryShouldWorkOnSingleMessage() throws Exception {
+    void deleteByQueryShouldWorkOnSingleMessage() throws Exception {
         DocumentId documentId =  DocumentId.fromString("1:2");
         String content = "{\"message\": \"trying out Elasticsearch\", \"property\":\"1\"}";
         RoutingKey routingKey = useDocumentId(documentId);
@@ -173,7 +173,7 @@ public class ElasticSearchIndexerTest {
     }
 
     @Test
-    public void deleteByQueryShouldWorkWhenMultipleMessages() throws Exception {
+    void deleteByQueryShouldWorkWhenMultipleMessages() throws Exception {
         DocumentId documentId = DocumentId.fromString("1:1");
         String content = "{\"message\": \"trying out Elasticsearch\", \"property\":\"1\"}";
         
@@ -202,7 +202,7 @@ public class ElasticSearchIndexerTest {
     }
     
     @Test
-    public void deleteMessage() throws Exception {
+    void deleteMessage() throws Exception {
         DocumentId documentId = DocumentId.fromString("1:2");
         String content = "{\"message\": \"trying out Elasticsearch\"}";
 
@@ -220,7 +220,7 @@ public class ElasticSearchIndexerTest {
     }
 
     @Test
-    public void deleteShouldWorkWhenMultipleMessages() throws Exception {
+    void deleteShouldWorkWhenMultipleMessages() throws Exception {
         DocumentId documentId = DocumentId.fromString("1:1");
         String content = "{\"message\": \"trying out Elasticsearch\", \"mailboxId\":\"1\"}";
 
@@ -248,13 +248,13 @@ public class ElasticSearchIndexerTest {
     }
     
     @Test
-    public void updateMessagesShouldNotThrowWhenEmptyList() {
+    void updateMessagesShouldNotThrowWhenEmptyList() {
         assertThatCode(() -> testee.update(ImmutableList.of(), ROUTING))
             .doesNotThrowAnyException();
     }
     
     @Test
-    public void deleteMessagesShouldNotThrowWhenEmptyList() {
+    void deleteMessagesShouldNotThrowWhenEmptyList() {
         assertThatCode(() -> testee.delete(ImmutableList.of(), ROUTING))
             .doesNotThrowAnyException();
     }
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
index f204f2c..0862711 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
@@ -24,35 +24,35 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.io.IOException;
 
 import org.elasticsearch.client.RestHighLevelClient;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class IndexCreationFactoryTest {
+class IndexCreationFactoryTest {
     private static final IndexName INDEX_NAME = new IndexName("index");
     private static final ReadAliasName ALIAS_NAME = new ReadAliasName("alias");
 
-    @Rule
-    public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
+    @RegisterExtension
+    public DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
     private RestHighLevelClient client;
 
-    @Before
-    public void setUp() {
-        client = elasticSearch.clientProvider().get();
+    @BeforeEach
+    void setUp() {
+        client = elasticSearch.getDockerElasticSearch().clientProvider().get();
         new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
             .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(client);
     }
 
-    @After
-    public void tearDown() throws IOException {
+    @AfterEach
+    void tearDown() throws IOException {
         client.close();
     }
 
     @Test
-    public void createIndexAndAliasShouldNotThrowWhenCalledSeveralTime() {
+    void createIndexAndAliasShouldNotThrowWhenCalledSeveralTime() {
         new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
             .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
@@ -60,7 +60,7 @@ public class IndexCreationFactoryTest {
     }
 
     @Test
-    public void useIndexShouldThrowWhenNull() {
+    void useIndexShouldThrowWhenNull() {
         assertThatThrownBy(() ->
             new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
                 .useIndex(null))
@@ -68,7 +68,7 @@ public class IndexCreationFactoryTest {
     }
 
     @Test
-    public void addAliasShouldThrowWhenNull() {
+    void addAliasShouldThrowWhenNull() {
         assertThatThrownBy(() ->
             new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
                 .useIndex(INDEX_NAME)
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
index e78c970..7d2f52e 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
@@ -26,22 +26,22 @@ import java.io.IOException;
 
 import org.elasticsearch.client.RestHighLevelClient;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class NodeMappingFactoryTest {
+class NodeMappingFactoryTest {
     private static final String MESSAGE = "message";
     private static final IndexName INDEX_NAME = new IndexName("index");
     private static final ReadAliasName ALIAS_NAME = new ReadAliasName("alias");
 
-    @Rule
-    public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
+    @RegisterExtension
+    public DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
     private RestHighLevelClient client;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         client = elasticSearch.getDockerElasticSearch().clientProvider().get();
         new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
             .useIndex(INDEX_NAME)
@@ -52,20 +52,20 @@ public class NodeMappingFactoryTest {
             getMappingsSources());
     }
 
-    @After
-    public void tearDown() throws IOException {
+    @AfterEach
+    void tearDown() throws IOException {
         client.close();
     }
 
     @Test
-    public void applyMappingShouldNotThrowWhenCalledSeveralTime() throws Exception {
+    void applyMappingShouldNotThrowWhenCalledSeveralTime() throws Exception {
         NodeMappingFactory.applyMapping(client,
             INDEX_NAME,
             getMappingsSources());
     }
 
     @Test
-    public void applyMappingShouldNotThrowWhenIncrementalChanges() throws Exception {
+    void applyMappingShouldNotThrowWhenIncrementalChanges() throws Exception {
         NodeMappingFactory.applyMapping(client,
             INDEX_NAME,
             getMappingsSources());
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrolledSearchTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrolledSearchTest.java
index 6cd3e45..c4e9e2b 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrolledSearchTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrolledSearchTest.java
@@ -24,7 +24,7 @@ import static org.awaitility.Awaitility.await;
 
 import java.io.IOException;
 
-import org.apache.james.backends.es.DockerElasticSearchRule;
+import org.apache.james.backends.es.DockerElasticSearchExtension;
 import org.apache.james.backends.es.ElasticSearchConfiguration;
 import org.apache.james.backends.es.IndexCreationFactory;
 import org.apache.james.backends.es.IndexName;
@@ -40,12 +40,12 @@ import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class ScrolledSearchTest {
+class ScrolledSearchTest {
     private static final TimeValue TIMEOUT = TimeValue.timeValueMinutes(1);
     private static final int SIZE = 2;
     private static final String MESSAGE = "message";
@@ -54,13 +54,13 @@ public class ScrolledSearchTest {
 
     private static final ConditionFactory WAIT_CONDITION = await().timeout(Duration.FIVE_SECONDS);
 
-    @Rule
-    public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
+    @RegisterExtension
+    public DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
     private RestHighLevelClient client;
 
-    @Before
-    public void setUp() {
-        client = elasticSearch.clientProvider().get();
+    @BeforeEach
+    void setUp() {
+        client = elasticSearch.getDockerElasticSearch().clientProvider().get();
         new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
             .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
@@ -68,13 +68,13 @@ public class ScrolledSearchTest {
         elasticSearch.awaitForElasticSearch();
     }
 
-    @After
-    public void tearDown() throws IOException {
+    @AfterEach
+    void tearDown() throws IOException {
         client.close();
     }
 
     @Test
-    public void scrollIterableShouldWorkWhenEmpty() {
+    void scrollIterableShouldWorkWhenEmpty() {
         SearchRequest searchRequest = new SearchRequest(INDEX_NAME.getValue())
             .scroll(TIMEOUT)
             .source(new SearchSourceBuilder()
@@ -86,7 +86,7 @@ public class ScrolledSearchTest {
     }
 
     @Test
-    public void scrollIterableShouldWorkWhenOneElement() throws Exception {
+    void scrollIterableShouldWorkWhenOneElement() throws Exception {
         String id = "1";
         client.index(new IndexRequest(INDEX_NAME.getValue())
                 .type(NodeMappingFactory.DEFAULT_MAPPING_NAME)
@@ -109,7 +109,7 @@ public class ScrolledSearchTest {
     }
 
     @Test
-    public void scrollIterableShouldWorkWhenSizeElement() throws Exception {
+    void scrollIterableShouldWorkWhenSizeElement() throws Exception {
         String id1 = "1";
         client.index(new IndexRequest(INDEX_NAME.getValue())
                 .type(NodeMappingFactory.DEFAULT_MAPPING_NAME)
@@ -139,7 +139,7 @@ public class ScrolledSearchTest {
     }
 
     @Test
-    public void scrollIterableShouldWorkWhenMoreThanSizeElement() throws Exception {
+    void scrollIterableShouldWorkWhenMoreThanSizeElement() throws Exception {
         String id1 = "1";
         client.index(new IndexRequest(INDEX_NAME.getValue())
                 .type(NodeMappingFactory.DEFAULT_MAPPING_NAME)


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