hello folks given the function: ```fun <T : Any...
# mockk
l
hello folks given the function:
Copy code
fun <T : Any> myFunction(foo: Foo, bar: Bar, response: KClass<T>): MyResponse<T> { do magic }
how can it be mocked to control the returned object? I tried something like:
Copy code
every { mockedClass.myFunction(any(), any(), ofType(SomeType::class) } returns SomeType()
but it didn't work... and using the type directly,
myFunction(any(), any(), SomeType::class)
is never matched.
e
why
ofType()
? that would match a
SomeType
, not a
KClass<SomeType>
a straightforward
Copy code
mockedClass.myFunction(any(), any(), SomeType::class)
should work
👍 1
if you do want
KClass<out SomeType>
, you'd have to write a custom matcher, like
Copy code
myFunction(any(), any(), match<KClass<*>>(SomeType::class::isSuperclassOf))
l
@ephemient using
myFunction(any(), any(), SomeType::class)
is never matched… only returns
null
for it