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

Sequence of Value Class Matchers not working #778

Closed
3 tasks done
CfGit12 opened this issue Jan 4, 2022 · 4 comments
Closed
3 tasks done

Sequence of Value Class Matchers not working #778

CfGit12 opened this issue Jan 4, 2022 · 4 comments

Comments

@CfGit12
Copy link

CfGit12 commented Jan 4, 2022

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

When using verifySequence and trying to use multiple instances of any() as a matcher for a value class parameter it should work.

Current Behavior

The first any() matcher works. Subsequent any() matchers fail.

Failure Information (for bugs)

I've looked at #633 and #152 which seem to cover off the general case of using value classes. I've not found anything covering my verifySequence issue however. I note a workaround further down which I am going to use for now but thought best to raise this.

Steps to Reproduce

Minimal code below. If you comment out the failing case (which is what I want to work) then the verify exactly 3 version does work, which for now is an acceptable workaround. Would like the sequence version though.

class ValueClassSequenceTest: StringSpec() {

    interface MyInterface {
        fun doSomething(x: MyValueClass) {
            return
        }
    }

    @JvmInline
    value class MyValueClass(val something: Int)

    init {
        "Test repeated call of doSomething" {
            val myInterface: MyInterface = mockk(relaxed = true)

            myInterface.doSomething(MyValueClass(1))
            myInterface.doSomething(MyValueClass(2))
            myInterface.doSomething(MyValueClass(3))

            // Does NOT work
            verifySequence {
                myInterface.doSomething(any())
                myInterface.doSomething(any()) // Fails - uses a matcher of eq(0) (see below)
                myInterface.doSomething(any()) // Fails - uses a matcher of eq(0) (see below)
            }
            
            // Note: removing the second/third calls and matchers and leaving only one behind in the sequence
            // DOES work.

            // Also Works
            verify(exactly = 3) {
                myInterface.doSomething(any())
            }
        }
    }
}

Context

  • MockK version: 1.12.2
  • OS: macOS
  • Kotlin version: 1.6.0
  • JDK version: 17
  • JUnit version: kotest 4.6.3
  • Type of test: unit test

Failure Logs

Note that first matcher is correct, second and third are not.

Verification failed: calls are not exactly matching verification sequence

Matchers: 
+MyInterface(#1).doSomething-MR0IliI(any()))
MyInterface(#1).doSomething-MR0IliI(eq(0)))
MyInterface(#1).doSomething-MR0IliI(eq(0)))

Calls:
1) MyInterface(#1).doSomething-MR0IliI(1)
2) MyInterface(#1).doSomething-MR0IliI(2)
3) +MyInterface(#1).doSomething-MR0IliI(3)
@Raibaz
Copy link
Collaborator

Raibaz commented Jan 12, 2022

Looks like a bug indeed, thanks for submitting this.

@Raibaz Raibaz assigned Raibaz and unassigned Raibaz Jan 12, 2022
@Raibaz Raibaz added the bug label Jan 12, 2022
@Raibaz
Copy link
Collaborator

Raibaz commented Jan 12, 2022

Out of curiosity, is this still happening if you use allAny() rather than any()?

@CfGit12
Copy link
Author

CfGit12 commented Jan 13, 2022

Yep. That also fails with the same problem.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

@stale stale bot added the stale label Apr 16, 2022
@stale stale bot closed this as completed Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants