Reputation: 7201
There was a similar question asked about Mockito here
I have a situation where I would like to mock out readValue
in the following line
val animal: Animal = objectMapper.readValue(String(message.body))
I tried
@Test
fun `test you filthy animal`() {
val animal = Animal("bird")
every {
objectMapper.readValue(any<String>())
} returns animal
}
...but I keep getting the following error:
Not enough information to infer type variable T
I have been scratching my head trying to figure it out in Mockk.
Upvotes: 5
Views: 3984
Reputation: 7201
I ended up figuring it out:
import org.junit.jupiter.api.Test
@Test
fun `test you filthy animal`() {
val animal = Animal("bird")
every {
objectMapper.readValue<Animal>(any<String>())
} returns animal
}
Edit: Later I ran into more issues that were resolved with the following:
every {
objectMapper.readValue(any<String>(), any<TypeReference<Animal>>())
} returns animal
Upvotes: 8