data class Product(
val interests: ProductInterests
)
data class ProductInterests(
val minRate: ProductInterestRate,
val maxRate: ProductInterestRate
)
@JvmInline
value class ProductInterestRate private constructor(
val value: BigDecimal
) {
companion object {
fun from(value: BigDecimal): ProductInterestRate = ProductInterestRate(value.setScale(2,RoundingMode.HALF_EVEN))
}
}
테스트코드
class FixtureMonkeyTest {
private val fixtureMonkey = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.build()
@Test
fun `create fixture`() {
// given
val builder = fixtureMonkey.giveMeBuilder(Product::class.java)
// when
val obj = builder.sample()
// then
obj.shouldNotBeNull()
}
}
위와 같이 value class 가 private constructor를 가질 경우 테스트 객체 생성에 실패합니다.
Tell us how to reproduce this issue.Or provide us an example repository to check the bug
Expected behaviour
테스트 객체 생성 성공
Actual behaviour
java.lang.IllegalArgumentException: object is not an instance of declaring class
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at kotlin.reflect.jvm.internal.calls.ValueClassAwareCaller.call(ValueClassAwareCaller.kt:179)
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:200)
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112)
at com.navercorp.fixturemonkey.kotlin.introspector.PrimaryConstructorArbitraryIntrospector.introspect$lambda$3(PrimaryConstructorArbitraryIntrospector.kt:72)
at com.navercorp.fixturemonkey.api.arbitrary.ObjectCombinableArbitrary.combined(ObjectCombinableArbitrary.java:54)
at com.navercorp.fixturemonkey.api.arbitrary.NullInjectCombinableArbitrary.combined(NullInjectCombinableArbitrary.java:46)
at com.navercorp.fixturemonkey.api.arbitrary.TraceableCombinableArbitrary.combined(TraceableCombinableArbitrary.java:42)
at com.navercorp.fixturemonkey.api.arbitrary.ObjectCombinableArbitrary.lambda$combined$0(ObjectCombinableArbitrary.java:51)
at java.base/java.util.HashMap.forEach(HashMap.java:1421)
at com.navercorp.fixturemonkey.api.arbitrary.ObjectCombinableArbitrary.combined(ObjectCombinableArbitrary.java:50)
at com.navercorp.fixturemonkey.api.arbitrary.NullInjectCombinableArbitrary.combined(NullInjectCombinableArbitrary.java:46)
at com.navercorp.fixturemonkey.api.arbitrary.TraceableCombinableArbitrary.combined(TraceableCombinableArbitrary.java:42)
at com.navercorp.fixturemonkey.api.arbitrary.FilteredCombinableArbitrary.combined(FilteredCombinableArbitrary.java:73)
at com.navercorp.fixturemonkey.resolver.ResolvedCombinableArbitrary.combined(ResolvedCombinableArbitrary.java:77)
at com.navercorp.fixturemonkey.resolver.DefaultArbitraryBuilder.sample(DefaultArbitraryBuilder.java:489)
Describe the bug
대상 모델
테스트코드
위와 같이 value class 가 private constructor를 가질 경우 테스트 객체 생성에 실패합니다.
Your environment
build.gradle.kts
Steps to reproduce
Tell us how to reproduce this issue. Or provide us an example repository to check the bug
Expected behaviour
테스트 객체 생성 성공
Actual behaviour