Skip to content

Commit

Permalink
Fix do-syntax handling in MockitoWhen
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmladenov committed Jul 22, 2024
1 parent f661d91 commit be6b295
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@ public boolean visit(MethodInvocation mi) {
* If the method call just after when() matches the one we are expecting, bingo!
*/
if(inWhenMode) {
if(methodToSetUp.equals(methodName) || methodToSetUp.equals(previousMethodName)) {
if(methodToSetUp.equals(methodName) ||
methodToSetUp.equals(previousMethodName) && allowedDoInvocations.contains(methodName)) {
numberOfCallsToWhen++;
inWhenMode = false;
previousMethodName = "";
} else if(notInDoWhenOrNoMatch(methodName)){
inWhenMode = false;
previousMethodName = "";
} else {
previousMethodName = methodName;
}
inWhenMode = false;
previousMethodName = "";
} else {
/**
* We wait for a call to when().
Expand All @@ -70,12 +66,7 @@ public boolean visit(MethodInvocation mi) {
}
return super.visit(mi);
}
private boolean notInDoWhenOrNoMatch(String methodName){
return !methodName.equals("when")
&&
(allowedDoInvocations.contains(previousMethodName)
|| !allowedDoInvocations.contains(methodName));
}

@Override
public boolean result() {
return comparison.compare(numberOfCallsToWhen, expectedNumberOfOccurrences);
Expand Down

0 comments on commit be6b295

Please sign in to comment.