Java
Immutable type
ConstructorPropertiesIntrospector
0. Prerequisites
Should satisfy one of below preconditions
- record type
- any constructors with
@ConstructorProperties
Multiple constructors with record would be instantiated by constructor with
@ConstructorProperties
1. Altering objectIntrospector
option
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.build();
FactoryMethodArbitraryIntrospector
0. Prerequisites
- static factory method
1. Altering objectIntrospector
option
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(FactoryMethodArbitraryIntrospector.INSTANCE)
.build();
JacksonArbitraryIntrospector
This practice should add extra module because it depends on third-party library Jackson
0. Prerequisites
Type should be serializable/deserializable by Jackson
1. Adding dependency
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-jackson:1.1.0")
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-jackson</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
2. Altering objectIntrospector
option
If you have custom ObjectMapper
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.plugin(new JacksonPlugin(objectMapper))
.build();
If you DON’T have a custom ObjectMapper
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.plugin(new JacksonPlugin())
.build();
Mutable type
ConstructorPropertiesIntrospector
0. Prerequisites
Should satisfy one of below preconditions
- record type
- any constructors with
@ConstructorProperties
Multiple constructors with record would be instantiated by constructor with
@ConstructorProperties
1. Altering objectIntrospector
option
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.build();
FieldReflectionArbitraryIntrospector
0. Prerequisites
- No args constructor
- Getter / Setter
1. Altering objectIntrospector
option
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
.build();
BeanArbitraryIntrospector
BeanArbitraryIntrospector
is default objectIntrospector
0. Prerequisites
- No args constructor
- Setter