Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockk matching and overloaded function withArg

Hello I am trying to find a way to match an overloaded function inside of the verify using withArg

The doc doesnt really point this out

    every { getResponse.Ids } returns listOf(121212L)
    assert( client.getExtIds(Ids) )
    verify {
        client.getExtIdsCall().call(
            withArg {
                assertEquals(GetExtIdsRequest.builder()
                    .withIds("foo")
                    .withType("bar")
                    .build().hashCode(), it.hashCode()
                )
            }
        )
    }

Something like above. But unfortunately I cant because the client.getExtIdsCall().call() accepts two different types of objects. One of which has the hashCode I want. So the it can not be referred correctly to call the hashCode function

like image 379
Bao Thai Avatar asked Oct 29 '25 17:10

Bao Thai


1 Answers

You can resolve this by explicitly specifying the type parameter of function withArg, e.g. if you want your parameter to be a Long, you can write:

withArg<Long> { ... }
like image 155
Karsten Gabriel Avatar answered Nov 01 '25 06:11

Karsten Gabriel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!