Class AutoFill
java.lang.Object
cloud.opencode.base.test.data.AutoFill
AutoFill - Auto-populates Record and POJO instances via reflection
自动填充 - 通过反射自动填充Record和POJO实例
Generates fully populated test objects without manually setting every field. Supports both Java Records (via canonical constructor) and traditional POJOs (via no-arg constructor + setter methods).
生成完全填充的测试对象,无需手动设置每个字段。 支持Java Record(通过规范构造函数)和传统POJO(通过无参构造函数 + setter方法)。
Value generation notes | 值生成说明:
- Generated int and long values are always positive (1..bound) - 生成的int和long值始终为正数
- Collection fields (List, Set, Map) are filled with 1-2 String elements due to type erasure - 由于类型擦除,集合字段使用1-2个String元素填充
Features | 主要功能:
- Record support via canonical constructor - 通过规范构造函数支持Record
- POJO support via no-arg constructor + setters - 通过无参构造函数和setter支持POJO
- Deterministic generation with seed - 使用种子进行确定性生成
- Field override for specific values - 字段覆盖以设置特定值
- Recursive filling with max depth control - 带最大深度控制的递归填充
- Batch generation via list() - 通过list()批量生成
Usage Examples | 使用示例:
// Simple record filling
var user = AutoFill.of(UserRecord.class).build();
// Deterministic with seed
var user = AutoFill.of(UserRecord.class).seed(42L).build();
// Override specific fields
var user = AutoFill.of(UserRecord.class)
.with("name", "Alice")
.with("age", 30)
.build();
// Generate a list of 10 instances
List<UserRecord> users = AutoFill.of(UserRecord.class).list(10);
Security | 安全性:
- Thread-safe: No (Builder is not thread-safe) - 线程安全: 否(Builder非线程安全)
- Null-safe: Yes (rejects null type) - 空值安全: 是(拒绝空类型)
- Since:
- JDK 25, opencode-base-test V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for configuring and creating auto-filled instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AutoFill.Builder<T> Creates a builder for the given type.
-
Method Details
-
of
Creates a builder for the given type. 为指定类型创建构建器。- Type Parameters:
T- the target type | 目标类型- Parameters:
type- the class to auto-fill | 要自动填充的类- Returns:
- a new builder | 新的构建器
- Throws:
NullPointerException- if type is null | 当类型为空时抛出
-