11/*
2- * Copyright 2002-2023 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -93,7 +93,6 @@ class BeanUtilsKotlinTests {
9393 @Test
9494 fun `Instantiate value class` () {
9595 val constructor = BeanUtils .findPrimaryConstructor(ValueClass ::class .java)!!
96- assertThat(constructor ).isNotNull()
9796 val value = " Hello value class!"
9897 val instance = BeanUtils .instantiateClass(constructor , value)
9998 assertThat(instance).isEqualTo(ValueClass (value))
@@ -102,7 +101,6 @@ class BeanUtilsKotlinTests {
102101 @Test
103102 fun `Instantiate value class with multiple constructors` () {
104103 val constructor = BeanUtils .findPrimaryConstructor(ValueClassWithMultipleConstructors ::class .java)!!
105- assertThat(constructor ).isNotNull()
106104 val value = " Hello value class!"
107105 val instance = BeanUtils .instantiateClass(constructor , value)
108106 assertThat(instance).isEqualTo(ValueClassWithMultipleConstructors (value))
@@ -111,7 +109,6 @@ class BeanUtilsKotlinTests {
111109 @Test
112110 fun `Instantiate class with value class parameter` () {
113111 val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithValueClass ::class .java)!!
114- assertThat(constructor ).isNotNull()
115112 val value = ValueClass (" Hello value class!" )
116113 val instance = BeanUtils .instantiateClass(constructor , value)
117114 assertThat(instance).isEqualTo(ConstructorWithValueClass (value))
@@ -120,7 +117,6 @@ class BeanUtilsKotlinTests {
120117 @Test
121118 fun `Instantiate class with nullable value class parameter` () {
122119 val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithNullableValueClass ::class .java)!!
123- assertThat(constructor ).isNotNull()
124120 val value = ValueClass (" Hello value class!" )
125121 var instance = BeanUtils .instantiateClass(constructor , value)
126122 assertThat(instance).isEqualTo(ConstructorWithNullableValueClass (value))
@@ -131,7 +127,6 @@ class BeanUtilsKotlinTests {
131127 @Test
132128 fun `Instantiate primitive value class` () {
133129 val constructor = BeanUtils .findPrimaryConstructor(PrimitiveValueClass ::class .java)!!
134- assertThat(constructor ).isNotNull()
135130 val value = 0
136131 val instance = BeanUtils .instantiateClass(constructor , value)
137132 assertThat(instance).isEqualTo(PrimitiveValueClass (value))
@@ -140,7 +135,6 @@ class BeanUtilsKotlinTests {
140135 @Test
141136 fun `Instantiate class with primitive value class parameter` () {
142137 val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithPrimitiveValueClass ::class .java)!!
143- assertThat(constructor ).isNotNull()
144138 val value = PrimitiveValueClass (0 )
145139 val instance = BeanUtils .instantiateClass(constructor , value)
146140 assertThat(instance).isEqualTo(ConstructorWithPrimitiveValueClass (value))
@@ -149,14 +143,55 @@ class BeanUtilsKotlinTests {
149143 @Test
150144 fun `Instantiate class with nullable primitive value class parameter` () {
151145 val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithNullablePrimitiveValueClass ::class .java)!!
152- assertThat(constructor ).isNotNull()
153146 val value = PrimitiveValueClass (0 )
154147 var instance = BeanUtils .instantiateClass(constructor , value)
155148 assertThat(instance).isEqualTo(ConstructorWithNullablePrimitiveValueClass (value))
156149 instance = BeanUtils .instantiateClass(constructor , null )
157150 assertThat(instance).isEqualTo(ConstructorWithNullablePrimitiveValueClass (null ))
158151 }
159152
153+ @Test
154+ fun `Get parameter names with Foo` () {
155+ val ctor = BeanUtils .findPrimaryConstructor(Foo ::class .java)!!
156+ val names = BeanUtils .getParameterNames(ctor)
157+ assertThat(names).containsExactly(" param1" , " param2" )
158+ }
159+
160+ @Test
161+ fun `Get parameter names filters out DefaultConstructorMarker with ConstructorWithValueClass` () {
162+ val ctor = BeanUtils .findPrimaryConstructor(ConstructorWithValueClass ::class .java)!!
163+ val names = BeanUtils .getParameterNames(ctor)
164+ assertThat(names).containsExactly(" value" )
165+ }
166+
167+ @Test
168+ fun `getParameterNames filters out DefaultConstructorMarker with ConstructorWithNullableValueClass` () {
169+ val ctor = BeanUtils .findPrimaryConstructor(ConstructorWithNullableValueClass ::class .java)!!
170+ val names = BeanUtils .getParameterNames(ctor)
171+ assertThat(names).containsExactly(" value" )
172+ }
173+
174+ @Test
175+ fun `getParameterNames filters out DefaultConstructorMarker with ConstructorWithPrimitiveValueClass` () {
176+ val ctor = BeanUtils .findPrimaryConstructor(ConstructorWithPrimitiveValueClass ::class .java)!!
177+ val names = BeanUtils .getParameterNames(ctor)
178+ assertThat(names).containsExactly(" value" )
179+ }
180+
181+ @Test
182+ fun `getParameterNames filters out DefaultConstructorMarker with ConstructorWithNullablePrimitiveValueClass` () {
183+ val ctor = BeanUtils .findPrimaryConstructor(ConstructorWithNullablePrimitiveValueClass ::class .java)!!
184+ val names = BeanUtils .getParameterNames(ctor)
185+ assertThat(names).containsExactly(" value" )
186+ }
187+
188+ @Test
189+ fun `getParameterNames with ClassWithZeroParameterCtor` () {
190+ val ctor = BeanUtils .findPrimaryConstructor(ClassWithZeroParameterCtor ::class .java)!!
191+ val names = BeanUtils .getParameterNames(ctor)
192+ assertThat(names).isEmpty()
193+ }
194+
160195
161196 class Foo (val param1 : String , val param2 : Int )
162197
@@ -216,4 +251,6 @@ class BeanUtilsKotlinTests {
216251
217252 data class ConstructorWithNullablePrimitiveValueClass (val value : PrimitiveValueClass ? )
218253
254+ class ClassWithZeroParameterCtor ()
255+
219256}
0 commit comments