Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I mock a generic (template) private method using MockK in Kotlin?

I would like to mock the following function:

private fun <T> updateItemInDb(id: Long, column: String, data: T)

which is invoked in the following way by my class:

updateItemInDb(it, DB_POS, i), where it is a Long, DB_POS is String and i is an Int.

I want the function to just run without doing anything. I tried the following in my unit test:

1) every { adapter["updateItemInDb"](any<Long>(), any<String>(), any<Int>()) } just Runs

This gives me a type mismatch error: required MockKStubScope<Unit>, found MockKStubScope<Any?>

2) every { adapter["updateItemInDb"](any<Long>(), any<String>(), any<Int>()) } answers { }

This fails at runtime with io.mockk.MockKException: can't find function updateItemInDb(-1078155520644112829, -d008fa83c4f49c0, 843241211) for dynamic call

like image 681
AlexSee Avatar asked Sep 17 '25 19:09

AlexSee


1 Answers

Now yes. Generic private functions was fixed since 1.7.16

like image 62
oleksiyp Avatar answered Sep 20 '25 09:09

oleksiyp