Skip to content

Commit

Permalink
Refactor: extract duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrPrzybylak committed Mar 2, 2024
1 parent 107bdfe commit f5f2718
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/mockito/internal/verification/Only.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ public void verify(VerificationData data) {
MatchableInvocation target = data.getTarget();
List<Invocation> invocations = data.getAllInvocations();
List<Invocation> chunk = findInvocations(invocations, target);
if (invocations.size() != 1 && !chunk.isEmpty()) {
if(!chunk.isEmpty()) {
markVerified(chunk.get(0), target);
}
if (invocations.size() != 1 && !chunk.isEmpty()) {
Invocation unverified = findFirstUnverified(invocations);
throw noMoreInteractionsWanted(unverified, (List) invocations);
}
if (invocations.size() != 1 || chunk.isEmpty()) {
throw wantedButNotInvoked(target);
}
markVerified(chunk.get(0), target);
}

@Override
Expand Down

0 comments on commit f5f2718

Please sign in to comment.