if (!shouldMockMethod(methodName, sig)) {
return PROCEED;
}
Object returnValue = null;
MethodInvocationControl methodInvocationControl;
Class<?> objectType;
if (object instanceof Class<?>) {
objectType = (Class<?>) object;
methodInvocationControl = MockRepository.getStaticMethodInvocationControl(objectType);
} else {
final Class<?> type = object.getClass();
objectType = WhiteboxImpl.getUnmockedType(type);
methodInvocationControl = MockRepository.getInstanceMethodInvocationControl(object);
}
/*
* if invocationControl is null or the method is not mocked, invoke
* original method or suppress the method code otherwise invoke the
* invocation handler.
*/
Method method;
try {
method = WhiteboxImpl.getBestMethodCandidate(objectType, methodName, sig, true);
} catch (MethodNotFoundException e) {
/*
* Dirty hack to get around issue 110
* (http://code.google.com/p/powermock/issues/detail?id=110). Review
* this! What we do here is to try to find a reflective method on
* class. This has begun to fail since version 1.2 when we supported
* mocking static methods in system classes.
*/
try {
method = WhiteboxImpl.getMethod(Class.class, methodName, sig);
} catch (MethodNotFoundException e2) {
throw e;
}
}
// 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 ( // The following describes the equals method.
method.getName().equals("equals")
&& method.getParameterTypes().length == 1
&& method.getParameterTypes()[0] == Object.class
&& Modifier.isFinal(method.getModifiers())) {
returnValue = PROCEED;
} else {
if (methodInvocationControl != null && methodInvocationControl.isMocked(method) && shouldMockThisCall()) {
returnValue = methodInvocationControl.invoke(object, method, args);
if (returnValue == SUPPRESS) {
returnValue = TypeUtils.getDefaultValue(returnTypeAsString);
}
} else if (MockRepository.hasMethodProxy(method)) {
/*