This guide outlines the code consistency and style conventions for contributing to the Fixture Monkey project. Please follow these rules to reduce code review time and maintain project quality.
- Language Version:
- Java: JDK 8 or higher compatible
- Kotlin: 1.8 or higher
- Encoding: UTF-8
- Line Ending: LF (Line Feed)
- Indentation: Use Tab (Size: 4)
- Please configure your IDE to match the
.editorconfigfile included in the project root.
- Please configure your IDE to match the
- Package: Lowercase, format
com.navercorp.fixturemonkey... - Class/Interface: PascalCase (e.g.,
MonkeyContext,CombinableArbitrary) - Method/Variable: camelCase (e.g.,
giveMeOne,objectBuilder) - Constant: UPPER_SNAKE_CASE (e.g.,
DEFAULT_MAX_TRIES)
- No Lombok in Production Code: Do not use Lombok in production code (
src/main/java). Explicitly write Getters, constructors, etc., or use IDE generation features. - Lombok Allowed in Test Code: Lombok usage is permitted in test code (
src/test/java).
- @API Annotation: Public APIs must use the
org.apiguardian.api.APIannotation to specify status and introduction version (since).@API(since = "0.6.0", status = Status.MAINTAINED) public interface CombinableArbitrary<T> { ... }
- Javadoc: Public classes and methods must have Javadoc explaining their role, parameters, and return values.
- Design objects to be Immutable whenever possible.
- Actively use the
finalkeyword for fields.
- Trailing Commas: It is recommended to use Trailing Commas for multi-line parameters or list declarations.
MatchArbitraryIntrospector( listOf( PrimaryConstructorArbitraryIntrospector.INSTANCE, it, // Trailing comma ) )
- Standard Library Usage: Utilize Kotlin standard library functions (
apply,let,map, etc.) appropriately for concise code.
- Frameworks:
- jqwik: Mainly used for Property-based testing. Use the
@Propertyannotation. - JUnit 5: Used for general unit testing.
- AssertJ: Used for writing assertions.
- jqwik: Mainly used for Property-based testing. Use the
- Test Naming: Write test names that clearly indicate the target and intent.
All source files (*.java, *.kt) must include the Apache License 2.0 header at the very top.
/*
* Fixture Monkey
*
* Copyright (c) 2021-present NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* ...
*/Understanding the internal object generation flow is crucial for contributing to core logic.
- FixtureMonkey: The main entry point. It holds the
MonkeyContextand createsArbitraryBuilder. - ArbitraryBuilder: Configures how to generate an object. It accumulates user customizations (manipulators).
- ArbitraryResolver: Resolves the
ArbitraryBuilderinto aCombinableArbitrary. It constructs theObjectTree. - ObjectTree: Represents the structure of the object to be generated. It consists of
ObjectNodes. - ArbitraryIntrospector: Determines how to create an instance of a specific type (e.g., Constructor, Bean, Factory method).
- Initialization:
FixtureMonkey.create()initializes options and context. - Builder Creation:
fixtureMonkey.giveMeBuilder(Type)creates aDefaultArbitraryBuilderwith aRootProperty. - Customization: Methods like
.set(),.size()addArbitraryManipulators to theArbitraryBuilderContext. - Resolution: Calling
.sample()triggersArbitraryResolver.resolve().- It creates an
ObjectTreerepresenting the object structure. - It applies all registered
ArbitraryManipulators to theObjectTree. - It traverses the tree to generate the actual object using
ArbitraryIntrospectors.
- It creates an
- Generation: The
ObjectTreeproduces the final Java/Kotlin object instance.
- Introspection: The process of inspecting a class to understand how to instantiate it.
- Manipulation: The process of modifying the generated object or its structure based on user input (path expressions).
- Lazy Evaluation: Objects are not generated until
.sample()is called, allowing for efficient configuration.