From 1a9696e8ac888c13afcf6f6a2d1de84a9fd9ea20 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 5 Jan 2026 21:22:58 +0800 Subject: [PATCH] add test --- .../v7/core/collection/queue/Linked.java | 2 +- .../v7/core/reflect/kotlin/KParameter.java | 8 +++- .../core/reflect/kotlin/KClassUtilTest.java | 2 +- hutool-jmh/pom.xml | 9 +++- hutool-json/pom.xml | 4 +- .../v7/json/kotlin/JsonToKotlinBeanTest.java | 41 +++++++++++++++++++ .../hutool/v7/json/kotlin/TestKBeanForJson.kt | 23 +++++++++++ pom.xml | 19 +++++---- 8 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 hutool-json/src/test/java/cn/hutool/v7/json/kotlin/JsonToKotlinBeanTest.java create mode 100644 hutool-json/src/test/java/cn/hutool/v7/json/kotlin/TestKBeanForJson.kt diff --git a/hutool-core/src/main/java/cn/hutool/v7/core/collection/queue/Linked.java b/hutool-core/src/main/java/cn/hutool/v7/core/collection/queue/Linked.java index e1cff3598a..0015c56305 100755 --- a/hutool-core/src/main/java/cn/hutool/v7/core/collection/queue/Linked.java +++ b/hutool-core/src/main/java/cn/hutool/v7/core/collection/queue/Linked.java @@ -20,7 +20,7 @@ package cn.hutool.v7.core.collection.queue; * Linked接口定义了一个链式数据结构的通用接口
* 链式结构中每个元素都包含两个指针,分别指向前一个元素和后一个元素。 * - * @param 泛型参数,表示链式结构中元素的类型,必须继承自Linked接口 + * @param 泛型参数,表示链式结构中元素的类型,必须继承自{@code Linked}接口 * @author Looly */ public interface Linked> { diff --git a/hutool-core/src/main/java/cn/hutool/v7/core/reflect/kotlin/KParameter.java b/hutool-core/src/main/java/cn/hutool/v7/core/reflect/kotlin/KParameter.java index 68a16ada7f..350026a243 100644 --- a/hutool-core/src/main/java/cn/hutool/v7/core/reflect/kotlin/KParameter.java +++ b/hutool-core/src/main/java/cn/hutool/v7/core/reflect/kotlin/KParameter.java @@ -39,7 +39,13 @@ public class KParameter { METHOD_GET_NAME = MethodUtil.getMethod(kParameterClass, "getName"); METHOD_GET_TYPE = MethodUtil.getMethod(kParameterClass, "getType"); - final Class kTypeClass = ClassLoaderUtil.loadClass("kotlin.reflect.jvm.internal.KTypeImpl"); + Class kTypeClass; + try{ + // Kotlin 2.3.0+ + kTypeClass = ClassLoaderUtil.loadClass("kotlin.reflect.jvm.internal.types.AbstractKType"); + } catch (final Exception e) { + kTypeClass = ClassLoaderUtil.loadClass("kotlin.reflect.jvm.internal.KTypeImpl"); + } METHOD_GET_JAVA_TYPE = MethodUtil.getMethod(kTypeClass, "getJavaType"); } diff --git a/hutool-core/src/test/java/cn/hutool/v7/core/reflect/kotlin/KClassUtilTest.java b/hutool-core/src/test/java/cn/hutool/v7/core/reflect/kotlin/KClassUtilTest.java index f2d0e2448f..f796c9bbfe 100644 --- a/hutool-core/src/test/java/cn/hutool/v7/core/reflect/kotlin/KClassUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/v7/core/reflect/kotlin/KClassUtilTest.java @@ -38,7 +38,7 @@ public class KClassUtilTest { final List constructors = KClassUtil.getConstructors(TestKBean.class); Assertions.assertEquals(1, constructors.size()); - Assertions.assertEquals("kotlin.reflect.jvm.internal.KFunctionImpl", + Assertions.assertEquals("kotlin.reflect.jvm.internal.DescriptorKFunction", constructors.get(0).getClass().getName()); } diff --git a/hutool-jmh/pom.xml b/hutool-jmh/pom.xml index fce080b3a3..00a3f58ac7 100644 --- a/hutool-jmh/pom.xml +++ b/hutool-jmh/pom.xml @@ -25,7 +25,7 @@ cn.hutool.v7 hutool-parent - 7.0.0.M1 + 7.0.0-M5-SNAPSHOT hutool-jmh @@ -37,6 +37,11 @@ true 1.37 + + 2.20.1 + 2.0.60 + 2.13.2 + 1.15.2 @@ -89,7 +94,7 @@ com.squareup.moshi moshi - 1.15.1 + ${moshi.version} test diff --git a/hutool-json/pom.xml b/hutool-json/pom.xml index 7c556876f1..0a19e02037 100755 --- a/hutool-json/pom.xml +++ b/hutool-json/pom.xml @@ -36,8 +36,8 @@ cn.hutool.v7.json 0.13.0 - 2.20.0 - 2.0.59 + 2.20.1 + 2.0.60 2.13.2 1.15.2 diff --git a/hutool-json/src/test/java/cn/hutool/v7/json/kotlin/JsonToKotlinBeanTest.java b/hutool-json/src/test/java/cn/hutool/v7/json/kotlin/JsonToKotlinBeanTest.java new file mode 100644 index 0000000000..a745265d35 --- /dev/null +++ b/hutool-json/src/test/java/cn/hutool/v7/json/kotlin/JsonToKotlinBeanTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2026 Hutool Team. + * + * Licensed 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 cn.hutool.v7.json.kotlin; + +import cn.hutool.v7.json.JSONUtil; +import com.alibaba.fastjson2.JSON; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JsonToKotlinBeanTest { + @Test + void toBeanTest() { + final TestKBeanForJson bean = JSONUtil.parseObj("{\"id\":\"VampireAchao\", \"name\":\"阿超\", \"country\":\"中国\"}").toBean(TestKBeanForJson.class); + assertEquals("VampireAchao", bean.getId()); + assertEquals("阿超", bean.getName()); + assertEquals("中国", bean.getCountry()); + } + + @Test + void toBeanByFastJsonTest() { + final TestKBeanForJson javaObject = JSON.parseObject("{\"id\":\"VampireAchao\", \"name\":\"阿超\", \"country\":\"中国\"}").toJavaObject(TestKBeanForJson.class); + assertEquals("VampireAchao", javaObject.getId()); + assertEquals("阿超", javaObject.getName()); + assertEquals("中国", javaObject.getCountry()); + } +} diff --git a/hutool-json/src/test/java/cn/hutool/v7/json/kotlin/TestKBeanForJson.kt b/hutool-json/src/test/java/cn/hutool/v7/json/kotlin/TestKBeanForJson.kt new file mode 100644 index 0000000000..32ef6cea01 --- /dev/null +++ b/hutool-json/src/test/java/cn/hutool/v7/json/kotlin/TestKBeanForJson.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2026 Hutool Team. + * + * Licensed 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 cn.hutool.v7.json.kotlin + +data class TestKBeanForJson(val id: String, var name: String?, var country: String?){ + init { + //println("CTOR called: id=$id, name=$name, country=$country") + } +} diff --git a/pom.xml b/pom.xml index 4afca93c50..8aefbcc8e2 100755 --- a/pom.xml +++ b/pom.xml @@ -47,19 +47,24 @@ hutool-socket hutool-swing hutool-ai + + hutool-jmh - utf-8 - utf-8 + UTF-8 + UTF-8 + UTF-8 cn.hutool.v7 + + -Dfile.encoding=UTF-8 17 - 6.0.0 + 6.0.1 1.18.42 - 2.2.20 - 1.82 + 2.3.0 + 1.83 @@ -217,7 +222,7 @@ org.codehaus.mojo versions-maven-plugin - 2.19.1 + 2.20.1 false @@ -257,7 +262,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.1 + 3.4.0 oss