From 1ed8ad7fda2529b7293b09bc31b5b3a6cddfcb10 Mon Sep 17 00:00:00 2001 From: "ah.jo" Date: Sat, 10 Aug 2024 19:14:46 +0900 Subject: [PATCH] Publish 1.0.23 version --- README.md | 8 +-- build.gradle.kts | 2 +- docs/config/_default/params.toml | 2 +- .../generating-interface.md | 71 ++++++++++++++++++- .../v1.0.x-kor/release-notes/_index.md | 8 +++ .../generating-interface.md | 68 ++++++++++++++++++ docs/content/v1.0.x/release-notes/_index.md | 9 +++ 7 files changed, 161 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 739855145..baa365fa4 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,13 @@ Each primitive type property is generated by [Jqwik](https://github.com/jlink/jq #### Java ```groovy -testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.22") +testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.23") ``` #### Kotlin ```groovy -testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.0.22") +testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.0.23") ``` ### Maven @@ -49,7 +49,7 @@ testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1. com.navercorp.fixturemonkey fixture-monkey-starter - 1.0.22 + 1.0.23 test ``` @@ -60,7 +60,7 @@ testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1. com.navercorp.fixturemonkey fixture-monkey-starter-kotlin - 1.0.22 + 1.0.23 test ``` diff --git a/build.gradle.kts b/build.gradle.kts index d8e2a40c8..5f2808bfb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { group = "com.navercorp.fixturemonkey" - version = "1.0.23-SNAPSHOT" + version = "1.0.23" } subprojects { diff --git a/docs/config/_default/params.toml b/docs/config/_default/params.toml index 326c7eb78..ec8b8443c 100644 --- a/docs/config/_default/params.toml +++ b/docs/config/_default/params.toml @@ -8,7 +8,7 @@ description = "" ## Documentation docsVersion = "1.0.0" -fixtureMonkeyVersion = "1.0.22" +fixtureMonkeyVersion = "1.0.23" ## Open Graph images = ["fixtureMonkey.png"] diff --git a/docs/content/v1.0.x-kor/docs/generating-objects/generating-interface.md b/docs/content/v1.0.x-kor/docs/generating-objects/generating-interface.md index c2b1c8688..e45e0d355 100644 --- a/docs/content/v1.0.x-kor/docs/generating-objects/generating-interface.md +++ b/docs/content/v1.0.x-kor/docs/generating-objects/generating-interface.md @@ -29,7 +29,7 @@ public interface StringSupplier { public class DefaultStringSupplier implements StringSupplier { private final String value; - @ConstructorProperties("value") // It is not needed if you are using Lombok. + @ConstructorProperties("value") // 롬복을 사용하면 추가하지 않아도 됩니다. public DefaultStringSupplier(String value) { this.value = value; } @@ -122,6 +122,75 @@ List list = fixture.giveMeOne(new TypeReference>() { 이렇게 설정하면 `List` 인터페이스의 설정이 `Collection` 인터페이스에 영향을 줍니다. 구체적으로 이야기하면 `List` 인터페이스는 기본 설정으로 구현체 `ArrayList`를 생성하므로 `Collection` 인터페이스는 `ArrayList`를 생성합니다. + +추가할 인터페이스 구현체들이 많은데 일정한 패턴을 가지고 있다면 다음과 같이 사용하면 편하게 처리할 수 있습니다. + +```java +interface ObjectValueSupplier { + Object getValue(); +} + +interface StringValueSupplier extends ObjectValueSupplier { + String getValue(); +} + +public class DefaultStringValueSupplier implements StringValueSupplier { + private final String value; + + @ConstructorProperties("value") // 롬복을 사용하면 추가하지 않아도 됩니다. + public DefaultStringValueSupplier(String value) { + this.value = value; + } + + @Override + public String getValue() { + return this.value; + } +} + +interface IntegerValueSupplier extends ObjectValueSupplier { + Integer getValue(); +} + +public class DefaultIntegerValueSupplier implements IntegerValueSupplier { + private final Integer value; + + @ConstructorProperties("value") // 롬복을 사용하면 추가하지 않아도 됩니다. + public DefaultIntegerValueSupplier(Integer value) { + this.value = value; + } + + @Override + public Integer getValue() { + return this.value; + } +} + +FixtureMonkey fixture = FixtureMonkey.builder() + .objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) + .plugin( + new InterfacePlugin() + .interfaceImplements( + new AssignableTypeMatcher(ObjectValueSupplier.class), + property -> { + Class actualType = Types.getActualType(property.getType()); + if (StringValueSupplier.class.isAssignableFrom(actualType)) { + return List.of(PropertyUtils.toProperty(DefaultStringValueSupplier.class)); + } + + if (IntegerValueSupplier.class.isAssignableFrom(actualType)) { + return List.of(PropertyUtils.toProperty(DefaultIntegerValueSupplier.class)); + } + return List.of(); + } + ) + ) + .build(); + +DefaultStringValueSupplier stringValueSupplier = (DefaultStringValueSupplier)fixture.giveMeOne(StringValueSupplier.class); +DefaultIntegerValueSupplier integerValueSupplier = (DefaultIntegerValueSupplier)fixture.giveMeOne(IntegerValueSupplier.class); +``` + ```java FixtureMonkey fixture = FixtureMonkey.builder() .plugin( diff --git a/docs/content/v1.0.x-kor/release-notes/_index.md b/docs/content/v1.0.x-kor/release-notes/_index.md index 29d08e3c2..862da18a9 100644 --- a/docs/content/v1.0.x-kor/release-notes/_index.md +++ b/docs/content/v1.0.x-kor/release-notes/_index.md @@ -6,6 +6,14 @@ docs: weight: 100 --- +sectionStart +### v.1.0.23 +Add the flexible option for complex usage in InterfacePlugin. + +Fix for generating Kotlin self-reference with default arguments. + +sectionEnd + sectionStart ### v.1.0.22 Add compatibility with ObjectPropertyGenerator and CandidateConcretePropertyResolver. diff --git a/docs/content/v1.0.x/docs/generating-objects/generating-interface.md b/docs/content/v1.0.x/docs/generating-objects/generating-interface.md index 35f3dae7b..35b165a5d 100644 --- a/docs/content/v1.0.x/docs/generating-objects/generating-interface.md +++ b/docs/content/v1.0.x/docs/generating-objects/generating-interface.md @@ -138,6 +138,74 @@ ArrayList collection = (ArrayList)fixture.giveMeOne(new TypeRefe // collection will be an instance of ArrayList ``` +You can use this option below if there are too many implementations to add using the options, but they have a similar pattern. + +```java +interface ObjectValueSupplier { + Object getValue(); +} + +interface StringValueSupplier extends ObjectValueSupplier { + String getValue(); +} + +public class DefaultStringValueSupplier implements StringValueSupplier { + private final String value; + + @ConstructorProperties("value") // It is not needed if you are using Lombok. + public DefaultStringValueSupplier(String value) { + this.value = value; + } + + @Override + public String getValue() { + return this.value; + } +} + +interface IntegerValueSupplier extends ObjectValueSupplier { + Integer getValue(); +} + +public class DefaultIntegerValueSupplier implements IntegerValueSupplier { + private final Integer value; + + @ConstructorProperties("value") // It is not needed if you are using Lombok. + public DefaultIntegerValueSupplier(Integer value) { + this.value = value; + } + + @Override + public Integer getValue() { + return this.value; + } +} + +FixtureMonkey fixture = FixtureMonkey.builder() + .objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) // used for instantiate implementations of ObjectValueSupplier + .plugin( + new InterfacePlugin() + .interfaceImplements( + new AssignableTypeMatcher(ObjectValueSupplier.class), + property -> { + Class actualType = Types.getActualType(property.getType()); + if (StringValueSupplier.class.isAssignableFrom(actualType)) { + return List.of(PropertyUtils.toProperty(DefaultStringValueSupplier.class)); + } + + if (IntegerValueSupplier.class.isAssignableFrom(actualType)) { + return List.of(PropertyUtils.toProperty(DefaultIntegerValueSupplier.class)); + } + return List.of(); + } + ) + ) + .build(); + +DefaultStringValueSupplier stringValueSupplier = (DefaultStringValueSupplier)fixture.giveMeOne(StringValueSupplier.class); +DefaultIntegerValueSupplier integerValueSupplier = (DefaultIntegerValueSupplier)fixture.giveMeOne(IntegerValueSupplier.class); +``` + ### Generic Interfaces What if we need to generate some complex generic interface? All you have to do is do what you did with the simple diff --git a/docs/content/v1.0.x/release-notes/_index.md b/docs/content/v1.0.x/release-notes/_index.md index ccc98d769..a8d4fb212 100644 --- a/docs/content/v1.0.x/release-notes/_index.md +++ b/docs/content/v1.0.x/release-notes/_index.md @@ -5,6 +5,15 @@ menu: docs: weight: 100 --- + +sectionStart +### v.1.0.23 +Add the flexible option for complex usage in InterfacePlugin. + +Fix for generating Kotlin self-reference with default arguments. + +sectionEnd + sectionStart ### v.1.0.22 Add compatibility with ObjectPropertyGenerator and CandidateConcretePropertyResolver.