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 classMockGateway.NoMockito.noMockitois 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 StringUsed to tell the MockGateway that the next call should not be mocked regardless if aMethodInvocationControlis found in theMockRepository.static booleanTells PowerMock whether or not to mockClass.isAnnotationPresent(Class)andClass.getAnnotation(Class).static booleanTells PowerMock whether or not to mockObject.getClass().static booleanTells PowerMock to mock standard methods.static final Objectstatic final Object -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanstatic ObjectconstructorCall(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 isnullor the enclosing instance.private static ObjectdoMethodCall(Object object, Object[] args, String returnTypeAsString, MockInvocation mockInvocation, MethodInvocationControl methodInvocationControl) private static ObjectdoMethodCall(Object object, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) static ObjectfieldCall(Object instanceOrClassContainingTheField, Class<?> classDefiningField, String fieldName, Class<?> fieldType) private static booleanisAnnotationMethod(String methodName, Class<?>[] sig) private static booleanisEqualsMethod(MockInvocation mockInvocation) private static booleanisGetClassMethod(String methodName, Class<?>[] sig) private static booleanisJavaStandardMethod(String methodName, Class<?>[] sig) private static booleanisStaticMethod(MockInvocation mockInvocation) static ObjectmethodCall(Class<?> type, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) static ObjectmethodCall(Object instance, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) static ObjectnewInstanceCall(Class<?> type, Object[] args, Class<?>[] sig) private static booleanshouldMockMethod(String methodName, Class<?>[] sig) private static booleanstatic ObjectstaticConstructorCall(String className) static booleansuppressConstructorCall(Class<?> type, Object[] args, Class<?>[] sig) private static ObjecttryHandleEqualsMethod(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 aMethodInvocationControlis 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
-
fieldCall
-
staticConstructorCall
-
constructorCall
-
suppressConstructorCall
-
methodCall
-
methodCall
-
doMethodCall
-
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 isnullor 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.
-