1

I am using Mockk as my mocking framework when testing my Spring Boot Data repository interfaces.

Actually I am doing the following

every { itemRepository.saveAll(listOf(any(), any())) } returns listOf<Item>(mockk())

which should mock the following behaviour

val loot: List<Item> = itemGenerator.generateLoot(lootTable)
itemRepository.saveAll(loot)

The error message I receive is the following:

Failed matching mocking signature for
SignedCall(retValue=, isRetValueMock=true, retType=class kotlin.collections.Iterable, self=ItemRepository(#28), method=saveAll(Iterable), args=[[com.barbarus.gameserver.item.Item@ea00de, com.barbarus.gameserver.item.Item@23ca36d]], invocationStr=ItemRepository(#28).saveAll([com.barbarus.gameserver.item.Item@ea00de, com.barbarus.gameserver.item.Item@23ca36d]))
left matchers: [any(), any()]

The error message says left matchers: [any(), any()] pointing out that I somehow am not defining the expected arguments right.

I could fully define the items by real implementations in my test logic but I'd like to stick with mockk() just to keep the test code slim and fast.

However I kinda am not able to define the List<Item> with two elements using listOf(any(),any()) here. I tried other API of Mockk without any luck.

Any idea what to use in this case?

xetra11
  • 7,671
  • 14
  • 84
  • 159

1 Answers1

1

You should type the any() when you are passing into saveAll().

For instance:

import com.barbarus.gameserver.item.Item
...

every { itemRepository.saveAll(any<List<Item>>() } returns listOf<Item>(mockk())

Solution from another post

Byron Wong
  • 145
  • 9