概述
Mockito的基本注解,以下代码是我测试一个复杂的消息驱动代码的测试逻辑。
/**
* Created by jinglongjun on 16/1/25.
*/
public class TradeStatusChangeListenerTest extends TestCase {
@Mock
MergeSplitService mergeSplitService;
@Mock
TradeSearchService tradeSearchService;
@Mock
ITradeService tradeService;
@Mock
ITbTradeDao tbTradeDao;
@Mock
ISolrUpdateService solrUpdateService;
@Mock
PlatformTransactionManager txManager;
@Spy
TradeStatusChangeListener tcl;
private User user;
private TbTrade tbTrade;
private List<TbTrade> result = new ArrayList<TbTrade>();
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
tcl.tradeSearchService = this.tradeSearchService;
tcl.tradeService = this.tradeService;
user = new User().setTaobaoId(1L);
tbTrade = new TbTrade().setSysTid(1111L).setMergeSplitType(TbTrade.SPLIT_TYPE_AUTO_MERGE);
result.add(tbTrade);
}
//测试退款关闭
@Test
public void testStatuschange() {
EventSourceBase source = new CommonEventSource(new Object(), "12", "trade.close.statuschange",
new Object[]{user}, result, "asdasd");
tcl.onObserved(source);
Mockito.verify(tradeSearchService, Mockito.atLeastOnce()).queryBySysTid(user, tbTrade.getSysTid(), true);
}
}
* Created by jinglongjun on 16/1/25.
*/
public class TradeStatusChangeListenerTest extends TestCase {
@Mock
MergeSplitService mergeSplitService;
@Mock
TradeSearchService tradeSearchService;
@Mock
ITradeService tradeService;
@Mock
ITbTradeDao tbTradeDao;
@Mock
ISolrUpdateService solrUpdateService;
@Mock
PlatformTransactionManager txManager;
@Spy
TradeStatusChangeListener tcl;
private User user;
private TbTrade tbTrade;
private List<TbTrade> result = new ArrayList<TbTrade>();
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
tcl.tradeSearchService = this.tradeSearchService;
tcl.tradeService = this.tradeService;
user = new User().setTaobaoId(1L);
tbTrade = new TbTrade().setSysTid(1111L).setMergeSplitType(TbTrade.SPLIT_TYPE_AUTO_MERGE);
result.add(tbTrade);
}
//测试退款关闭
@Test
public void testStatuschange() {
EventSourceBase source = new CommonEventSource(new Object(), "12", "trade.close.statuschange",
new Object[]{user}, result, "asdasd");
tcl.onObserved(source);
Mockito.verify(tradeSearchService, Mockito.atLeastOnce()).queryBySysTid(user, tbTrade.getSysTid(), true);
}
}
最后
以上就是忧虑鞋子为你收集整理的Mockito注解基本例子的全部内容,希望文章能够帮你解决Mockito注解基本例子所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复