Class MockException

All Implemented Interfaces:
Serializable

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

    • MockException

      public MockException(TestErrorCode errorCode)
      Creates mock exception with error code. 使用错误码创建Mock异常。
      Parameters:
      errorCode - the error code | 错误码
    • MockException

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

      public MockException(String message)
      Creates mock exception with message. 使用消息创建Mock异常。
      Parameters:
      message - the message | 消息
    • MockException

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

    • creationFailed

      public static MockException creationFailed(Class<?> type)
      Creates exception for mock creation failure. 为Mock创建失败创建异常。
      Parameters:
      type - the type that failed to mock | 无法Mock的类型
      Returns:
      the exception | 异常
    • notInterface

      public static MockException notInterface(Class<?> type)
      Creates exception for non-interface mock attempt. 为非接口Mock尝试创建异常。
      Parameters:
      type - the non-interface type | 非接口类型
      Returns:
      the exception | 异常
    • verificationFailed

      public static MockException verificationFailed(String expected, int actual)
      Creates exception for verification failure. 为验证失败创建异常。
      Parameters:
      expected - the expected invocation | 期望的调用
      actual - the actual invocation count | 实际调用次数
      Returns:
      the exception | 异常