Class MockBuilder<T>
java.lang.Object
cloud.opencode.base.test.mock.MockBuilder<T>
- Type Parameters:
T- the interface type | 接口类型Performance | 性能特性:
- Time complexity: O(1) to build; O(1) per method invocation on the mock - 时间复杂度: O(1) 构建;O(1) 每次方法调用
- Space complexity: O(m) where m is the number of registered method handlers - 空间复杂度: O(m),m 为注册的方法处理器数量
Mock Builder
模拟构建器
Simple mock builder for interfaces.
接口的简单模拟构建器。
Features | 主要功能:
- Core functionality - 核心功能
Usage Examples | 使用示例:
// Use type
type instance = ...;
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the mock 构建模拟对象defaultHandler(Function<Method, Object> handler) Set default handler 设置默认处理器defaultReturn(Object defaultValue) Set default return value 设置默认返回值static <T> TQuick create mock with default values 快速创建带默认值的模拟static <T> MockBuilder<T> Create builder for interface 为接口创建构建器When method called, return value 当方法调用时,返回值When method called, execute function 当方法调用时,执行函数
-
Method Details
-
of
Create builder for interface 为接口创建构建器- Type Parameters:
T- the type | 类型- Parameters:
interfaceType- the interface type | 接口类型- Returns:
- the builder | 构建器
-
when
When method called, return value 当方法调用时,返回值- Parameters:
methodName- the method name | 方法名称returnValue- the return value | 返回值- Returns:
- this builder | 此构建器
-
when
-
defaultReturn
Set default return value 设置默认返回值- Parameters:
defaultValue- the default value | 默认值- Returns:
- this builder | 此构建器
-
defaultHandler
Set default handler 设置默认处理器- Parameters:
handler- the handler | 处理器- Returns:
- this builder | 此构建器
-
build
-
mock
Quick create mock with default values 快速创建带默认值的模拟- Type Parameters:
T- the type | 类型- Parameters:
interfaceType- the interface type | 接口类型- Returns:
- the mock | 模拟对象
-