Class MockException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.test.exception.TestException
cloud.opencode.base.test.exception.MockException
- All Implemented Interfaces:
Serializable
Mock Exception - Exception thrown during mock operations
Mock异常 - Mock操作期间抛出的异常
This exception is thrown when mock creation, stubbing, or verification fails.
当Mock创建、存根或验证失败时抛出此异常。
Features | 主要功能:
- Mock creation failure reporting - Mock创建失败报告
- Non-interface mock attempt detection - 非接口Mock尝试检测
- Verification failure reporting - 验证失败报告
Usage Examples | 使用示例:
throw MockException.creationFailed(MyClass.class);
throw MockException.notInterface(MyClass.class);
throw MockException.verificationFailed("save called 1 time(s)", 0);
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMockException(TestErrorCode errorCode) Creates mock exception with error code.MockException(TestErrorCode errorCode, String detail) Creates mock exception with error code and detail.MockException(String message) Creates mock exception with message.MockException(String message, Throwable cause) Creates mock exception with message and cause. -
Method Summary
Modifier and TypeMethodDescriptionstatic MockExceptioncreationFailed(Class<?> type) Creates exception for mock creation failure.static MockExceptionnotInterface(Class<?> type) Creates exception for non-interface mock attempt.static MockExceptionverificationFailed(String expected, int actual) Creates exception for verification failure.Methods inherited from class TestException
getTestErrorCodeMethods inherited from class OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
MockException
Creates mock exception with error code. 使用错误码创建Mock异常。- Parameters:
errorCode- the error code | 错误码
-
MockException
Creates mock exception with error code and detail. 使用错误码和详情创建Mock异常。- Parameters:
errorCode- the error code | 错误码detail- the detail message | 详细消息
-
MockException
Creates mock exception with message. 使用消息创建Mock异常。- Parameters:
message- the message | 消息
-
MockException
-
-
Method Details
-
creationFailed
Creates exception for mock creation failure. 为Mock创建失败创建异常。- Parameters:
type- the type that failed to mock | 无法Mock的类型- Returns:
- the exception | 异常
-
notInterface
Creates exception for non-interface mock attempt. 为非接口Mock尝试创建异常。- Parameters:
type- the non-interface type | 非接口类型- Returns:
- the exception | 异常
-
verificationFailed
Creates exception for verification failure. 为验证失败创建异常。- Parameters:
expected- the expected invocation | 期望的调用actual- the actual invocation count | 实际调用次数- Returns:
- the exception | 异常
-