I'm trying to write some unit tests in Kotlin where I need to mock a static method from a Java class (let's call it A). The tricky part is that this method has bounded type parameters. Here's the method signature (C is a class, I is an interface):
public class A {
@NonNull
public static <T extends C & I> A doSomething(T thing) {}
}
In my Kotlin test class, I'm attempting to use the MockK library to mock this static method. I want to capture the thing parameter passed to the doSomething method in a slot, but I'm not sure how I can do this/if this is even possible due to the bounded type parameters.
Here's the essence of what I'm trying to do:
class Test {
@Test
fun test() {
mockkStatic(A::class)
val thingSlot = slot<T extends C & I>()
every { A.doSomething(capture(thingSlot)) } answers { ... }
...
}
}
Is there a way to achieve this in Kotlin using MockK? If not, what alternatives or workarounds could I consider?
The only way I could get something like this to work so far is by defining an explicit type that extends C and I, but I want this to be able to work for any type matching the generic constraint.