我遇到以下问题。我有一个弹簧启动测试,我在其中注入和监视mongoDbChannel
bean。然后我尝试启动正常的工作流程并验证是否send
在 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());
}
}
结果,我收到any
与具体参数值不匹配的错误消息。然而,通常any
意味着任何参数值。这里出了什么问题?
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)
已编辑:我正在使用 java 8。我尝试使用any(GenericMessage.class)
,any(Message.class)
但效果相同。