Skip to content

Commit

Permalink
Publish 1.0.23 version
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Aug 10, 2024
1 parent 4c592fd commit 1ed8ad7
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,7 +49,7 @@ testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-starter</artifactId>
<version>1.0.22</version>
<version>1.0.23</version>
<scope>test</scope>
</dependency>
```
Expand All @@ -60,7 +60,7 @@ testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-starter-kotlin</artifactId>
<version>1.0.22</version>
<version>1.0.23</version>
<scope>test</scope>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

allprojects {
group = "com.navercorp.fixturemonkey"
version = "1.0.23-SNAPSHOT"
version = "1.0.23"
}

subprojects {
Expand Down
2 changes: 1 addition & 1 deletion docs/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = ""

## Documentation
docsVersion = "1.0.0"
fixtureMonkeyVersion = "1.0.22"
fixtureMonkeyVersion = "1.0.23"

## Open Graph
images = ["fixtureMonkey.png"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -122,6 +122,75 @@ List<String> list = fixture.giveMeOne(new TypeReference<List<String>>() {
이렇게 설정하면 `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(
Expand Down
8 changes: 8 additions & 0 deletions docs/content/v1.0.x-kor/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,74 @@ ArrayList<String> collection = (ArrayList<String>)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
Expand Down
9 changes: 9 additions & 0 deletions docs/content/v1.0.x/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1ed8ad7

Please sign in to comment.