}
return null;
}
});
// }
Invocation invocation = new Invocation(interceptionObject, new DelegatingMethod(method), arguments,
SequenceNumber.next(), cglibProxyRealMethod) {
private static final long serialVersionUID = -3679957412502758558L;
/**
* We need to override this method because normally the String
* "method" is assembled by calling the "qualifiedName" method but
* this is not possible in our case. The reason is that the
* qualifiedName method does
*
* <pre>
* new MockUtil().getMockName(mock)
* </pre>
*
* which later will call the "isMockitoMock" method which will
* return false and an exception will be thrown. The reason why
* "isMockitoMock" returns false is that the mock is not created by
* the Mockito CGLib Enhancer in case of static methods.
*/
@Override
protected String toString(@SuppressWarnings("rawtypes") List<Matcher> matchers, PrintSettings printSettings) {
MatchersPrinter matchersPrinter = new MatchersPrinter();
String method = Whitebox.getType(getMock()).getName() + "." + getMethodName();
String invocation = method + matchersPrinter.getArgumentsLine(matchers, printSettings);
if (printSettings.isMultiline()
|| (!matchers.isEmpty() && invocation.length() > Whitebox.<Integer> getInternalState(
Invocation.class, "MAX_LINE_LENGTH"))) {
return method + matchersPrinter.getArgumentsBlock(matchers, printSettings);
} else {
return invocation;
}
}
};
try {
return mockHandler.handle(invocation);
} catch (NotAMockException e) {
if(invocation.getMock().getClass().getName().startsWith("java.") && MockRepository.getInstanceMethodInvocationControl(invocation.getMock()) != null) {
return invocation.callRealMethod();
} else {
throw e;
}
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.updateErrorMessageForMethodInvocation(e);