Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #731 No methods matching the name(s) get were found in the …
…class hierarchy for interfaces
- Loading branch information
Arthur Zagretdinov
committed
Jan 28, 2017
1 parent
ddda468
commit 53bdb4c
Showing
19 changed files
with
439 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
powermock-core/src/main/java/org/powermock/core/MockInvocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.powermock.core; | ||
|
||
import org.powermock.core.spi.MethodInvocationControl; | ||
import org.powermock.reflect.exceptions.MethodNotFoundException; | ||
import org.powermock.reflect.internal.WhiteboxImpl; | ||
import org.powermock.reflect.internal.proxy.UnproxiedType; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
class MockInvocation { | ||
private Object object; | ||
private String methodName; | ||
private Class<?>[] sig; | ||
private Class<?> objectType; | ||
private MethodInvocationControl methodInvocationControl; | ||
private Method method; | ||
|
||
MockInvocation(Object object, String methodName, Class<?>... sig) { | ||
this.object = object; | ||
this.methodName = methodName; | ||
this.sig = sig; | ||
init(); | ||
} | ||
|
||
private void init() { | ||
if (object instanceof Class<?>) { | ||
objectType = (Class<?>) object; | ||
methodInvocationControl = MockRepository.getStaticMethodInvocationControl(objectType); | ||
} else { | ||
final Class<?> type = object.getClass(); | ||
UnproxiedType unproxiedType = WhiteboxImpl.getUnproxiedType(type); | ||
objectType = unproxiedType.getOriginalType(); | ||
methodInvocationControl = MockRepository.getInstanceMethodInvocationControl(object); | ||
} | ||
method = findMethodToInvoke(methodName, sig, objectType); | ||
} | ||
|
||
Class<?> getObjectType() { | ||
return objectType; | ||
} | ||
|
||
MethodInvocationControl getMethodInvocationControl() { | ||
return methodInvocationControl; | ||
} | ||
|
||
Method getMethod() { | ||
return method; | ||
} | ||
|
||
private static Method findMethodToInvoke(String methodName, Class<?>[] sig, Class<?> objectType) { | ||
/* | ||
* 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; | ||
} | ||
} | ||
return method; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.