Class MockGateway


  • public class MockGateway
    extends java.lang.Object
    All mock invocations are routed through this gateway. This includes method calls, construction of new instances and more. Do not use this class directly, but always go through the PowerMock facade.
    • Constructor Summary

      Constructors 
      Constructor Description
      MockGateway()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static boolean calledFromMockito()  
      static java.lang.Object constructorCall​(java.lang.Class<?> type, java.lang.Object[] args, java.lang.Class<?>[] sig)  
      private static java.lang.Object[] copyArgumentsForInnerOrLocalOrAnonymousClass​(java.lang.Object[] args, java.lang.Class<?> sig, boolean excludeEnclosingInstance)
      The first parameter of an inner, local or anonymous inner class is null or the enclosing instance.
      private static java.lang.Object doMethodCall​(java.lang.Object object, java.lang.Object[] args, java.lang.String returnTypeAsString, MockInvocation mockInvocation, MethodInvocationControl methodInvocationControl)  
      private static java.lang.Object doMethodCall​(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] sig, java.lang.String returnTypeAsString)  
      static java.lang.Object fieldCall​(java.lang.Object instanceOrClassContainingTheField, java.lang.Class<?> classDefiningField, java.lang.String fieldName, java.lang.Class<?> fieldType)  
      private static boolean isAnnotationMethod​(java.lang.String methodName, java.lang.Class<?>[] sig)  
      private static boolean isEqualsMethod​(MockInvocation mockInvocation)  
      private static boolean isGetClassMethod​(java.lang.String methodName, java.lang.Class<?>[] sig)  
      private static boolean isJavaStandardMethod​(java.lang.String methodName, java.lang.Class<?>[] sig)  
      private static boolean isStaticMethod​(MockInvocation mockInvocation)  
      static java.lang.Object methodCall​(java.lang.Class<?> type, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] sig, java.lang.String returnTypeAsString)  
      static java.lang.Object methodCall​(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] sig, java.lang.String returnTypeAsString)  
      static java.lang.Object newInstanceCall​(java.lang.Class<?> type, java.lang.Object[] args, java.lang.Class<?>[] sig)  
      private static boolean shouldMockMethod​(java.lang.String methodName, java.lang.Class<?>[] sig)  
      private static boolean shouldMockThisCall()  
      static java.lang.Object staticConstructorCall​(java.lang.String className)  
      static boolean suppressConstructorCall​(java.lang.Class<?> type, java.lang.Object[] args, java.lang.Class<?>[] sig)  
      private static java.lang.Object tryHandleEqualsMethod​(MockInvocation mockInvocation)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROCEED

        public static final java.lang.Object PROCEED
      • SUPPRESS

        public static final java.lang.Object SUPPRESS
      • DONT_MOCK_NEXT_CALL

        public static final java.lang.String DONT_MOCK_NEXT_CALL
        Used to tell the MockGateway that the next call should not be mocked regardless if a MethodInvocationControl is found in the MockRepository. Used to allow for e.g. recursive partial mocking.
        See Also:
        Constant Field Values
      • MOCK_STANDARD_METHODS

        public static boolean MOCK_STANDARD_METHODS
        Tells PowerMock to mock standard methods. These are Object.toString(), Object.hashCode() and Object.equals(Object). By default this is true.
      • MOCK_GET_CLASS_METHOD

        public static boolean MOCK_GET_CLASS_METHOD
        Tells PowerMock whether or not to mock Object.getClass().
      • MOCK_ANNOTATION_METHODS

        public static boolean MOCK_ANNOTATION_METHODS
        Tells PowerMock whether or not to mock Class.isAnnotationPresent(Class) and Class.getAnnotation(Class).
    • Constructor Detail

      • MockGateway

        public MockGateway()
    • Method Detail

      • newInstanceCall

        public static java.lang.Object newInstanceCall​(java.lang.Class<?> type,
                                                       java.lang.Object[] args,
                                                       java.lang.Class<?>[] sig)
                                                throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • fieldCall

        public static java.lang.Object fieldCall​(java.lang.Object instanceOrClassContainingTheField,
                                                 java.lang.Class<?> classDefiningField,
                                                 java.lang.String fieldName,
                                                 java.lang.Class<?> fieldType)
      • staticConstructorCall

        public static java.lang.Object staticConstructorCall​(java.lang.String className)
      • constructorCall

        public static java.lang.Object constructorCall​(java.lang.Class<?> type,
                                                       java.lang.Object[] args,
                                                       java.lang.Class<?>[] sig)
                                                throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • suppressConstructorCall

        public static boolean suppressConstructorCall​(java.lang.Class<?> type,
                                                      java.lang.Object[] args,
                                                      java.lang.Class<?>[] sig)
                                               throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • methodCall

        public static java.lang.Object methodCall​(java.lang.Object instance,
                                                  java.lang.String methodName,
                                                  java.lang.Object[] args,
                                                  java.lang.Class<?>[] sig,
                                                  java.lang.String returnTypeAsString)
                                           throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • methodCall

        public static java.lang.Object methodCall​(java.lang.Class<?> type,
                                                  java.lang.String methodName,
                                                  java.lang.Object[] args,
                                                  java.lang.Class<?>[] sig,
                                                  java.lang.String returnTypeAsString)
                                           throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • doMethodCall

        private static java.lang.Object doMethodCall​(java.lang.Object object,
                                                     java.lang.String methodName,
                                                     java.lang.Object[] args,
                                                     java.lang.Class<?>[] sig,
                                                     java.lang.String returnTypeAsString)
                                              throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • doMethodCall

        private static java.lang.Object doMethodCall​(java.lang.Object object,
                                                     java.lang.Object[] args,
                                                     java.lang.String returnTypeAsString,
                                                     MockInvocation mockInvocation,
                                                     MethodInvocationControl methodInvocationControl)
                                              throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • tryHandleEqualsMethod

        private static java.lang.Object tryHandleEqualsMethod​(MockInvocation mockInvocation)
      • isEqualsMethod

        private static boolean isEqualsMethod​(MockInvocation mockInvocation)
      • isStaticMethod

        private static boolean isStaticMethod​(MockInvocation mockInvocation)
      • calledFromMockito

        private static boolean calledFromMockito()
      • shouldMockMethod

        private static boolean shouldMockMethod​(java.lang.String methodName,
                                                java.lang.Class<?>[] sig)
      • isJavaStandardMethod

        private static boolean isJavaStandardMethod​(java.lang.String methodName,
                                                    java.lang.Class<?>[] sig)
      • isGetClassMethod

        private static boolean isGetClassMethod​(java.lang.String methodName,
                                                java.lang.Class<?>[] sig)
      • isAnnotationMethod

        private static boolean isAnnotationMethod​(java.lang.String methodName,
                                                  java.lang.Class<?>[] sig)
      • shouldMockThisCall

        private static boolean shouldMockThisCall()
      • copyArgumentsForInnerOrLocalOrAnonymousClass

        private static java.lang.Object[] copyArgumentsForInnerOrLocalOrAnonymousClass​(java.lang.Object[] args,
                                                                                       java.lang.Class<?> sig,
                                                                                       boolean excludeEnclosingInstance)
        The first parameter of an inner, local or anonymous inner class is null or the enclosing instance. This should not be included in the substitute invocation since it is never expected by the user.

        Seems with Javassist 3.17.1-GA & Java 7, the 'null' is passed as the last argument.