Class RecordAssert<R extends Record>

java.lang.Object
cloud.opencode.base.test.assertion.RecordAssert<R>
Type Parameters:
R - the record type | Record类型

public final class RecordAssert<R extends Record> extends Object
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 Details

    • assertThat

      public static <R extends Record> RecordAssert<R> assertThat(R actual)
      Creates assertion for a record instance. 为Record实例创建断言。
      Type Parameters:
      R - the record type | Record类型
      Parameters:
      actual - the actual record | 实际Record
      Returns:
      the assertion | 断言
    • isNull

      public RecordAssert<R> isNull()
      Asserts that the record is null. 断言Record为null。
      Returns:
      this | 此对象
    • isNotNull

      public RecordAssert<R> isNotNull()
      Asserts that the record is not null. 断言Record不为null。
      Returns:
      this | 此对象
    • hasComponent

      public RecordAssert<R> hasComponent(String componentName, Object expectedValue)
      Asserts that a named component has the expected value. 断言指定名称的组件具有期望值。
      Parameters:
      componentName - the component name | 组件名称
      expectedValue - the expected value | 期望值
      Returns:
      this | 此对象
    • componentIsNull

      public RecordAssert<R> componentIsNull(String componentName)
      Asserts that a named component is null. 断言指定名称的组件为null。
      Parameters:
      componentName - the component name | 组件名称
      Returns:
      this | 此对象
    • componentIsNotNull

      public RecordAssert<R> componentIsNotNull(String componentName)
      Asserts that a named component is not null. 断言指定名称的组件不为null。
      Parameters:
      componentName - the component name | 组件名称
      Returns:
      this | 此对象
    • componentIsInstanceOf

      public RecordAssert<R> componentIsInstanceOf(String componentName, Class<?> expectedType)
      Asserts that a named component is of the expected type. 断言指定名称的组件是期望的类型。
      Parameters:
      componentName - the component name | 组件名称
      expectedType - the expected type | 期望类型
      Returns:
      this | 此对象
    • hasComponentCount

      public RecordAssert<R> hasComponentCount(int expectedCount)
      Asserts that the record has the specified number of components. 断言Record具有指定数量的组件。
      Parameters:
      expectedCount - the expected component count | 期望的组件数量
      Returns:
      this | 此对象
    • hasComponentNamed

      public RecordAssert<R> hasComponentNamed(String componentName)
      Asserts that the record has a component with the given name. 断言Record具有指定名称的组件。
      Parameters:
      componentName - the component name | 组件名称
      Returns:
      this | 此对象
    • isEqualTo

      public RecordAssert<R> isEqualTo(R expected)
      Asserts that the record equals the expected record. 断言Record等于期望的Record。
      Parameters:
      expected - the expected record | 期望的Record
      Returns:
      this | 此对象