Skip to content

Kotlin data class and ArgumentMatchers issue #558

@johnowl

Description

@johnowl

When I run the test below (created only to illustrate a real problem) I expect it to pass, but it doesn't.

@JvmInline value class MyValueClass(
    val value: String,
)

class MyClass {
    fun myMethod(myValueClass: MyValueClass): String = myValueClass.value
}

class Test {
    @Test
    fun testDoSomething() {
        val myValueClass = MyValueClass("something")
        val mock = mock<MyClass>()

        whenever(mock.myMethod(eq(myValueClass))).thenReturn("something")

        assertThat(mock.myMethod(myValueClass)).isEqualTo("something")
    }
}

However, if I refactor the MyValueClass to be a data class, it works. Any workaround to make it work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions