Skip to content
Merged
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 @@ -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 @@ -5,6 +5,7 @@ import com.navercorp.fixturemonkey.api.instantiator.Instantiator
import com.navercorp.fixturemonkey.api.instantiator.Instantiator.constructor
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin
import com.navercorp.fixturemonkey.kotlin.giveMeBuilder
import com.navercorp.fixturemonkey.kotlin.giveMeOne
import com.navercorp.fixturemonkey.kotlin.instantiator.instantiateBy
import com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT
import org.assertj.core.api.BDDAssertions.then
Expand Down Expand Up @@ -446,6 +447,16 @@ class InstantiatorTest {
then(actual).isNotNull()
}

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

val actual = SUT.giveMeOne<PrivateConstructorObject>()
.value

then(actual).isNotNull()
}

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