Class AssertionException
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.AssertionException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
EqualsAssertionException
Assertion Exception - Exception thrown when an assertion fails
断言异常 - 断言失败时抛出的异常
This exception is thrown when an assertion fails during testing.
此异常在测试期间断言失败时抛出。
Features | 主要功能:
- Typed assertion failures with error codes - 带错误码的类型化断言失败
- Factory methods for common assertion failures - 常见断言失败的工厂方法
- Support for message, cause, and error code construction - 支持消息、原因和错误码构造
Usage Examples | 使用示例:
throw AssertionException.failed("Expected value not found");
throw AssertionException.notEqual("expected", "actual");
throw AssertionException.timeout(5000, 6200);
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
ConstructorsConstructorDescriptionAssertionException(TestErrorCode errorCode) Creates assertion exception with error code.AssertionException(TestErrorCode errorCode, String detail) Creates assertion exception with error code and detail.AssertionException(String message) Creates assertion exception with message.AssertionException(String message, Throwable cause) Creates assertion exception with message and cause. -
Method Summary
Modifier and TypeMethodDescriptionstatic AssertionExceptionCreates exception for assertion failed.static AssertionExceptionCreates exception for equality assertion.static AssertionExceptionCreates exception for null assertion.static AssertionExceptiontimeout(long timeoutMs, long actualMs) Creates exception for timeout.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
-
AssertionException
Creates assertion exception with error code. 使用错误码创建断言异常。- Parameters:
errorCode- the error code | 错误码
-
AssertionException
Creates assertion exception with error code and detail. 使用错误码和详情创建断言异常。- Parameters:
errorCode- the error code | 错误码detail- the detail message | 详细消息
-
AssertionException
Creates assertion exception with message. 使用消息创建断言异常。- Parameters:
message- the message | 消息
-
AssertionException
-
-
Method Details
-
failed
Creates exception for assertion failed. 为断言失败创建异常。- Parameters:
message- the message | 消息- Returns:
- the exception | 异常
-
nullAssertion
Creates exception for null assertion. 为空值断言创建异常。- Returns:
- the exception | 异常
-
notEqual
Creates exception for equality assertion. 为相等断言创建异常。- Parameters:
expected- the expected value | 期望值actual- the actual value | 实际值- Returns:
- the exception | 异常
-
timeout
Creates exception for timeout. 为超时创建异常。- Parameters:
timeoutMs- the timeout in milliseconds | 超时毫秒数actualMs- the actual time in milliseconds | 实际毫秒数- Returns:
- the exception | 异常
-