如何模拟 jdbctemplate.query() 方法? [英] How to mock jdbctemplate.query() method?

查看:48
本文介绍了如何模拟 jdbctemplate.query() 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mokito.when(jdbcTemplate.query(sql, new ParticipantMapper())).thenReturn(participantExistingList); 

我正在使用上面的代码行来模拟 jdbcTemplate 但它不起作用.有人可以帮助如何模拟 jdbcTemplate.

I am using above line of code for Mocking jdbcTemplate but its not working. Can some one will help how to mock jdbcTemplate.

推荐答案

尝试对所有 Argument 使用 ArgumentMatchers,如下所示:

Try to use ArgumentMatchers for all Arguments, like this:

Mokito.when(jdbcTemplate.query(any(String.class), any(ParticipantMapper.class)).thenReturn(participantExistingList);

根据您希望关注交互,您可以使用例如eq() 为您的 sql 字符串.有关 JavaDoc,请参阅此处.

Depending on your wish to focus the interaction, you may use e.g. eq() for your sql String. See here for JavaDoc.

这篇关于如何模拟 jdbctemplate.query() 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆