Interface MockPolicyInterceptionSettings

  • All Known Implementing Classes:
    MockPolicyInterceptionSettingsImpl

    public interface MockPolicyInterceptionSettings
    Contains interception related settings. PowerMock uses the information stored in this object to intercept method calls and field calls etc and specify a return value or suppression.

    Since mock policies can be chained subsequent policies can override behavior of a previous policy. To avoid accidental overrides it's recommended add behavior instead of setting behavior since the latter overrides all previous configurations.

    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      void addFieldToSuppress​(java.lang.reflect.Field[] fields)
      Add specific fields that should be suppressed upon invocation.
      void addFieldToSuppress​(java.lang.reflect.Field firstField, java.lang.reflect.Field... additionalFields)
      Add specific fields that should be suppressed upon invocation.
      void addFieldTypesToSuppress​(java.lang.String[] fieldTypes)
      Add field types that should be suppressed.
      void addFieldTypesToSuppress​(java.lang.String firstType, java.lang.String... additionalFieldTypes)
      Add field types that should be suppressed.
      void addMethodsToSuppress​(java.lang.reflect.Method[] methods)
      Add methods to suppress upon invocation.
      void addMethodsToSuppress​(java.lang.reflect.Method methodToSuppress, java.lang.reflect.Method... additionalMethodsToSuppress)
      Add methods to suppress upon invocation.
      void addSubtituteReturnValue​(java.lang.reflect.Method method, java.lang.Object returnObject)
      Deprecated.
      java.lang.reflect.Field[] getFieldsToSuppress()  
      java.lang.String[] getFieldTypesToSuppress()  
      java.lang.reflect.Method[] getMethodsToSuppress()  
      java.util.Map<java.lang.reflect.Method,​java.lang.reflect.InvocationHandler> getProxiedMethods()
      Get all methods that should be proxied and the invocation handler for each method.
      java.util.Map<java.lang.reflect.Method,​java.lang.Object> getStubbedMethods()
      Get all substitute return values and also returns an unmodifiable map of all method-object pairs the were initialized.
      java.util.Map<java.lang.reflect.Method,​java.lang.Object> getSubstituteReturnValues()
      Deprecated.
      Use getStubbedMethods() instead.
      void proxyMethod​(java.lang.reflect.Method method, java.lang.reflect.InvocationHandler invocationHandler)
      Proxy a method with the given invocation handler.
      void setFieldsSuppress​(java.lang.reflect.Field[] fields)
      Set specific fields that should be suppressed upon invocation.
      void setFieldTypesToSuppress​(java.lang.String[] fieldTypes)
      Set which field types that should be suppressed.
      void setMethodsToProxy​(java.util.Map<java.lang.reflect.Method,​java.lang.reflect.InvocationHandler> proxies)
      Set the methods to proxy.
      void setMethodsToStub​(java.util.Map<java.lang.reflect.Method,​java.lang.Object> substituteReturnValues)
      Set the substitute return values.
      void setMethodsToSuppress​(java.lang.reflect.Method[] methods)
      Set which methods to suppress.
      void setSubtituteReturnValues​(java.util.Map<java.lang.reflect.Method,​java.lang.Object> substituteReturnValues)
      Deprecated.
      void stubMethod​(java.lang.reflect.Method method, java.lang.Object returnObject)
      Add a method that should be intercepted and return another value ( returnObject) (i.e.
    • Method Detail

      • setMethodsToSuppress

        void setMethodsToSuppress​(java.lang.reflect.Method[] methods)
        Set which methods to suppress. Note that this overrides all previous configurations.
      • addMethodsToSuppress

        void addMethodsToSuppress​(java.lang.reflect.Method methodToSuppress,
                                  java.lang.reflect.Method... additionalMethodsToSuppress)
        Add methods to suppress upon invocation.
      • addMethodsToSuppress

        void addMethodsToSuppress​(java.lang.reflect.Method[] methods)
        Add methods to suppress upon invocation.
      • setMethodsToStub

        void setMethodsToStub​(java.util.Map<java.lang.reflect.Method,​java.lang.Object> substituteReturnValues)
        Set the substitute return values. The substitute return values is a key-value map where each key is a method that should be intercepted and each value is the new return value for that method when it's intercepted.

        Note that this overrides all previous configurations.

      • stubMethod

        void stubMethod​(java.lang.reflect.Method method,
                        java.lang.Object returnObject)
        Add a method that should be intercepted and return another value ( returnObject) (i.e. the method is stubbed).
      • proxyMethod

        void proxyMethod​(java.lang.reflect.Method method,
                         java.lang.reflect.InvocationHandler invocationHandler)
        Proxy a method with the given invocation handler. Each call to the method will be routed to the invocationHandler instead.
      • getProxiedMethods

        java.util.Map<java.lang.reflect.Method,​java.lang.reflect.InvocationHandler> getProxiedMethods()
        Get all methods that should be proxied and the invocation handler for each method.
      • setMethodsToProxy

        void setMethodsToProxy​(java.util.Map<java.lang.reflect.Method,​java.lang.reflect.InvocationHandler> proxies)
        Set the methods to proxy. The proxies are a key-value map where each key is a method that should be intercepted and routed to the invocation handler instead.

        Note that this overrides all previous configurations.

      • setSubtituteReturnValues

        @Deprecated
        void setSubtituteReturnValues​(java.util.Map<java.lang.reflect.Method,​java.lang.Object> substituteReturnValues)
        Deprecated.
        Set the substitute return values. The substitute return values is a key-value map where each key is a method that should be intercepted and each value is the new return value for that method when it's intercepted.

        Note that this overrides all previous configurations.

      • addSubtituteReturnValue

        @Deprecated
        void addSubtituteReturnValue​(java.lang.reflect.Method method,
                                     java.lang.Object returnObject)
        Deprecated.
        Add a method that should be intercepted and return another value ( returnObject). The substitute return values is a key-value map where each key is a method that should be intercepted and each value is the new return value for that method when it's intercepted.
      • setFieldsSuppress

        void setFieldsSuppress​(java.lang.reflect.Field[] fields)
        Set specific fields that should be suppressed upon invocation. Note that this overrides all previous configurations.
      • addFieldToSuppress

        void addFieldToSuppress​(java.lang.reflect.Field firstField,
                                java.lang.reflect.Field... additionalFields)
        Add specific fields that should be suppressed upon invocation.
      • addFieldToSuppress

        void addFieldToSuppress​(java.lang.reflect.Field[] fields)
        Add specific fields that should be suppressed upon invocation.
      • setFieldTypesToSuppress

        void setFieldTypesToSuppress​(java.lang.String[] fieldTypes)
        Set which field types that should be suppressed. Note that this overrides all previous configurations.
      • addFieldTypesToSuppress

        void addFieldTypesToSuppress​(java.lang.String firstType,
                                     java.lang.String... additionalFieldTypes)
        Add field types that should be suppressed.
      • addFieldTypesToSuppress

        void addFieldTypesToSuppress​(java.lang.String[] fieldTypes)
        Add field types that should be suppressed.
      • getMethodsToSuppress

        java.lang.reflect.Method[] getMethodsToSuppress()
        Returns:
        Which methods that should be suppressed/stubbed (i.e. return a default value when invoked).
      • getStubbedMethods

        java.util.Map<java.lang.reflect.Method,​java.lang.Object> getStubbedMethods()
        Get all substitute return values and also returns an unmodifiable map of all method-object pairs the were initialized.
      • getSubstituteReturnValues

        @Deprecated
        java.util.Map<java.lang.reflect.Method,​java.lang.Object> getSubstituteReturnValues()
        Deprecated.
        Use getStubbedMethods() instead.
        Get all substitute return values and also returns an unmodifiable map of all method-object pairs the were initialized.
      • getFieldsToSuppress

        java.lang.reflect.Field[] getFieldsToSuppress()
        Returns:
        Which fields should be suppressed (i.e. will be set to null or other default values).
      • getFieldTypesToSuppress

        java.lang.String[] getFieldTypesToSuppress()
        Returns:
        The fully-qualified names to the fields that should be suppressed.