Browse Source

去除单元测试--add-opensc参数,适配高版本jdk.

nieqiurong 1 year ago
parent
commit
7d7528253f

+ 5 - 5
build.gradle

@@ -179,11 +179,11 @@ subprojects {
         // 增加jvm参数不是一个很好的处理方案,最好还是只用java8下跑,下面只是兼容运行一下,但在高版本jdk下还有很多第三方反射库存在问题(等待完全升级)
         // 部分测试用例如果需要在高版本java下运行用@EnabledOnJre
         // 例如: https://github.com/cglib/cglib/issues/191
-        if (JavaVersion.current().isJava9Compatible()) {
-            jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
-                        "--add-opens", "java.base/java.util=ALL-UNNAMED",
-                        "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
-        }
+//        if (JavaVersion.current().isJava9Compatible()) {
+//            jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
+//                        "--add-opens", "java.base/java.util=ALL-UNNAMED",
+//                        "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
+//        }
         exclude("**/phoenix/**")
         exclude("**/postgresql/**")
 //        exclude("**/generator/**")

+ 4 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/toolkit/support/IdeaProxyLambdaMetaTest.java

@@ -1,6 +1,8 @@
 package com.baomidou.mybatisplus.core.toolkit.support;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandleProxies;
@@ -20,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 class IdeaProxyLambdaMetaTest {
 
     @Test
+    @EnabledOnJre(JRE.JAVA_8)
     void test() throws NoSuchMethodException, IllegalAccessException {
         MethodHandles.Lookup lookup = MethodHandles.lookup();
         MethodHandle handle = lookup.findStatic(IdeaProxyLambdaMetaTest.class, "s", MethodType.methodType(int.class));
@@ -34,4 +37,4 @@ class IdeaProxyLambdaMetaTest {
         return ThreadLocalRandom.current().nextInt();
     }
 
-}
+}

+ 3 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/BeanUtilsTest.java

@@ -20,6 +20,8 @@ import lombok.Getter;
 import lombok.Setter;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
 
 import java.util.Map;
 
@@ -35,6 +37,7 @@ class BeanUtilsTest {
      * 测试 beanToMap
      */
     @Test
+    @EnabledOnJre(JRE.JAVA_8)
     void beanMapConvertTest() {
         Map<String, Object> map = BeanUtils.beanToMap(new User() {{
             setId(123);

+ 3 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/CollectionUtilsTest.java

@@ -3,6 +3,8 @@ package com.baomidou.mybatisplus.test.toolkit;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
 
 import java.lang.reflect.Field;
 import java.util.HashMap;
@@ -15,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
 class CollectionUtilsTest {
 
     @Test
+    @EnabledOnJre(JRE.JAVA_8)
     void testCreateHashMap() throws ReflectiveOperationException {
         Map<String, String> hashMap = newHashMapWithExpectedSize(4);
         Assertions.assertEquals(8, getTableSize(hashMap));

+ 3 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/LambdaUtilsTest.java

@@ -21,6 +21,8 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
 import lombok.Getter;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandleProxies;
@@ -39,6 +41,7 @@ class LambdaUtilsTest {
      * 测试解析
      */
     @Test
+    @EnabledOnJre(JRE.JAVA_8)
     @SuppressWarnings("unchecked")
     void testExtract() throws IllegalAccessException, NoSuchMethodException {
         SFunction<TestModel, Object> function = TestModel::getName;

+ 55 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/PluginUtilsTest.java

@@ -0,0 +1,55 @@
+package com.baomidou.mybatisplus.test.toolkit;
+
+import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
+import org.apache.ibatis.builder.StaticSqlSource;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.executor.SimpleExecutor;
+import org.apache.ibatis.executor.statement.RoutingStatementHandler;
+import org.apache.ibatis.executor.statement.StatementHandler;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.plugin.Intercepts;
+import org.apache.ibatis.plugin.Invocation;
+import org.apache.ibatis.plugin.Signature;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.RowBounds;
+import org.apache.ibatis.transaction.jdbc.JdbcTransaction;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
+import java.sql.Connection;
+
+/**
+ * @author nieqiurong 2023/8/5 10:28
+ */
+public class PluginUtilsTest {
+
+    @Intercepts({
+        @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})}
+    )
+    static class TestInterceptor implements Interceptor {
+
+        @Override
+        public Object intercept(Invocation invocation) throws InvocationTargetException, IllegalAccessException {
+            return invocation.proceed();
+        }
+
+    }
+
+    @Test
+    void testRealTargetByProxy() {
+        Configuration configuration = new Configuration();
+        Executor executor = new SimpleExecutor(configuration, new JdbcTransaction(Mockito.mock(Connection.class)));
+        MappedStatement mappedStatement = new MappedStatement.Builder(configuration, "test", new StaticSqlSource(configuration, "-------------"), SqlCommandType.SELECT).build();
+        RoutingStatementHandler statementHandler = new RoutingStatementHandler(executor, mappedStatement, new Object(), new RowBounds(), null, Mockito.mock(BoundSql.class));
+        Object plugin = new TestInterceptor().plugin(statementHandler);
+        Assertions.assertTrue(Proxy.isProxyClass(plugin.getClass()));
+        Assertions.assertEquals(statementHandler, PluginUtils.realTarget(plugin));
+    }
+
+}

+ 3 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/PageTest.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.reflection.property.PropertyCopier;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
 import org.springframework.beans.BeanUtils;
 import org.springframework.cglib.beans.BeanCopier;
 
@@ -16,6 +18,7 @@ import java.util.Collections;
 class PageTest {
 
     @Test
+    @EnabledOnJre(JRE.JAVA_8)
     void testCopy(){
         Page page1 = new Page(2, 10, 100, false);
         page1.setOptimizeCountSql(false);