From 73c3368af4e9bbfeb7b244db95bd08857faebbab Mon Sep 17 00:00:00 2001 From: jinia91 Date: Mon, 18 Dec 2023 14:46:31 +0900 Subject: [PATCH 1/2] add:private access and testcode --- .../PrimaryConstructorArbitraryIntrospector.kt | 2 ++ .../fixturemonkey/tests/kotlin/InstantiatorTest.kt | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/fixture-monkey-kotlin/src/main/kotlin/com/navercorp/fixturemonkey/kotlin/introspector/PrimaryConstructorArbitraryIntrospector.kt b/fixture-monkey-kotlin/src/main/kotlin/com/navercorp/fixturemonkey/kotlin/introspector/PrimaryConstructorArbitraryIntrospector.kt index e9b610900..1e8d22c87 100644 --- a/fixture-monkey-kotlin/src/main/kotlin/com/navercorp/fixturemonkey/kotlin/introspector/PrimaryConstructorArbitraryIntrospector.kt +++ b/fixture-monkey-kotlin/src/main/kotlin/com/navercorp/fixturemonkey/kotlin/introspector/PrimaryConstructorArbitraryIntrospector.kt @@ -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 { @@ -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 } diff --git a/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt b/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt index 8359a2fb8..865ca12c5 100644 --- a/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt +++ b/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt @@ -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() + .sample() + .value + + then(actual).isNotNull() + } + @RepeatedTest(TEST_COUNT) fun instantiateDefaultArgumentConstructor() { class ConstructorObject(val value: String = "default") From 416dda2b15ea69ee83a232b7a27a840c25e81acc Mon Sep 17 00:00:00 2001 From: jinia91 Date: Mon, 18 Dec 2023 16:28:17 +0900 Subject: [PATCH 2/2] feed: giveMeBuilder -> giveMeOne --- .../navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt b/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt index 865ca12c5..a095498e9 100644 --- a/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt +++ b/fixture-monkey-tests/kotlin-tests/src/test/kotlin/com/navercorp/fixturemonkey/tests/kotlin/InstantiatorTest.kt @@ -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 @@ -450,8 +451,7 @@ class InstantiatorTest { fun instantiatePrivateConstructorWithoutInstantiate() { class PrivateConstructorObject private constructor(val value: String) - val actual = SUT.giveMeBuilder() - .sample() + val actual = SUT.giveMeOne() .value then(actual).isNotNull()