Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback);_Java_Spring_Spring Boot_Mockito_Jdbctemplate - Fatal编程技术网

Java 如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback);

Java 如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback);,java,spring,spring-boot,mockito,jdbctemplate,Java,Spring,Spring Boot,Mockito,Jdbctemplate,我试图模仿(Spring boot、JUnit、Oracle) 我得到以下编译时异常: The method execute(PreparedStatementCreator, PreparedStatementCallback<Object>) is ambiguous for the type 如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback)。如何使其工作?方法jdbcTe

我试图模仿(Spring boot、JUnit、Oracle)

我得到以下编译时异常:

The method execute(PreparedStatementCreator, PreparedStatementCallback<Object>) is ambiguous for the type 

如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback)。如何使其工作?

方法
jdbcTemplate.execute()

因此,当您使用matcher
any()
模拟它时,编译器根本不知道您实际指的是哪个方法,并抛出一个错误

要修复此问题,请在matcher中提供一个类来解决此歧义

例如,如果您想要模拟

JdbcTemplate.execute(PreparedStatementCreator psc,PreparedStatementCallback操作)
使用

doThrow(securityDAOException).when(jdbcTemplate).execute(any(PreparedStatementCreator.class)、any(PreparedStatementCallback.class));

方法
JdbcTemplate.execute()

因此,当您使用matcher
any()
模拟它时,编译器根本不知道您实际指的是哪个方法,并抛出一个错误

要修复此问题,请在matcher中提供一个类来解决此歧义

例如,如果您想要模拟

JdbcTemplate.execute(PreparedStatementCreator psc,PreparedStatementCallback操作)
使用

doThrow(securityDAOException).when(jdbcTemplate).execute(any(PreparedStatementCreator.class)、any(PreparedStatementCallback.class));

谢谢@Pavel。我可以通过添加doThrow(dataAccessException).when(jdbcTemplate).execute(any(CallableStatementCreator.class)、any(CallableStatementCallback.class))使其工作;谢谢你,帕维尔。我可以通过添加doThrow(dataAccessException).when(jdbcTemplate).execute(any(CallableStatementCreator.class)、any(CallableStatementCallback.class))使其工作;
The method execute(PreparedStatementCreator, PreparedStatementCallback<Object>) is ambiguous for the type 
doThrow(securityDAOException).when(jdbcTemplate).execute(any(), any());