Skip to content

Sequence of Value Class Matchers not working #778

@CfGit12

Description

@CfGit12

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions