【发布时间】:2017-10-27 06:43:16
【问题描述】:
我遇到以下问题。我有一个弹簧启动测试,我在其中注入和监视mongoDbChannel bean。然后我尝试启动正常的工作流程并验证是否在 bean 上调用了方法 send。
@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),但效果相同。
【问题讨论】:
标签: spring-boot java-8 mockito integration-testing springmockito