Class AssertionException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
EqualsAssertionException

public class AssertionException extends TestException
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 Details

    • AssertionException

      public AssertionException(TestErrorCode errorCode)
      Creates assertion exception with error code. 使用错误码创建断言异常。
      Parameters:
      errorCode - the error code | 错误码
    • AssertionException

      public AssertionException(TestErrorCode errorCode, String detail)
      Creates assertion exception with error code and detail. 使用错误码和详情创建断言异常。
      Parameters:
      errorCode - the error code | 错误码
      detail - the detail message | 详细消息
    • AssertionException

      public AssertionException(String message)
      Creates assertion exception with message. 使用消息创建断言异常。
      Parameters:
      message - the message | 消息
    • AssertionException

      public AssertionException(String message, Throwable cause)
      Creates assertion exception with message and cause. 使用消息和原因创建断言异常。
      Parameters:
      message - the message | 消息
      cause - the cause | 原因
  • Method Details

    • failed

      public static AssertionException failed(String message)
      Creates exception for assertion failed. 为断言失败创建异常。
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • nullAssertion

      public static AssertionException nullAssertion()
      Creates exception for null assertion. 为空值断言创建异常。
      Returns:
      the exception | 异常
    • notEqual

      public static AssertionException notEqual(Object expected, Object actual)
      Creates exception for equality assertion. 为相等断言创建异常。
      Parameters:
      expected - the expected value | 期望值
      actual - the actual value | 实际值
      Returns:
      the exception | 异常
    • timeout

      public static AssertionException timeout(long timeoutMs, long actualMs)
      Creates exception for timeout. 为超时创建异常。
      Parameters:
      timeoutMs - the timeout in milliseconds | 超时毫秒数
      actualMs - the actual time in milliseconds | 实际毫秒数
      Returns:
      the exception | 异常