Package org.powermock.core
Class MockGateway
- java.lang.Object
-
- org.powermock.core.MockGateway
-
public class MockGateway extends java.lang.ObjectAll 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 classMockGateway.NoMockitoMockGateway.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
Fields Modifier and Type Field Description static java.lang.StringDONT_MOCK_NEXT_CALLUsed to tell the MockGateway that the next call should not be mocked regardless if aMethodInvocationControlis found in theMockRepository.static booleanMOCK_ANNOTATION_METHODSTells PowerMock whether or not to mockClass.isAnnotationPresent(Class)andClass.getAnnotation(Class).static booleanMOCK_GET_CLASS_METHODTells PowerMock whether or not to mockObject.getClass().static booleanMOCK_STANDARD_METHODSTells PowerMock to mock standard methods.static java.lang.ObjectPROCEEDstatic java.lang.ObjectSUPPRESS
-
Constructor Summary
Constructors Constructor Description MockGateway()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleancalledFromMockito()static java.lang.ObjectconstructorCall(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 isnullor the enclosing instance.private static java.lang.ObjectdoMethodCall(java.lang.Object object, java.lang.Object[] args, java.lang.String returnTypeAsString, MockInvocation mockInvocation, MethodInvocationControl methodInvocationControl)private static java.lang.ObjectdoMethodCall(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] sig, java.lang.String returnTypeAsString)static java.lang.ObjectfieldCall(java.lang.Object instanceOrClassContainingTheField, java.lang.Class<?> classDefiningField, java.lang.String fieldName, java.lang.Class<?> fieldType)private static booleanisAnnotationMethod(java.lang.String methodName, java.lang.Class<?>[] sig)private static booleanisEqualsMethod(MockInvocation mockInvocation)private static booleanisGetClassMethod(java.lang.String methodName, java.lang.Class<?>[] sig)private static booleanisJavaStandardMethod(java.lang.String methodName, java.lang.Class<?>[] sig)private static booleanisStaticMethod(MockInvocation mockInvocation)static java.lang.ObjectmethodCall(java.lang.Class<?> type, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] sig, java.lang.String returnTypeAsString)static java.lang.ObjectmethodCall(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] sig, java.lang.String returnTypeAsString)static java.lang.ObjectnewInstanceCall(java.lang.Class<?> type, java.lang.Object[] args, java.lang.Class<?>[] sig)private static booleanshouldMockMethod(java.lang.String methodName, java.lang.Class<?>[] sig)private static booleanshouldMockThisCall()static java.lang.ObjectstaticConstructorCall(java.lang.String className)static booleansuppressConstructorCall(java.lang.Class<?> type, java.lang.Object[] args, java.lang.Class<?>[] sig)private static java.lang.ObjecttryHandleEqualsMethod(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 aMethodInvocationControlis 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 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 & Java 7, the 'null' is passed as the last argument.
-
-