Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix verifier logic for slots and different matchers #951

Merged
merged 1 commit into from Oct 24, 2022

Conversation

m-burst
Copy link
Contributor

@m-burst m-burst commented Oct 21, 2022

Closes #774

Comment on lines +58 to +60
val matchedCalls = allCallsForMockMethod.filter(matcher::match)

if(matchedCalls.size > 1 && matcher.args.any { it is CapturingSlotMatcher<*> }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK if there are multiple calls overall but only one of them matches and will be captured

@@ -162,7 +163,7 @@ open class UnorderedCallVerifier(
}

captureBlocks.add {
for (call in allCallsForMockMethod) {
for (call in matchedCalls) {
Copy link
Contributor Author

@m-burst m-burst Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

captureAnswer was called for non-matched calls, which led to incorrect capturing results

Comment on lines -88 to -89
mock.doSomething("1", capture(dataSlotId1))
mock.doSomething("2", capture(dataSlotId2))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not fail if left as is, because with different values of the first argument only 1 call will be matched in each case

Comment on lines +139 to +140
// Each capture should have happened once because of different matchers for `id` argument
assertEquals(slotList.size, 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this was 4

@m-burst m-burst marked this pull request as ready for review October 21, 2022 20:09
@Raibaz
Copy link
Collaborator

Raibaz commented Oct 24, 2022

Brilliant, thanks a lot for fixing this!

@Raibaz Raibaz merged commit a2421bf into mockk:master Oct 24, 2022
@m-burst m-burst deleted the issue-774 branch November 30, 2022 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: capturing subtypes in verify block fails in v1.12.1
2 participants