I have a function with many overloads: ```fun prep...
# mockk
m
I have a function with many overloads:
Copy code
fun prepareStatement(sql: String): PreparedStatement
fun prepareStatement(sql: String, resultSetType: Int): PreparedStatement
fun prepareStatement(sql: String, resultSetType: Int, resultSetConcurrency: Int): PreparedStatement
fun prepareStatement(sql: String, resultSetType: Int, resultSetConcurrency: Int, resultSetHoldability: Int): PreparedStatement
What if I want to mock all of them in the same way, whereas I only care about the `sql`parameter? Currently I repeat
every  {
block for each overload. Is there more preferred way, e.g. matching functions by name?
m
i’m guessing (hoping, really) your overloads each call the last one setting default values for the parameters that they don’t receive. If that’s the case, you should be able to have the first overloads mocked with
every { prepareStatement(any()) } answers { callOriginal() }
and then mock just the last one in each of your tests does this make sense to you?
m
Thanks for the idea, I have not thought that the overloads should actually call each other. But I have already extracted the answer to a `val answer = FunctionAnswer { call -> ... }`and provided that to each overload, so if I need to specify them all anyway, then that way is very close.
m
makes a lot of sense