Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin private primary constructor access #848

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -32,6 +32,7 @@ import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.KParameter
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.jvm.isAccessible

@API(since = "0.4.0", status = MAINTAINED)
class PrimaryConstructorArbitraryIntrospector : ArbitraryIntrospector {
Expand All @@ -54,6 +55,7 @@ class PrimaryConstructorArbitraryIntrospector : ArbitraryIntrospector {
val constructor = CONSTRUCTOR_CACHE.computeIfAbsent(type) {
requireNotNull(kotlinClass.primaryConstructor) { "No kotlin primary constructor provided for $kotlinClass" }
}
constructor.isAccessible = true

val arbitrariesByPropertyName = it.mapKeys { map -> map.key.objectProperty.property.name }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,17 @@ class InstantiatorTest {
then(actual).isNotNull()
}

@RepeatedTest(TEST_COUNT)
fun instantiatePrivateConstructorWithoutInstantiate() {
class PrivateConstructorObject private constructor(val value: String)

val actual = SUT.giveMeBuilder<PrivateConstructorObject>()
.sample()
jinia91 marked this conversation as resolved.
Show resolved Hide resolved
.value

then(actual).isNotNull()
}

@RepeatedTest(TEST_COUNT)
fun instantiateDefaultArgumentConstructor() {
class ConstructorObject(val value: String = "default")
Expand Down
Loading