I'm experiencing following problem. I've got a spring boot test, where I inject and spy the mongoDbChannel
bean. Then I try to start the normal workflow and verify if the method send
is called on the bean.
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MongoAsBackupConfig.class},
properties = {},
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class MongoAsBackupConfigTest {
@SpyBean(name = "mongoDbChannel")
private QueueChannel mongoDbChannel;
@Autowired
private DirectChannel mongoDbWithFailoverChannel;
@DirtiesContext
@Test
public void shouldUseFallbackForFullQueue() throws InterruptedException {
IntStream.rangeClosed(1, BACKUP_QUEUE_CAPACITY + OVERFILLING_CLICK_COUNT).forEach(someNumber ->
mongoDbWithFailoverChannel.send(MessageBuilder.withPayload(createPayload(someNumber)).build()));
verify(mongoDbChannel, times(BACKUP_QUEUE_CAPACITY)).send(Mockito.any());
}
}
As a result, I get the error message that any
doesn't match to the concrete parameter value. However normally any
means any value of param. What went wrong here?
Argument(s) are different! Wanted:
mongoDbChannel.send(
<any>
);
-> at MongoAsBackupConfigTest.shouldUseFallbackForFullQueue(MongoAsBackupConfigTest.java:67)
Actual invocation has different arguments:
mongoDbChannel.send(
GenericMessage [payload=Click(...), headers={id=0eaa2317-b1b5-604d-65c5-78da521cd585, timestamp=1509085945379}],
10
);
-> at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
EDITED:
I'm using java 8. And I tried to use any(GenericMessage.class)
, any(Message.class)
but it was the same effect.