Package org.powermock.core
Class MockGateway
- java.lang.Object
-
- org.powermock.core.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MockGateway.NoMockito
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
Fields Modifier and Type Field Description static java.lang.String
DONT_MOCK_NEXT_CALL
Used to tell the MockGateway that the next call should not be mocked regardless if aMethodInvocationControl
is found in theMockRepository
.static boolean
MOCK_ANNOTATION_METHODS
Tells PowerMock whether or not to mockClass.isAnnotationPresent(Class)
andClass.getAnnotation(Class)
.static boolean
MOCK_GET_CLASS_METHOD
Tells PowerMock whether or not to mockObject.getClass()
.static boolean
MOCK_STANDARD_METHODS
Tells PowerMock to mock standard methods.static java.lang.Object
PROCEED
static java.lang.Object
SUPPRESS
-
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 isnull
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)
-
-
-
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 aMethodInvocationControl
is found in theMockRepository
. 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 areObject.toString()
,Object.hashCode()
andObject.equals(Object)
. By default this istrue
.
-
MOCK_GET_CLASS_METHOD
public static boolean MOCK_GET_CLASS_METHOD
Tells PowerMock whether or not to mockObject.getClass()
.
-
MOCK_ANNOTATION_METHODS
public static boolean MOCK_ANNOTATION_METHODS
Tells PowerMock whether or not to mockClass.isAnnotationPresent(Class)
andClass.getAnnotation(Class)
.
-
-
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 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.
-
-