naver / fixture-monkey

Let Fixture Monkey generate test instances including edge cases automatically
https://naver.github.io/fixture-monkey
Apache License 2.0
560 stars 89 forks source link

Add KotlinAndJavaCompositeArbitraryIntrospector for supporting instantiating kotlin class with java reference Type #948

Closed jinia91 closed 6 months ago

jinia91 commented 6 months ago

This is a pr regarding the issue at https://github.com/naver/fixture-monkey/issues/946

I have implemented the KotlinAndJavaCompositeArbitraryIntrospector to facilitate the smooth creation of objects for Kotlin classes that have Java classes as properties.

~The default Kotlin plugin uses this ArbitraryIntrospector but has been modified to accept other Introspector as a plugin argument.~

additionaly added a corresponding test case.

~I personally feel that modifying the behavior of the default kotlin plugin is a bit excessive, so I hope the maintainer will make an appropriate judgment and edit.🙏~ => only imple KotlinAndJavaCompositeArbitraryIntrospector

add KotlinAndJavaCompositeArbitraryIntrospector benchmark

How Has This Been Tested?

check through test case

Is the Document updated?

add KotlinAndJavaCompositeArbitraryIntrospector in introspectors-for-kotlin

seongahjo commented 6 months ago

@jinia91 Hello, thank you for your contributing. It is a known issue so PrimaryConstructorArbitraryIntrospector would implements Matcher in 1.1.x so that it generates only a Kotlin type instance.

Your approach seems to be a good intermediate step in 1.0.x, but I am worried about whether it would cause any performance problems.

Can you add a new benchmark for KotlinAndJavaCompositeArbitraryIntrospector using jmh?

jinia91 commented 6 months ago
Benchmark Mode Threads Samples Score Score Error (99.9%) Unit
com.navercorp.fixturemonkey.ManipulationBenchmark.fixed avgt 1 10 586.739041 3.623991 ms/op
com.navercorp.fixturemonkey.ManipulationBenchmark.thenApply avgt 1 10 1341.850457 8.021999 ms/op
com.navercorp.fixturemonkey.ObjectGenerationBenchmark.beanGenerateOrderSheetWithFixtureMonkey avgt 1 10 596.574669 6.019172 ms/op
com.navercorp.fixturemonkey.ObjectGenerationBenchmark.builderGenerateOrderSheetWithFixtureMonkey avgt 1 10 505.341249 4.760138 ms/op
com.navercorp.fixturemonkey.ObjectGenerationBenchmark.fieldReflectionGenerateOrderSheetWithFixtureMonkey avgt 1 10 594.315525 10.230895 ms/op
com.navercorp.fixturemonkey.ObjectGenerationBenchmark.jacksonGenerateOrderSheetWithFixtureMonkey avgt 1 10 666.664955 3.442750 ms/op
Benchmark Mode Threads Samples Score Score Error (99.9%) Unit
com.navercorp.fixturemonkey.kotlin.KotlinObjectGenerationBenchMark.beanGenerateJavaOrderSheetWithFixtureMonkey avgt 1 10 1015.830312 11.054345 ms/op
com.navercorp.fixturemonkey.kotlin.KotlinObjectGenerationBenchMark.beanGenerateKotlinJavaCompositeOrderSheetWithFixtureMonkey avgt 1 10 1009.098525 12.771965 ms/op
com.navercorp.fixturemonkey.kotlin.KotlinObjectGenerationBenchMark.beanGenerateKotlinOrderSheetWithFixtureMonkey avgt 1 10 1040.497933 21.421765 ms/op