Mockk: cannot specify an answer for method call

653 views Asked by At

I have the following method call in my Kotlin class:

myService.trigger(id, processVariables, transientVariables)

... where "id" is a String, "processVariables" is a Java Map<String, Object> and "transientVariables" is a Kotlin MutableMap<String, Any>.

How to I specify the answer to return in a unit test for this circumstance? I have tried the following:

every { myService?.trigger(MY_ID, any(), any()) } returns unit

... but I get an error when the unit test runs:

io.mockk.MockKException: no answer found for: MyService(#2).trigger(MY_ID, {}, {key=value})

Thanks in advance for any assistance.

1

There are 1 answers

0
GarlicBread On BEST ANSWER

A workaround that can be compiled and results in a successful test run is to populate the Map with values:

val map = mapOf("Key" to "Value")
every { processInstance.processVariables } returns map

every { myService?.trigger(EXECUTION_ID, map, any()) } returns unit