具有返回类型Message<?>的Spring Integration Activator的JUnit. [英] JUnit for Spring Integration Activator with return type Message<?>
本文介绍了具有返回类型Message<?>的Spring Integration Activator的JUnit.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个JUnit测试用例.而且我的线索越来越少了,如何为以下方法编写测试用例. 所有需要嘲笑的东西.
I am trying to write a JUnit test cases. and I became clue less how can i write test case for the below method. What all needs to be mocked.
@Autowired
private DoseService doseService;
public Message<List<Dose>> getAllDoses() {
log.info("GET method");
List<Dose> doseLst = doseService.getAllDoses();
return MessageBuilder.withPayload(doseLst).setHeader("http_statusCode",
HttpStatus.OK).build();
}
预先感谢您的帮助.
推荐答案
针对您的方法,我会说只需要模拟DoseService
即可.其他一切看起来不错,您也不需要Message
作为参数.
Looking to your method I would say that only DoseService
has to be mocked. Everything else looks good and you also don’t need the Message
as an argument.
对于模拟,您可以使用Spring Boot中的@MockBean
.
For mocking you can use a @MockBean
from Spring Boot.
这篇关于具有返回类型Message<?>的Spring Integration Activator的JUnit.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文