Record Class Invocation

java.lang.Object
java.lang.Record
cloud.opencode.base.test.mock.Invocation
Record Components:
method - the invoked method | 调用的方法
args - the arguments | 参数
timestamp - the invocation timestamp | 调用时间戳

public record Invocation(Method method, Object[] args, Instant timestamp) extends Record
Invocation - Record of a method invocation on a mock 调用记录 - Mock上方法调用的记录

Immutable record of a method invocation including method, arguments, and timestamp.

方法调用的不可变记录,包括方法、参数和时间戳。

Features | 主要功能:

  • Immutable invocation recording - 不可变调用记录
  • Argument matching support - 参数匹配支持
  • Method name and type introspection - 方法名称和类型内省

Usage Examples | 使用示例:

Invocation inv = Invocation.of(method, args);
String name = inv.methodName();
boolean matches = inv.argsMatch("value1", 42);

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes (handles null args) - 空值安全: 是(处理空参数)
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • Invocation

      public Invocation(Method method, Object[] args, Instant timestamp)
      Compact constructor — defensively copies args array. 紧凑构造器 — 防御性复制参数数组。
  • Method Details

    • args

      public Object[] args()
      Returns a defensive copy of the arguments array. 返回参数数组的防御性副本。
      Returns:
      args copy or null | 参数副本或 null
    • of

      public static Invocation of(Method method, Object[] args)
      Creates an invocation with current timestamp. 使用当前时间戳创建调用记录。
      Parameters:
      method - the method | 方法
      args - the arguments | 参数
      Returns:
      the invocation | 调用记录
    • methodName

      public String methodName()
      Gets the method name. 获取方法名。
      Returns:
      the method name | 方法名
    • returnType

      public Class<?> returnType()
      Gets the return type. 获取返回类型。
      Returns:
      the return type | 返回类型
    • parameterTypes

      public Class<?>[] parameterTypes()
      Gets the parameter types. 获取参数类型。
      Returns:
      the parameter types | 参数类型
    • argsMatch

      public boolean argsMatch(Object... expectedArgs)
      Checks if arguments match. 检查参数是否匹配。
      Parameters:
      expectedArgs - the expected arguments | 期望参数
      Returns:
      true if match | 如果匹配返回 true
    • isMethod

      public boolean isMethod(String name)
      Checks if this invocation is for the specified method name. 检查此调用是否为指定方法名。
      Parameters:
      name - the method name | 方法名
      Returns:
      true if match | 如果匹配返回 true
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • method

      public Method method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component