Skip to content

Commit 5596154

Browse files
committed
Fixed method count in AbstractMethodMockingControl's IllegalStateException message
Issue: SPR-10885
1 parent 5639aa7 commit 5596154

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

spring-aspects/src/main/java/org/springframework/mock/staticmock/AbstractMethodMockingControl.aj

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,36 +97,34 @@ public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMeth
9797

9898
public void verify() {
9999
if (verified != calls.size()) {
100-
throw new IllegalStateException("Expected " + calls.size()
101-
+ " calls, received " + verified);
100+
throw new IllegalStateException("Expected " + calls.size() + " calls, received " + verified);
102101
}
103102
}
104103

105104
/**
106-
* Validate the call and provide the expected return value
107-
* @param lastSig
108-
* @param args
109-
* @return
105+
* Validate the call and provide the expected return value.
110106
*/
111107
public Object respond(String lastSig, Object[] args) {
112108
Call call = nextCall();
113109
CallResponse responseType = call.responseType;
114110
if (responseType == CallResponse.return_) {
115111
return call.returnValue(lastSig, args);
116-
} else if(responseType == CallResponse.throw_) {
117-
return (RuntimeException)call.throwException(lastSig, args);
118-
} else if(responseType == CallResponse.nothing) {
112+
}
113+
else if (responseType == CallResponse.throw_) {
114+
return call.throwException(lastSig, args);
115+
}
116+
else if (responseType == CallResponse.nothing) {
119117
// do nothing
120118
}
121119
throw new IllegalStateException("Behavior of " + call + " not specified");
122120
}
123121

124122
private Call nextCall() {
125-
if (verified > calls.size() - 1) {
126-
throw new IllegalStateException("Expected " + calls.size()
127-
+ " calls, received " + verified);
123+
verified++;
124+
if (verified > calls.size()) {
125+
throw new IllegalStateException("Expected " + calls.size() + " calls, received " + verified);
128126
}
129-
return calls.get(verified++);
127+
return calls.get(verified);
130128
}
131129

132130
public void expectCall(String lastSig, Object lastArgs[]) {
@@ -171,7 +169,8 @@ public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMeth
171169
expectations.expectCall(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs());
172170
// Return value doesn't matter
173171
return null;
174-
} else {
172+
}
173+
else {
175174
return expectations.respond(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs());
176175
}
177176
}

0 commit comments

Comments
 (0)