[SCB-2615-part1] migrate foundation-vertx module to junit5 (#3148)

diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/BodyBufferSupportImpl.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/BodyBufferSupportImpl.java
index 2bab47b..eceedf6 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/BodyBufferSupportImpl.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/BodyBufferSupportImpl.java
@@ -17,6 +17,7 @@
 
 package org.apache.servicecomb.foundation.vertx.http;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.servicecomb.foundation.vertx.VertxUtils;
 
 import io.vertx.core.buffer.Buffer;
@@ -48,12 +49,22 @@
     return bodyBuffer;
   }
 
+  @VisibleForTesting
+  void setBodyBytes(byte[] bodyBytes) {
+    this.bodyBytes = bodyBytes;
+  }
+
   @Override
   public byte[] getBodyBytes() {
     prepare();
     return bodyBytes;
   }
 
+  @VisibleForTesting
+  void setBodyLength(int bodyLength) {
+    this.bodyLength = bodyLength;
+  }
+
   @Override
   public int getBodyBytesLength() {
     prepare();
diff --git a/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java b/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java
index 6714033..874226f 100644
--- a/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java
+++ b/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java
@@ -18,29 +18,23 @@
 package io.vertx.ext.web.impl;
 
 import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
-import org.junit.Test;
 
 import io.vertx.core.http.impl.HttpServerRequestInternal;
 import io.vertx.ext.web.AllowForwardHeaders;
 import io.vertx.ext.web.RoutingContext;
-import mockit.Expectations;
-import mockit.Mocked;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 // HttpServerRequestWrapper is a package visible class, so put this test in package io.vertx.ext.web.impl
 public class TestHttpServerRequestUtils {
   @Test
-  public void testVertxServerRequestToHttpServletRequest(@Mocked RoutingContext context,
-      @Mocked HttpServerRequestInternal request) {
+  public void testVertxServerRequestToHttpServletRequest() {
+    RoutingContext context = Mockito.mock(RoutingContext.class);
+    HttpServerRequestInternal request = Mockito.mock(HttpServerRequestInternal.class);
     HttpServerRequestWrapper wrapper = new HttpServerRequestWrapper(request, AllowForwardHeaders.NONE);
-    new Expectations() {
-      {
-        request.scheme();
-        result = "http";
-        context.request();
-        result = wrapper;
-      }
-    };
+    Mockito.when(request.scheme()).thenReturn("http");
+    Mockito.when(context.request()).thenReturn(wrapper);
 
     VertxServerRequestToHttpServletRequest reqEx = new VertxServerRequestToHttpServletRequest(context, "abc");
     Assertions.assertEquals("abc", reqEx.getRequestURI());
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
index dd57ee4..a8ce06a 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
@@ -22,43 +22,37 @@
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
 
 import io.vertx.core.dns.AddressResolverOptions;
-import mockit.Expectations;
-import mockit.Mocked;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 public class TestAddressResolverConfig {
 
-  @BeforeClass
+  @BeforeAll
   public static void classSetup() {
     ArchaiusUtils.resetConfig();
   }
 
-  @AfterClass
+  @AfterAll
   public static void classTeardown() {
     ArchaiusUtils.resetConfig();
   }
 
   @Test
-  public void testGetResolverFromResource(@Mocked Configuration finalConfig) {
+  public void testGetResolverFromResource() {
+    Configuration finalConfig = Mockito.mock(Configuration.class);
     ArchaiusUtils.resetConfig();
     ArchaiusUtils.setProperty("addressResolver.servers", "8.8.8.8,8.8.4.4");
-    new Expectations() {
-      {
-        finalConfig.getStringArray("addressResolver.servers");
-        result = new String[] {"6.6.6.6", "6.6.4.4"};
-        finalConfig.getStringArray("addressResolver.searchDomains");
-        result = new String[] {"default.svc.local.cluster"};
-        finalConfig.getInteger("addressResolver.queryTimeout", null);
-        result = 2000;
-        finalConfig.getInteger("addressResolver.maxQueries", null);
-        result = -2;
-      }
-    };
+
+    Mockito.when(finalConfig.getStringArray("addressResolver.servers")).thenReturn(new String[] {"6.6.6.6", "6.6.4.4"});
+    Mockito.when(finalConfig.getStringArray("addressResolver.searchDomains")).thenReturn(new String[] {"default.svc.local.cluster"});
+    Mockito.when(finalConfig.getInteger("addressResolver.queryTimeout", null)).thenReturn(2000);
+    Mockito.when(finalConfig.getInteger("addressResolver.maxQueries", null)).thenReturn(-2);
+
     AddressResolverOptions resolverOptions = AddressResolverConfig.getAddressResover("test", finalConfig);
     Assertions.assertEquals(Arrays.asList("6.6.6.6", "6.6.4.4"), resolverOptions.getServers());
     Assertions.assertEquals(Collections.singletonList("default.svc.local.cluster"), resolverOptions.getSearchDomains());
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxTLSBuilder.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxTLSBuilder.java
index 1422631..9ed503d 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxTLSBuilder.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxTLSBuilder.java
@@ -44,7 +44,7 @@
   }
 
   @Test
-  public void testbuildHttpServerOptions() {
+  public void testBuildHttpServerOptions() {
     SSLOption option = SSLOption.buildFromYaml("rest.provider");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpServerOptions serverOptions = new HttpServerOptions();
@@ -54,7 +54,7 @@
   }
 
   @Test
-  public void testbuildHttpClientOptions_sslKey_noFactory() {
+  public void testBuildHttpClientOptions_sslKey_noFactory() {
     HttpClientOptions clientOptions = new HttpClientOptions();
     VertxTLSBuilder.buildHttpClientOptions("notExist", clientOptions);
     Assertions.assertTrue(clientOptions.isSsl());
@@ -77,7 +77,7 @@
   }
 
   @Test
-  public void testbuildHttpClientOptions_ssl_withFactory() {
+  public void testBuildHttpClientOptions_ssl_withFactory() {
     ArchaiusUtils.setProperty("ssl.exist.sslOptionFactory", SSLOptionFactoryForTest.class.getName());
     HttpClientOptions clientOptions = new HttpClientOptions();
     VertxTLSBuilder.buildHttpClientOptions("exist", clientOptions);
@@ -86,7 +86,7 @@
   }
 
   @Test
-  public void testbuildHttpClientOptions() {
+  public void testBuildHttpClientOptions() {
     SSLOption option = SSLOption.buildFromYaml("rest.consumer");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpClientOptions serverOptions = new HttpClientOptions();
@@ -96,7 +96,7 @@
   }
 
   @Test
-  public void testbuildClientOptionsBase() {
+  public void testBuildClientOptionsBase() {
     SSLOption option = SSLOption.buildFromYaml("rest.consumer");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpClientOptions serverOptions = new HttpClientOptions();
@@ -106,7 +106,7 @@
   }
 
   @Test
-  public void testbuildClientOptionsBaseFileNull() {
+  public void testBuildClientOptionsBaseFileNull() {
     SSLOption option = SSLOption.buildFromYaml("rest.consumer");
     option.setKeyStore(null);
     option.setTrustStore(null);
@@ -119,7 +119,7 @@
   }
 
   @Test
-  public void testbuildClientOptionsBaseAuthPeerFalse() {
+  public void testBuildClientOptionsBaseAuthPeerFalse() {
     SSLOption option = SSLOption.buildFromYaml("rest.consumer");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpClientOptions serverOptions = new HttpClientOptions();
@@ -136,7 +136,7 @@
   }
 
   @Test
-  public void testbuildClientOptionsBaseSTORE_JKS() {
+  public void testBuildClientOptionsBaseSTORE_JKS() {
     SSLOption option = SSLOption.buildFromYaml("rest.consumer");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpClientOptions serverOptions = new HttpClientOptions();
@@ -153,7 +153,7 @@
   }
 
   @Test
-  public void testbuildClientOptionsBaseSTORE_PKCS12() {
+  public void testBuildClientOptionsBaseSTORE_PKCS12() {
     SSLOption option = SSLOption.buildFromYaml("rest.consumer");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpClientOptions serverOptions = new HttpClientOptions();
@@ -170,7 +170,7 @@
   }
 
   @Test
-  public void testbuildHttpServerOptionsRequest() {
+  public void testBuildHttpServerOptionsRequest() {
     SSLOption option = SSLOption.buildFromYaml("rest.provider");
     SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
     HttpServerOptions serverOptions = new HttpServerOptions();
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/http/TestHttpClientPoolFactory.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/http/TestHttpClientPoolFactory.java
index 76b6c84..cf57fe6 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/http/TestHttpClientPoolFactory.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/http/TestHttpClientPoolFactory.java
@@ -16,16 +16,13 @@
  */
 package org.apache.servicecomb.foundation.vertx.client.http;
 
-import org.junit.Test;
-
 import io.vertx.core.http.HttpClient;
 import io.vertx.core.http.HttpClientOptions;
 import io.vertx.core.impl.ContextInternal;
-import io.vertx.core.impl.VertxImpl;
 import io.vertx.core.impl.VertxInternal;
-import mockit.Expectations;
-import mockit.Mocked;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 public class TestHttpClientPoolFactory {
   private final HttpClientOptions httpClientOptions = new HttpClientOptions();
@@ -33,16 +30,13 @@
   HttpClientPoolFactory factory = new HttpClientPoolFactory(httpClientOptions);
 
   @Test
-  public void createClientPool(@Mocked VertxInternal vertx, @Mocked ContextInternal context,
-      @Mocked HttpClient httpClient) {
-    new Expectations(VertxImpl.class) {
-      {
-        context.owner();
-        result = vertx;
-        vertx.createHttpClient(httpClientOptions);
-        result = httpClient;
-      }
-    };
+  public void createClientPool() {
+    VertxInternal vertx = Mockito.mock(VertxInternal.class);
+    ContextInternal context = Mockito.mock(ContextInternal.class);
+    HttpClient httpClient = Mockito.mock(HttpClient.class);
+    Mockito.when(context.owner()).thenReturn(vertx);
+    Mockito.when(vertx.createHttpClient(httpClientOptions)).thenReturn(httpClient);
+
     HttpClientWithContext pool = factory.createClientPool(context);
 
     Assertions.assertSame(context, pool.context());
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java
index 9f83fea..dfaf8ec 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java
@@ -16,24 +16,23 @@
  */
 package org.apache.servicecomb.foundation.vertx.client.tcp;
 
-import org.junit.Before;
-import org.junit.Test;
-
 import io.vertx.core.impl.ContextInternal;
-import mockit.Mocked;
+import io.vertx.core.impl.VertxInternal;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 public class TestTcpClientConnectionPool {
-  @Mocked
-  ContextInternal context;
-
-  @Mocked
-  NetClientWrapper netClientWrapper;
 
   TcpClientConnectionPool pool;
 
-  @Before
+  @BeforeEach
   public void setup() {
+    ContextInternal context = Mockito.mock(ContextInternal.class);
+    VertxInternal vertx = Mockito.mock(VertxInternal.class);
+    Mockito.when(context.owner()).thenReturn(vertx);
+    NetClientWrapper netClientWrapper = Mockito.mock(NetClientWrapper.class);
     pool = new TcpClientConnectionPool(context, netClientWrapper);
   }
 
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestBodyBufferSupportImpl.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestBodyBufferSupportImpl.java
index cf8f4bf..f12bec0 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestBodyBufferSupportImpl.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestBodyBufferSupportImpl.java
@@ -18,7 +18,6 @@
 package org.apache.servicecomb.foundation.vertx.http;
 
 import io.vertx.core.buffer.Buffer;
-import mockit.Deencapsulation;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -27,8 +26,8 @@
 
   @Test
   public void testSetBodyBuffer() {
-    Deencapsulation.setField(impl, "bodyBytes", new byte[] {});
-    Deencapsulation.setField(impl, "bodyLength", 10);
+    impl.setBodyBytes(new byte[] {});
+    impl.setBodyLength(10);
 
     Assertions.assertNotNull(impl.getBodyBytes());
     Assertions.assertEquals(10, impl.getBodyBytesLength());