|
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.
|
@@ -157,6 +157,48 @@ class BeanUtilsKotlinTests {
|
157 | 157 | assertThat(instance).isEqualTo(ConstructorWithNullablePrimitiveValueClass(null))
|
158 | 158 | }
|
159 | 159 |
|
| 160 | + @Test |
| 161 | + fun `Get parameter names with Foo`() { |
| 162 | + val ctor = BeanUtils.findPrimaryConstructor(Foo::class.java)!! |
| 163 | + val names = BeanUtils.getParameterNames(ctor) |
| 164 | + assertThat(names).containsExactly("param1", "param2") |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + fun `Get parameter names filters out DefaultConstructorMarker with ConstructorWithValueClass`() { |
| 169 | + val ctor = BeanUtils.findPrimaryConstructor(ConstructorWithValueClass::class.java)!! |
| 170 | + val names = BeanUtils.getParameterNames(ctor) |
| 171 | + assertThat(names).containsExactly("value") |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + fun `getParameterNames filters out DefaultConstructorMarker with ConstructorWithNullableValueClass`() { |
| 176 | + val ctor = BeanUtils.findPrimaryConstructor(ConstructorWithNullableValueClass::class.java)!! |
| 177 | + val names = BeanUtils.getParameterNames(ctor) |
| 178 | + assertThat(names).containsExactly("value") |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + fun `getParameterNames filters out DefaultConstructorMarker with ConstructorWithPrimitiveValueClass`() { |
| 183 | + val ctor = BeanUtils.findPrimaryConstructor(ConstructorWithPrimitiveValueClass::class.java)!! |
| 184 | + val names = BeanUtils.getParameterNames(ctor) |
| 185 | + assertThat(names).containsExactly("value") |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + fun `getParameterNames filters out DefaultConstructorMarker with ConstructorWithNullablePrimitiveValueClass`() { |
| 190 | + val ctor = BeanUtils.findPrimaryConstructor(ConstructorWithNullablePrimitiveValueClass::class.java)!! |
| 191 | + val names = BeanUtils.getParameterNames(ctor) |
| 192 | + assertThat(names).containsExactly("value") |
| 193 | + } |
| 194 | + |
| 195 | + @Test |
| 196 | + fun `getParameterNames with ClassWithZeroParameterCtor`() { |
| 197 | + val ctor = BeanUtils.findPrimaryConstructor(ClassWithZeroParameterCtor::class.java)!! |
| 198 | + val names = BeanUtils.getParameterNames(ctor) |
| 199 | + assertThat(names).isEmpty() |
| 200 | + } |
| 201 | + |
160 | 202 |
|
161 | 203 | class Foo(val param1: String, val param2: Int)
|
162 | 204 |
|
@@ -216,4 +258,6 @@ class BeanUtilsKotlinTests {
|
216 | 258 |
|
217 | 259 | data class ConstructorWithNullablePrimitiveValueClass(val value: PrimitiveValueClass?)
|
218 | 260 |
|
| 261 | + class ClassWithZeroParameterCtor() |
| 262 | + |
219 | 263 | }
|
0 commit comments