Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.time.LocalDate

/**
* @author Mark Paluch
* @author Edward Poot
*/
@JvmInline
value class MyValueClass(val id: String)
Expand All @@ -46,6 +47,10 @@ data class WithMyValueClass(val id: MyValueClass) {
// ---------
}

data class WithMyValueClassPrivateConstructor private constructor(val id: MyValueClass)

data class WithMyValueClassPrivateConstructorAndDefaultValue private constructor(val id: MyValueClass = MyValueClass("id"))

@JvmInline
value class MyNullableValueClass(val id: String? = "id")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import kotlin.reflect.KClass
*
* @author Mark Paluch
* @author Sebastien Deleuze
* @author Edward Poot
*/
@Suppress("UNCHECKED_CAST")
class KotlinClassGeneratingEntityInstantiatorUnitTests {
Expand Down Expand Up @@ -189,6 +190,24 @@ class KotlinClassGeneratingEntityInstantiatorUnitTests {
assertThat(instance.id.id).isEqualTo("hello")
}

@Test // GH-3389
fun `should use private default constructor for types using value class`() {

every { provider.getParameterValue<String>(any()) } returns "hello"
val instance = construct(WithMyValueClassPrivateConstructor::class)

assertThat(instance.id.id).isEqualTo("hello")
}

@Test // GH-3389
fun `should use private default constructor for types using value class with default value`() {

every { provider.getParameterValue<String>(any()) } returns "hello"
val instance = construct(WithMyValueClassPrivateConstructorAndDefaultValue::class)

assertThat(instance.id.id).isEqualTo("hello")
}

@Test
fun `should use default constructor for types using nullable value class`() {

Expand Down