提交 3ca0dcd9 编写于 作者: J Juergen Hoeller 提交者: unknown

Fixed method count in AbstractMethodMockingControl's IllegalStateException message

Issue: SPR-10885
(cherry picked from commit 55961544)
上级 e33324b7
...@@ -97,36 +97,34 @@ public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMeth ...@@ -97,36 +97,34 @@ public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMeth
public void verify() { public void verify() {
if (verified != calls.size()) { if (verified != calls.size()) {
throw new IllegalStateException("Expected " + calls.size() throw new IllegalStateException("Expected " + calls.size() + " calls, received " + verified);
+ " calls, received " + verified);
} }
} }
/** /**
* Validate the call and provide the expected return value * Validate the call and provide the expected return value.
* @param lastSig
* @param args
* @return
*/ */
public Object respond(String lastSig, Object[] args) { public Object respond(String lastSig, Object[] args) {
Call call = nextCall(); Call call = nextCall();
CallResponse responseType = call.responseType; CallResponse responseType = call.responseType;
if (responseType == CallResponse.return_) { if (responseType == CallResponse.return_) {
return call.returnValue(lastSig, args); return call.returnValue(lastSig, args);
} else if(responseType == CallResponse.throw_) { }
return (RuntimeException)call.throwException(lastSig, args); else if (responseType == CallResponse.throw_) {
} else if(responseType == CallResponse.nothing) { return call.throwException(lastSig, args);
}
else if (responseType == CallResponse.nothing) {
// do nothing // do nothing
} }
throw new IllegalStateException("Behavior of " + call + " not specified"); throw new IllegalStateException("Behavior of " + call + " not specified");
} }
private Call nextCall() { private Call nextCall() {
if (verified > calls.size() - 1) { verified++;
throw new IllegalStateException("Expected " + calls.size() if (verified > calls.size()) {
+ " calls, received " + verified); throw new IllegalStateException("Expected " + calls.size() + " calls, received " + verified);
} }
return calls.get(verified++); return calls.get(verified);
} }
public void expectCall(String lastSig, Object lastArgs[]) { public void expectCall(String lastSig, Object lastArgs[]) {
...@@ -171,7 +169,8 @@ public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMeth ...@@ -171,7 +169,8 @@ public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMeth
expectations.expectCall(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs()); expectations.expectCall(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs());
// Return value doesn't matter // Return value doesn't matter
return null; return null;
} else { }
else {
return expectations.respond(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs()); return expectations.respond(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs());
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册