Class RecordAssert<R extends Record>
java.lang.Object
cloud.opencode.base.test.assertion.RecordAssert<R>
- Type Parameters:
R- the record type | Record类型
Record Assert - Fluent assertions for Java Record components
Record断言 - Java Record组件的流式断言
Provides assertion methods for verifying Java Record component values
by name using reflection on RecordComponent.
通过反射 RecordComponent,按名称验证 Java Record 组件值的断言方法。
Features | 主要功能:
- Component value assertion by name - 按名称断言组件值
- Null/non-null checks for components - 组件的空/非空检查
- Type checking for components - 组件类型检查
- Fluent chaining API - 流式链式API
Usage Examples | 使用示例:
record Person(String name, int age) {}
RecordAssert.assertThat(new Person("Alice", 30))
.hasComponent("name", "Alice")
.hasComponent("age", 30)
.componentIsNotNull("name");
Security | 安全性:
- Thread-safe: No (not designed for concurrent use) - 线程安全: 否(非设计用于并发使用)
- Null-safe: Yes (validates non-null record) - 空值安全: 是(验证非空Record)
- Since:
- JDK 25, opencode-base-test V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends Record>
RecordAssert<R> assertThat(R actual) Creates assertion for a record instance.componentIsInstanceOf(String componentName, Class<?> expectedType) Asserts that a named component is of the expected type.componentIsNotNull(String componentName) Asserts that a named component is not null.componentIsNull(String componentName) Asserts that a named component is null.hasComponent(String componentName, Object expectedValue) Asserts that a named component has the expected value.hasComponentCount(int expectedCount) Asserts that the record has the specified number of components.hasComponentNamed(String componentName) Asserts that the record has a component with the given name.Asserts that the record equals the expected record.Asserts that the record is not null.isNull()Asserts that the record is null.
-
Method Details
-
assertThat
Creates assertion for a record instance. 为Record实例创建断言。- Type Parameters:
R- the record type | Record类型- Parameters:
actual- the actual record | 实际Record- Returns:
- the assertion | 断言
-
isNull
-
isNotNull
Asserts that the record is not null. 断言Record不为null。- Returns:
- this | 此对象
-
hasComponent
Asserts that a named component has the expected value. 断言指定名称的组件具有期望值。- Parameters:
componentName- the component name | 组件名称expectedValue- the expected value | 期望值- Returns:
- this | 此对象
-
componentIsNull
Asserts that a named component is null. 断言指定名称的组件为null。- Parameters:
componentName- the component name | 组件名称- Returns:
- this | 此对象
-
componentIsNotNull
Asserts that a named component is not null. 断言指定名称的组件不为null。- Parameters:
componentName- the component name | 组件名称- Returns:
- this | 此对象
-
componentIsInstanceOf
Asserts that a named component is of the expected type. 断言指定名称的组件是期望的类型。- Parameters:
componentName- the component name | 组件名称expectedType- the expected type | 期望类型- Returns:
- this | 此对象
-
hasComponentCount
Asserts that the record has the specified number of components. 断言Record具有指定数量的组件。- Parameters:
expectedCount- the expected component count | 期望的组件数量- Returns:
- this | 此对象
-
hasComponentNamed
Asserts that the record has a component with the given name. 断言Record具有指定名称的组件。- Parameters:
componentName- the component name | 组件名称- Returns:
- this | 此对象
-
isEqualTo
Asserts that the record equals the expected record. 断言Record等于期望的Record。- Parameters:
expected- the expected record | 期望的Record- Returns:
- this | 此对象
-