@@ -128,6 +128,35 @@ class BeanUtilsKotlinTests {
128
128
assertThat(instance).isEqualTo(OneConstructorWithNullableValueClass (null ))
129
129
}
130
130
131
+ @Test
132
+ fun `Instantiate primitive value class` () {
133
+ val constructor = BeanUtils .findPrimaryConstructor(PrimitiveValueClass ::class .java)!!
134
+ assertThat(constructor ).isNotNull()
135
+ val value = 0
136
+ val instance = BeanUtils .instantiateClass(constructor , value)
137
+ assertThat(instance).isEqualTo(PrimitiveValueClass (value))
138
+ }
139
+
140
+ @Test
141
+ fun `Instantiate class with primitive value class parameter` () {
142
+ val constructor = BeanUtils .findPrimaryConstructor(OneConstructorWithPrimitiveValueClass ::class .java)!!
143
+ assertThat(constructor ).isNotNull()
144
+ val value = PrimitiveValueClass (0 )
145
+ val instance = BeanUtils .instantiateClass(constructor , value)
146
+ assertThat(instance).isEqualTo(OneConstructorWithPrimitiveValueClass (value))
147
+ }
148
+
149
+ @Test
150
+ fun `Instantiate class with nullable primitive value class parameter` () {
151
+ val constructor = BeanUtils .findPrimaryConstructor(OneConstructorWithNullablePrimitiveValueClass ::class .java)!!
152
+ assertThat(constructor ).isNotNull()
153
+ val value = PrimitiveValueClass (0 )
154
+ var instance = BeanUtils .instantiateClass(constructor , value)
155
+ assertThat(instance).isEqualTo(OneConstructorWithNullablePrimitiveValueClass (value))
156
+ instance = BeanUtils .instantiateClass(constructor , null )
157
+ assertThat(instance).isEqualTo(OneConstructorWithNullablePrimitiveValueClass (null ))
158
+ }
159
+
131
160
132
161
class Foo (val param1 : String , val param2 : Int )
133
162
@@ -180,4 +209,11 @@ class BeanUtilsKotlinTests {
180
209
181
210
data class OneConstructorWithNullableValueClass (val value : ValueClass ? )
182
211
212
+ @JvmInline
213
+ value class PrimitiveValueClass (private val value : Int )
214
+
215
+ data class OneConstructorWithPrimitiveValueClass (val value : PrimitiveValueClass )
216
+
217
+ data class OneConstructorWithNullablePrimitiveValueClass (val value : PrimitiveValueClass ? )
218
+
183
219
}
0 commit comments