1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -93,7 +93,6 @@ class BeanUtilsKotlinTests {
93
93
@Test
94
94
fun `Instantiate value class` () {
95
95
val constructor = BeanUtils .findPrimaryConstructor(ValueClass ::class .java)!!
96
- assertThat(constructor ).isNotNull()
97
96
val value = " Hello value class!"
98
97
val instance = BeanUtils .instantiateClass(constructor , value)
99
98
assertThat(instance).isEqualTo(ValueClass (value))
@@ -102,7 +101,6 @@ class BeanUtilsKotlinTests {
102
101
@Test
103
102
fun `Instantiate value class with multiple constructors` () {
104
103
val constructor = BeanUtils .findPrimaryConstructor(ValueClassWithMultipleConstructors ::class .java)!!
105
- assertThat(constructor ).isNotNull()
106
104
val value = " Hello value class!"
107
105
val instance = BeanUtils .instantiateClass(constructor , value)
108
106
assertThat(instance).isEqualTo(ValueClassWithMultipleConstructors (value))
@@ -111,7 +109,6 @@ class BeanUtilsKotlinTests {
111
109
@Test
112
110
fun `Instantiate class with value class parameter` () {
113
111
val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithValueClass ::class .java)!!
114
- assertThat(constructor ).isNotNull()
115
112
val value = ValueClass (" Hello value class!" )
116
113
val instance = BeanUtils .instantiateClass(constructor , value)
117
114
assertThat(instance).isEqualTo(ConstructorWithValueClass (value))
@@ -120,7 +117,6 @@ class BeanUtilsKotlinTests {
120
117
@Test
121
118
fun `Instantiate class with nullable value class parameter` () {
122
119
val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithNullableValueClass ::class .java)!!
123
- assertThat(constructor ).isNotNull()
124
120
val value = ValueClass (" Hello value class!" )
125
121
var instance = BeanUtils .instantiateClass(constructor , value)
126
122
assertThat(instance).isEqualTo(ConstructorWithNullableValueClass (value))
@@ -131,7 +127,6 @@ class BeanUtilsKotlinTests {
131
127
@Test
132
128
fun `Instantiate primitive value class` () {
133
129
val constructor = BeanUtils .findPrimaryConstructor(PrimitiveValueClass ::class .java)!!
134
- assertThat(constructor ).isNotNull()
135
130
val value = 0
136
131
val instance = BeanUtils .instantiateClass(constructor , value)
137
132
assertThat(instance).isEqualTo(PrimitiveValueClass (value))
@@ -140,7 +135,6 @@ class BeanUtilsKotlinTests {
140
135
@Test
141
136
fun `Instantiate class with primitive value class parameter` () {
142
137
val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithPrimitiveValueClass ::class .java)!!
143
- assertThat(constructor ).isNotNull()
144
138
val value = PrimitiveValueClass (0 )
145
139
val instance = BeanUtils .instantiateClass(constructor , value)
146
140
assertThat(instance).isEqualTo(ConstructorWithPrimitiveValueClass (value))
@@ -149,14 +143,55 @@ class BeanUtilsKotlinTests {
149
143
@Test
150
144
fun `Instantiate class with nullable primitive value class parameter` () {
151
145
val constructor = BeanUtils .findPrimaryConstructor(ConstructorWithNullablePrimitiveValueClass ::class .java)!!
152
- assertThat(constructor ).isNotNull()
153
146
val value = PrimitiveValueClass (0 )
154
147
var instance = BeanUtils .instantiateClass(constructor , value)
155
148
assertThat(instance).isEqualTo(ConstructorWithNullablePrimitiveValueClass (value))
156
149
instance = BeanUtils .instantiateClass(constructor , null )
157
150
assertThat(instance).isEqualTo(ConstructorWithNullablePrimitiveValueClass (null ))
158
151
}
159
152
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
+
160
195
161
196
class Foo (val param1 : String , val param2 : Int )
162
197
@@ -216,4 +251,6 @@ class BeanUtilsKotlinTests {
216
251
217
252
data class ConstructorWithNullablePrimitiveValueClass (val value : PrimitiveValueClass ? )
218
253
254
+ class ClassWithZeroParameterCtor ()
255
+
219
256
}
0 commit comments