Skip to content

Commit

Permalink
add: access to private constructor (when constructing value class)
Browse files Browse the repository at this point in the history
  • Loading branch information
msugo1 committed Jan 31, 2024
1 parent ceeddf3 commit 0ceaaa2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class PrimaryConstructorArbitraryIntrospector : ArbitraryIntrospector {
try {
val parameterKotlinType = parameter.type.jvmErasure
return if (parameterKotlinType.isValue) {
parameterKotlinType.primaryConstructor!!.isAccessible = true
parameterKotlinType.primaryConstructor!!.call(arbitrariesByPropertyName[parameter.name])
} else {
arbitrariesByPropertyName[parameter.name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,38 @@ class ValueClassTest {
then(actual.foo).isNotNull
}

@Test
fun privateConstructorValueClassProperty() {
class ValueClassObject(val foo: FooWithPrivateConstructor)

val actual: ValueClassObject = SUT.giveMeOne()

then(actual).isNotNull
then(actual.foo).isNotNull
}

@Test
fun privateConstructorValueClassPropertyFixed() {
class ValueClassObject(val foo: FooWithPrivateConstructor)

val actual: ValueClassObject = SUT.giveMeBuilder<ValueClassObject>()
.fixed()
.sample()

then(actual).isNotNull
then(actual.foo).isNotNull
}

@JvmInline
value class Foo(
val bar: String,
)

@JvmInline
value class FooWithPrivateConstructor private constructor(
val bar: String
)

companion object {
private val SUT = FixtureMonkey.builder()
.plugin(KotlinPlugin())
Expand Down

0 comments on commit 0ceaaa2

Please sign in to comment.