public static boolean suppressConstructorCall(Class<?> type, Object[] args, Class<?>[] sig) throws Throwable { return constructorCall(type, args, sig) != PROCEED; }
@SuppressWarnings("UnusedDeclaration") public static Object methodCall(Class<?> type, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable { return doMethodCall(type, methodName, args, sig, returnTypeAsString); }
private static boolean shouldMockMethod(String methodName, Class<?>[] sig) { if (isJavaStandardMethod(methodName, sig) && !MOCK_STANDARD_METHODS) { return false; } else if (isGetClassMethod(methodName, sig) && !MOCK_GET_CLASS_METHOD) { return false; } else { return !(isAnnotationMethod(methodName, sig) && !MOCK_ANNOTATION_METHODS); } }
private static Object doMethodCall(Object object, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable { if (!shouldMockMethod(methodName, sig)) { return PROCEED; } MockInvocation mockInvocation = new MockInvocation(object, methodName, sig); MethodInvocationControl methodInvocationControl = mockInvocation.getMethodInvocationControl(); Object returnValue = null; // The following describes the equals non-static method. if (isEqualsMethod(mockInvocation) && !isStaticMethod(mockInvocation)) { returnValue = tryHandleEqualsMethod(mockInvocation); } if (returnValue != null) { return returnValue; } return doMethodCall(object, args, returnTypeAsString, mockInvocation, methodInvocationControl); }
private static Object tryHandleEqualsMethod(MockInvocation mockInvocation) { // Fix for Issue http://code.google.com/p/powermock/issues/detail?id=88 // For some reason the method call to equals() on final methods is // intercepted and during the further processing in Mockito the same // equals() method is called on the same instance. A StackOverflowError // is the result. The following fix changes this by checking if the // method to be called is a final equals() method. In that case the // original method is called by returning PROCEED. if (mockInvocation.getMethod().getParameterTypes().length == 1 && mockInvocation.getMethod().getParameterTypes()[0] == Object.class && Modifier.isFinal(mockInvocation.getMethod().getModifiers())) { return PROCEED; } if (calledFromMockito()){ return PROCEED; } return null; }
|| (args[args.length - 1] == null && sig[args.length - 1].getCanonicalName() == null)) && sig.length > 0) { args = copyArgumentsForInnerOrLocalOrAnonymousClass(args, sig[0], false); args = copyArgumentsForInnerOrLocalOrAnonymousClass(args, sig[0], true);
@SuppressWarnings("UnusedDeclaration") public static Object methodCall(Object instance, String methodName, Object[] args, Class<?>[] sig, String returnTypeAsString) throws Throwable { return doMethodCall(instance, methodName, args, sig, returnTypeAsString); }