Vitalii
Vitalii

Reputation: 11081

Mockito ambiguous method call: any() matches class and object

I need to mock this code

rabbitTemplate.convertAndSend(message, m -> {
    m.getMessageProperties().getHeaders().put("type", HEADER);
    return m;
});

I my test I write

doNothing().when(rabbitTemplate).convertAndSend(anyObject(), any(MessagePostProcessor.class));

There is an error

enter image description here

Any ideas about workaround?

Upvotes: 0

Views: 5746

Answers (1)

pvpkiran
pvpkiran

Reputation: 27048

Instead of using anyObject(). Try specifying the type.

doNothing().when(rabbitTemplate).convertAndSend(Mockito.any(String.class), any(MessagePostProcessor.class));

Upvotes: 3

Related Questions