Class MockProxyMetaClass

java.lang.Object
groovy.lang.MetaClassImpl
groovy.lang.ProxyMetaClass
groovy.mock.interceptor.MockProxyMetaClass
All Implemented Interfaces:
AdaptingMetaClass, MetaClass, MetaObjectProtocol, MutableMetaClass

public class MockProxyMetaClass extends ProxyMetaClass
The ProxyMetaClass for the MockInterceptor. Instance and class methods are intercepted, but constructors are not to allow mocking of aggregated objects.
  • Field Details

    • interceptConstruction

      public final boolean interceptConstruction
      Indicates whether constructor invocations should be intercepted.
  • Constructor Details

    • MockProxyMetaClass

      public MockProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee)
      Parameters:
      adaptee - the MetaClass to decorate with interceptability
    • MockProxyMetaClass

      public MockProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee, boolean interceptConstruction)
      Parameters:
      adaptee - the MetaClass to decorate with interceptability
  • Method Details

    • make

      public static MockProxyMetaClass make(Class theClass)
      convenience factory method for the most usual case.
    • make

      public static MockProxyMetaClass make(Class theClass, boolean interceptConstruction)
      convenience factory method allowing interceptConstruction to be set.
    • invokeMethod

      public Object invokeMethod(Object object, String methodName, Object[] arguments)
      Intercepts an instance method invocation and delegates to the adaptee when requested.
      Specified by:
      invokeMethod in interface MetaObjectProtocol
      Overrides:
      invokeMethod in class ProxyMetaClass
      Parameters:
      object - the receiver of the method call
      methodName - the method name
      arguments - the invocation arguments
      Returns:
      the interceptor result or the adaptee result when falling through
      See Also:
    • invokeMethod

      public Object invokeMethod(Class sender, Object object, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)
      Intercepts an instance method invocation with sender metadata and delegates when requested.
      Specified by:
      invokeMethod in interface MetaClass
      Overrides:
      invokeMethod in class ProxyMetaClass
      Parameters:
      sender - the sender class
      object - the receiver of the method call
      methodName - the method name
      arguments - the invocation arguments
      isCallToSuper - whether the call targets a superclass implementation
      fromInsideClass - whether the call originates from inside the declaring class
      Returns:
      the interceptor result or the adaptee result when falling through
      See Also:
    • invokeStaticMethod

      public Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
      Intercepts a static method invocation and delegates to the adaptee when requested.
      Specified by:
      invokeStaticMethod in interface MetaObjectProtocol
      Overrides:
      invokeStaticMethod in class ProxyMetaClass
      Parameters:
      object - the static receiver
      methodName - the method name
      arguments - the invocation arguments
      Returns:
      the interceptor result or the adaptee result when falling through
      See Also:
    • getProperty

      public Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1)
      Intercepts a property read and delegates to the adaptee when no custom value is supplied.
      Specified by:
      getProperty in interface MetaClass
      Overrides:
      getProperty in class ProxyMetaClass
      Parameters:
      aClass - the dispatch class
      object - the receiver of the property access
      property - the property name
      b - implementation-specific flag forwarded to the adaptee
      b1 - implementation-specific flag forwarded to the adaptee
      Returns:
      the intercepted or delegated property value
    • setProperty

      public void setProperty(Class aClass, Object object, String property, Object newValue, boolean b, boolean b1)
      Intercepts a property write and delegates to the adaptee when no custom handling is supplied.
      Specified by:
      setProperty in interface MetaClass
      Overrides:
      setProperty in class ProxyMetaClass
      Parameters:
      aClass - the dispatch class
      object - the receiver of the property access
      property - the property name
      newValue - the value to assign
      b - implementation-specific flag forwarded to the adaptee
      b1 - implementation-specific flag forwarded to the adaptee
    • invokeConstructor

      public Object invokeConstructor(Object[] arguments)
      Intercepts or delegates constructor invocation depending on interceptConstruction.
      Specified by:
      invokeConstructor in interface MetaObjectProtocol
      Overrides:
      invokeConstructor in class ProxyMetaClass
      Parameters:
      arguments - the constructor arguments
      Returns:
      the constructed instance or interceptor-supplied replacement