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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 85f20d779 [SCB-2454] Allow test to run on jdk17 (#2787)
85f20d779 is described below

commit 85f20d779c6731a6e38aba533100057799408092
Author: ZhangJian He <[email protected]>
AuthorDate: Mon Apr 18 09:42:17 2022 +0800

    [SCB-2454] Allow test to run on jdk17 (#2787)
---
 .../common/rest/TestRestProducerInvocation.java    |  3 ++-
 .../org/apache/servicecomb/config/ConfigUtil.java  |  6 +++--
 .../apache/servicecomb/config/TestConfigUtil.java  |  3 +--
 .../servicecomb/foundation/ssl/SSLOption.java      |  3 ++-
 .../servicecomb/foundation/ssl/SSLOptionTest.java  | 30 +++++++++++-----------
 pom.xml                                            | 13 +++++++++-
 ...efaultExceptionToProducerResponseConverter.java | 13 +++++-----
 ...cationExceptionToProducerResponseConverter.java | 11 ++++----
 8 files changed, 49 insertions(+), 33 deletions(-)

diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
index d69f1719f..eced4c8bd 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
@@ -103,7 +103,8 @@ public class TestRestProducerInvocation {
   }
 
   @Test
-  public void invokeSendFail(@Mocked InvocationException expected) {
+  public void invokeSendFail() {
+    InvocationException expected = new 
InvocationException(javax.ws.rs.core.Response.Status.BAD_REQUEST, "test");
     restProducerInvocation = new MockUp<RestProducerInvocation>() {
       @Mock
       void sendFailResponse(Throwable throwable) {
diff --git 
a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index aec33df45..88c49859d 100644
--- 
a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -33,6 +33,7 @@ import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.configuration.AbstractConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.EnvironmentConfiguration;
@@ -174,8 +175,9 @@ public final class ConfigUtil {
     return source;
   }
 
-  //inject a copy of servicecomb.xxx for cse.xxx
-  private static void duplicateCseConfigToServicecomb(AbstractConfiguration 
source) {
+  // inject a copy of servicecomb.xxx for cse.xxx
+  @VisibleForTesting
+  static void duplicateCseConfigToServicecomb(AbstractConfiguration source) {
     Iterator<String> keys = source.getKeys();
     while (keys.hasNext()) {
       String key = keys.next();
diff --git 
a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
 
b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
index 0f3559f01..c292aa2ad 100644
--- 
a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
+++ 
b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
@@ -48,7 +48,6 @@ import com.netflix.config.DynamicConfiguration;
 import com.netflix.config.DynamicPropertyFactory;
 import com.netflix.config.DynamicWatchedConfiguration;
 
-import mockit.Deencapsulation;
 import mockit.Expectations;
 import mockit.Mock;
 import mockit.MockUp;
@@ -184,7 +183,7 @@ public class TestConfigUtil {
 
     AbstractConfiguration config = new DynamicConfiguration();
     config.addProperty("cse.list", list);
-    Deencapsulation.invoke(ConfigUtil.class, 
"duplicateCseConfigToServicecomb", config);
+    ConfigUtil.duplicateCseConfigToServicecomb(config);
 
     Object result = config.getProperty("servicecomb.list");
     MatcherAssert.assertThat(result, instanceOf(List.class));
diff --git 
a/foundations/foundation-ssl/src/main/java/org/apache/servicecomb/foundation/ssl/SSLOption.java
 
b/foundations/foundation-ssl/src/main/java/org/apache/servicecomb/foundation/ssl/SSLOption.java
index 4e5812e20..bbc7e0d9d 100644
--- 
a/foundations/foundation-ssl/src/main/java/org/apache/servicecomb/foundation/ssl/SSLOption.java
+++ 
b/foundations/foundation-ssl/src/main/java/org/apache/servicecomb/foundation/ssl/SSLOption.java
@@ -459,7 +459,8 @@ public final class SSLOption {
     }
   }
 
-  private void load(String path) {
+  // visible for testing
+  void load(String path) {
     try {
       load(new FileInputStream(path));
     } catch (FileNotFoundException e) {
diff --git 
a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLOptionTest.java
 
b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLOptionTest.java
index 70726a127..6864d61b5 100644
--- 
a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLOptionTest.java
+++ 
b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLOptionTest.java
@@ -72,15 +72,15 @@ public class SSLOptionTest {
 
     boolean authPeer = option.isAuthPeer();
     option.setAuthPeer(authPeer);
-    Assert.assertEquals(true, authPeer);
+    Assert.assertTrue(authPeer);
 
     boolean checkCNHost = option.isCheckCNHost();
     option.setCheckCNHost(checkCNHost);
-    Assert.assertEquals(true, checkCNHost);
+    Assert.assertTrue(checkCNHost);
 
     boolean checkCNWhite = option.isCheckCNWhite();
     option.setCheckCNWhite(checkCNWhite);
-    Assert.assertEquals(true, checkCNWhite);
+    Assert.assertTrue(checkCNWhite);
 
     String checkCNWhiteFile = option.getCheckCNWhiteFile();
     option.setCheckCNWhiteFile(checkCNWhiteFile);
@@ -88,7 +88,7 @@ public class SSLOptionTest {
 
     boolean allowRenegociate = option.isAllowRenegociate();
     option.setAllowRenegociate(allowRenegociate);
-    Assert.assertEquals(false, allowRenegociate);
+    Assert.assertFalse(allowRenegociate);
 
     String storePath = option.getStorePath();
     option.setStorePath(storePath);
@@ -155,15 +155,15 @@ public class SSLOptionTest {
 
     boolean authPeer = option.isAuthPeer();
     option.setAuthPeer(authPeer);
-    Assert.assertEquals(true, authPeer);
+    Assert.assertTrue(authPeer);
 
     boolean checkCNHost = option.isCheckCNHost();
     option.setCheckCNHost(checkCNHost);
-    Assert.assertEquals(true, checkCNHost);
+    Assert.assertTrue(checkCNHost);
 
     boolean checkCNWhite = option.isCheckCNWhite();
     option.setCheckCNWhite(checkCNWhite);
-    Assert.assertEquals(true, checkCNWhite);
+    Assert.assertTrue(checkCNWhite);
 
     String checkCNWhiteFile = option.getCheckCNWhiteFile();
     option.setCheckCNWhiteFile(checkCNWhiteFile);
@@ -171,7 +171,7 @@ public class SSLOptionTest {
 
     boolean allowRenegociate = option.isAllowRenegociate();
     option.setAllowRenegociate(allowRenegociate);
-    Assert.assertEquals(false, allowRenegociate);
+    Assert.assertFalse(allowRenegociate);
 
     String storePath = option.getStorePath();
     option.setStorePath(storePath);
@@ -233,7 +233,7 @@ public class SSLOptionTest {
 
     boolean authPeer = option.isAuthPeer();
     option.setAuthPeer(authPeer);
-    Assert.assertEquals(false, authPeer);
+    Assert.assertFalse(authPeer);
     System.getProperties().remove("ssl.authPeer");
   }
 
@@ -246,7 +246,7 @@ public class SSLOptionTest {
 
     boolean authPeer = option.isAuthPeer();
     option.setAuthPeer(authPeer);
-    Assert.assertEquals(true, authPeer);
+    Assert.assertTrue(authPeer);
     System.getProperties().remove("ssl.authPeer");
   }
 
@@ -270,15 +270,15 @@ public class SSLOptionTest {
 
     boolean authPeer = option.isAuthPeer();
     option.setAuthPeer(authPeer);
-    Assert.assertEquals(true, authPeer);
+    Assert.assertTrue(authPeer);
 
     boolean checkCNHost = option.isCheckCNHost();
     option.setCheckCNHost(checkCNHost);
-    Assert.assertEquals(true, checkCNHost);
+    Assert.assertTrue(checkCNHost);
 
     boolean checkCNWhite = option.isCheckCNWhite();
     option.setCheckCNWhite(checkCNWhite);
-    Assert.assertEquals(true, checkCNWhite);
+    Assert.assertTrue(checkCNWhite);
 
     String checkCNWhiteFile = option.getCheckCNWhiteFile();
     option.setCheckCNWhiteFile(checkCNWhiteFile);
@@ -286,7 +286,7 @@ public class SSLOptionTest {
 
     boolean allowRenegociate = option.isAllowRenegociate();
     option.setAllowRenegociate(allowRenegociate);
-    Assert.assertEquals(false, allowRenegociate);
+    Assert.assertFalse(allowRenegociate);
 
     String storePath = option.getStorePath();
     option.setStorePath(storePath);
@@ -391,7 +391,7 @@ public class SSLOptionTest {
     SSLOption option = new SSLOption();
     boolean validAssert = true;
     try {
-      Deencapsulation.invoke(option, "load", "test");
+      option.load("test");
     } catch (Exception e) {
       Assert.assertEquals("java.lang.IllegalArgumentException", 
e.getClass().getName());
       validAssert = false;
diff --git a/pom.xml b/pom.xml
index e34ed46e6..39a4faeab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,11 @@
     <argLine>-Dfile.encoding=UTF-8</argLine>
     <skip-remote-resource>true</skip-remote-resource>
     <werror.properties>-Werror</werror.properties>
+    <test.additional.args/>
+    <!-- plugin version start -->
     <dependency-check-maven.version>7.0.4</dependency-check-maven.version>
+    <surefire-maven.version>3.0.0-M6</surefire-maven.version>
+    <!-- plugin version end -->
   </properties>
 
   <licenses>
@@ -255,8 +259,9 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <version>3.0.0-M5</version>
+        <version>${surefire-maven.version}</version>
         <configuration>
+          <argLine>${test.additional.args}</argLine>
           <skip>${maven.test.skip}</skip>
           <testFailureIgnore>${maven.test.failure.ignore}</testFailureIgnore>
           <excludes>
@@ -636,6 +641,12 @@
       </activation>
       <properties>
         <werror.properties/>
+        <test.additional.args>
+          -Djdk.attach.allowAttachSelf
+          --add-opens java.base/jdk.internal.loader=ALL-UNNAMED
+          --add-opens java.base/java.lang=ALL-UNNAMED
+          --add-opens java.base/java.io=ALL-UNNAMED
+        </test.additional.args>
       </properties>
     </profile>
   </profiles>
diff --git 
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestDefaultExceptionToProducerResponseConverter.java
 
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestDefaultExceptionToProducerResponseConverter.java
index c90d5e7e3..38fba02c6 100644
--- 
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestDefaultExceptionToProducerResponseConverter.java
+++ 
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestDefaultExceptionToProducerResponseConverter.java
@@ -18,22 +18,23 @@ package org.apache.servicecomb.swagger.invocation.exception;
 
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.junit.Assert;
-import org.junit.Test;
 
 import mockit.Mocked;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
 
 public class TestDefaultExceptionToProducerResponseConverter {
   DefaultExceptionToProducerResponseConverter converter = new 
DefaultExceptionToProducerResponseConverter();
 
   @Test
   public void getExceptionClass() {
-    Assert.assertNull(converter.getExceptionClass());
+    Assertions.assertNull(converter.getExceptionClass());
   }
 
   @Test
-  public void convert(@Mocked SwaggerInvocation swaggerInvocation, @Mocked 
Error e) {
-    Response response = converter.convert(swaggerInvocation, e);
-    Assert.assertSame(e, ((InvocationException) 
response.getResult()).getCause());
+  public void convert(@Mocked SwaggerInvocation swaggerInvocation) {
+    IllegalStateException stateException = new IllegalStateException("test");
+    Response response = converter.convert(swaggerInvocation, stateException);
+    Assertions.assertSame(stateException, ((InvocationException) 
response.getResult()).getCause());
   }
 }
diff --git 
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestInvocationExceptionToProducerResponseConverter.java
 
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestInvocationExceptionToProducerResponseConverter.java
index 49dbd59ea..159c2b223 100644
--- 
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestInvocationExceptionToProducerResponseConverter.java
+++ 
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestInvocationExceptionToProducerResponseConverter.java
@@ -18,22 +18,23 @@ package org.apache.servicecomb.swagger.invocation.exception;
 
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.junit.Assert;
-import org.junit.Test;
 
 import mockit.Mocked;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
 
 public class TestInvocationExceptionToProducerResponseConverter {
   InvocationExceptionToProducerResponseConverter converter = new 
InvocationExceptionToProducerResponseConverter();
 
   @Test
   public void getExceptionClass() {
-    Assert.assertEquals(InvocationException.class, 
converter.getExceptionClass());
+    Assertions.assertEquals(InvocationException.class, 
converter.getExceptionClass());
   }
 
   @Test
-  public void convert(@Mocked SwaggerInvocation swaggerInvocation, @Mocked 
InvocationException e) {
+  public void convert(@Mocked SwaggerInvocation swaggerInvocation) {
+    InvocationException e = new 
InvocationException(javax.ws.rs.core.Response.Status.BAD_REQUEST, "test");
     Response response = converter.convert(swaggerInvocation, e);
-    Assert.assertSame(e, response.getResult());
+    Assertions.assertSame(e, response.getResult());
   }
 }

Reply via email to