如何使用Jmockit模拟JdbcTemplate.update? [英] How to mock JdbcTemplate.update using Jmockit?
本文介绍了如何使用Jmockit模拟JdbcTemplate.update?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Jmockit的新手,我正尝试使用以下验证模拟jdbcTemplate.udpate()
,
I'm new to Jmockit and I'm trying to mock jdbcTemplate.udpate()
using the following verification,
new Expectations() {{
someRef.flushUpdates();
}};
new Verifications() {{
String query;
jdbcTemplate.update(query = withCapture(), withInstanceOf(Date.class));
times = 1;
}};
flushUpdate
具有更新查询,
public void flushUpdates(){
Date now = new Date();
String query = "Update table_name set last_updated = ? ";
jdbcTemplate.update(query,now);
}
测试旨在验证update
查询是否被触发两次.
The test is to verify if update
query is triggered twice.
但是我遇到了以下错误.
But I'm getting the following error.
mockit.internal.MissingInvocation: Missing 1 invocations to:
org.springframework.jdbc.core.JdbcTemplate#update(String, Object[])
with arguments: any String, an instance of java.util.Date
on mock instance: org.springframework.jdbc.core.JdbcTemplate@2d000e80
有人有什么主意吗?
推荐答案
mockit.internal.MissingInvocation:方法参数不匹配时,将引发缺少对1的调用:因此,当您使用"any"关键字时,在调用模拟方法时它不会寻找完全匹配的内容.
mockit.internal.MissingInvocation: Missing 1 invocations to: is thrown when your method parameters do not match. So when you use 'any' keyword it does not look for an exact match while invoking the mocked method.
@Test
public void test(){
someRef.flushUpdates();
new Verifications() {{
String query;
jdbcTemplate.update((String)any, (Date)any);
times = 1;
}};
}
这篇关于如何使用Jmockit模拟JdbcTemplate.update?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文