Package org.powermock.core
Class MockGateway
java.lang.Object
org.powermock.core.MockGateway
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
MockGateway.NoMockito.noMockito
is wrapped into it's own static class to make sure it is initialized not earlier thancalledFromMockito()
is called for the first time. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Used to tell the MockGateway that the next call should not be mocked regardless if aMethodInvocationControl
is found in theMockRepository
.static boolean
Tells PowerMock whether or not to mockClass.isAnnotationPresent(Class)
andClass.getAnnotation(Class)
.static boolean
Tells PowerMock whether or not to mockObject.getClass()
.static boolean
Tells PowerMock to mock standard methods.static final Object
static final Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
static Object
constructorCall
(Class<?> type, Object[] args, Class<?>[] sig) private static Object[]
copyArgumentsForInnerOrLocalOrAnonymousClass
(Object[] args, Class<?> sig, boolean excludeEnclosingInstance) The first parameter of an inner, local or anonymous inner class isnull
or the enclosing instance.private static Object
doMethodCall
(Object object, Object[] args, String returnTypeAsString, MockInvocation mockInvocation, MethodInvocationControl methodInvocationControl) private static Object
doMethodCall
(Object object, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) static Object
fieldCall
(Object instanceOrClassContainingTheField, Class<?> classDefiningField, String fieldName, Class<?> fieldType) private static boolean
isAnnotationMethod
(String methodName, Class<?>[] sig) private static boolean
isEqualsMethod
(MockInvocation mockInvocation) private static boolean
isGetClassMethod
(String methodName, Class<?>[] sig) private static boolean
isJavaStandardMethod
(String methodName, Class<?>[] sig) private static boolean
isStaticMethod
(MockInvocation mockInvocation) static Object
methodCall
(Class<?> type, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) static Object
methodCall
(Object instance, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) static Object
newInstanceCall
(Class<?> type, Object[] args, Class<?>[] sig) private static boolean
shouldMockMethod
(String methodName, Class<?>[] sig) private static boolean
static Object
staticConstructorCall
(String className) static boolean
suppressConstructorCall
(Class<?> type, Object[] args, Class<?>[] sig) private static Object
tryHandleEqualsMethod
(MockInvocation mockInvocation)
-
Field Details
-
PROCEED
-
SUPPRESS
-
DONT_MOCK_NEXT_CALL
Used to tell the MockGateway that the next call should not be mocked regardless if aMethodInvocationControl
is found in theMockRepository
. Used to allow for e.g. recursive partial mocking.- See Also:
-
MOCK_STANDARD_METHODS
public static boolean MOCK_STANDARD_METHODSTells PowerMock to mock standard methods. These areObject.toString()
,Object.hashCode()
andObject.equals(Object)
. By default this istrue
. -
MOCK_GET_CLASS_METHOD
public static boolean MOCK_GET_CLASS_METHODTells PowerMock whether or not to mockObject.getClass()
. -
MOCK_ANNOTATION_METHODS
public static boolean MOCK_ANNOTATION_METHODSTells PowerMock whether or not to mockClass.isAnnotationPresent(Class)
andClass.getAnnotation(Class)
.
-
-
Constructor Details
-
MockGateway
public MockGateway()
-
-
Method Details
-
newInstanceCall
- Throws:
Throwable
-
fieldCall
-
staticConstructorCall
-
constructorCall
- Throws:
Throwable
-
suppressConstructorCall
public static boolean suppressConstructorCall(Class<?> type, Object[] args, Class<?>[] sig) throws Throwable - Throws:
Throwable
-
methodCall
public static Object methodCall(Object instance, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable - Throws:
Throwable
-
methodCall
public static Object methodCall(Class<?> type, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable - Throws:
Throwable
-
doMethodCall
private static Object doMethodCall(Object object, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable - Throws:
Throwable
-
doMethodCall
private static Object doMethodCall(Object object, Object[] args, String returnTypeAsString, MockInvocation mockInvocation, MethodInvocationControl methodInvocationControl) throws Throwable - Throws:
Throwable
-
tryHandleEqualsMethod
-
isEqualsMethod
-
isStaticMethod
-
calledFromMockito
private static boolean calledFromMockito() -
shouldMockMethod
-
isJavaStandardMethod
-
isGetClassMethod
-
isAnnotationMethod
-
shouldMockThisCall
private static boolean shouldMockThisCall() -
copyArgumentsForInnerOrLocalOrAnonymousClass
private static Object[] copyArgumentsForInnerOrLocalOrAnonymousClass(Object[] args, Class<?> sig, boolean excludeEnclosingInstance) The first parameter of an inner, local or anonymous inner class isnull
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 invalid input: '&' Java 7, the 'null
' is passed as the last argument.
-