Class Spy
java.lang.Object
cloud.opencode.base.test.mock.Spy
Spy
间谍
Records method invocations for verification.
记录方法调用以供验证。
Features | 主要功能:
- Method invocation recording - 方法调用记录
- Call verification support - 调用验证支持
Usage Examples | 使用示例:
Spy spy = new Spy();
spy.record("methodName", args);
assertTrue(spy.wasCalled("methodName"));
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear recorded invocations 清除记录的调用intgetCallCount(String methodName) Get call count 获取调用次数Get all invocations 获取所有调用getInvocations(String methodName) Get invocations for method 获取方法的调用Get last invocation 获取最后一次调用booleanVerify no interactions 验证没有交互voidRecord an invocation 记录一次调用booleanVerify method was called 验证方法被调用booleanwasCalledTimes(String methodName, int times) Verify method was called n times 验证方法被调用n次
-
Constructor Details
-
Spy
public Spy()
-
-
Method Details
-
record
-
wasCalled
Verify method was called 验证方法被调用- Parameters:
methodName- the method name | 方法名称- Returns:
- true if called | 如果被调用返回true
-
wasCalledTimes
Verify method was called n times 验证方法被调用n次- Parameters:
methodName- the method name | 方法名称times- the expected times | 期望次数- Returns:
- true if called n times | 如果被调用n次返回true
-
getCallCount
Get call count 获取调用次数- Parameters:
methodName- the method name | 方法名称- Returns:
- the count | 次数
-
getInvocations
Get all invocations 获取所有调用- Returns:
- the invocations | 调用列表
-
getInvocations
Get invocations for method 获取方法的调用- Parameters:
methodName- the method name | 方法名称- Returns:
- the invocations | 调用列表
-
getLastInvocation
Get last invocation 获取最后一次调用- Returns:
- the invocation or null | 调用或null
-
clear
public void clear()Clear recorded invocations 清除记录的调用 -
noInteractions
public boolean noInteractions()Verify no interactions 验证没有交互- Returns:
- true if no invocations | 如果没有调用返回true
-