mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.09k stars 198 forks source link

Verifying enum value #449

Closed rekire closed 2 years ago

rekire commented 2 years ago

I'm trying to verify that a method is called with a given argument. That argument is a non-nullable enum type. So I get the exception eq(SomeEnum.foo) must not be null. Here is a sample what I'm trying to do:

enum class SomeEnum {
    foo, bar
}

open class MyClass {
    fun doSomething() {
        magic(SomeEnum.foo)
    }

    internal fun magic(whatever: SomeEnum) {}
}

@Test
fun mockitoBug() {
    val sut = spy(MyClass())
    sut.doSomething()
    verify(sut).magic(eq(SomeEnum.foo))
}

Capturing does not work too. What can I do or is that really a bug as I assume?

rekire commented 2 years ago

I used the wrong import for eq. I had import org.mockito.Mockito.* but it should be import org.mockito.kotlin.*