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.
-
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 mockObject.getClass()
.static boolean
Tells PowerMock to mock standard methods.static final Object
static final Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
constructorCall
(Class<?> type, Object[] args, Class<?>[] sig) private static Object[]
copyArgumentsForInnerOrLocalOrAnonymousClass
(Object[] args, boolean excludeEnclosingInstance) The first parameter of an inner, local or anonymous inner class isnull
or the enclosing instance.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
isGetClassMethod
(String methodName, Class<?>[] sig) private static boolean
isJavaStandardMethod
(String methodName, Class<?>[] sig) 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)
-
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()
.
-
-
Constructor Details
-
MockGateway
public MockGateway()
-
-
Method Details
-
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
-
shouldMockMethod
-
isJavaStandardMethod
-
isGetClassMethod
-
shouldMockThisCall
private static boolean shouldMockThisCall() -
methodCall
public static Object methodCall(Object instance, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable - Throws:
Throwable
-
newInstanceCall
- Throws:
Throwable
-
fieldCall
-
staticConstructorCall
-
constructorCall
- Throws:
Throwable
-
copyArgumentsForInnerOrLocalOrAnonymousClass
private static Object[] copyArgumentsForInnerOrLocalOrAnonymousClass(Object[] args, 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 & Java 7, the 'null
' is passed as the last argument.
-