Java 如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback);
我试图模仿(Spring boot、JUnit、Oracle) 我得到以下编译时异常: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
The method execute(PreparedStatementCreator, PreparedStatementCallback<Object>) is ambiguous for the type
如何模拟jdbcTemplate.execute(callableStatementCreator,callableStatementCallback)。如何使其工作?方法
jdbcTemplate.execute()
是
因此,当您使用matcherany()
模拟它时,编译器根本不知道您实际指的是哪个方法,并抛出一个错误
要修复此问题,请在matcher中提供一个类来解决此歧义
例如,如果您想要模拟
JdbcTemplate.execute(PreparedStatementCreator psc,PreparedStatementCallback操作)
使用
doThrow(securityDAOException).when(jdbcTemplate).execute(any(PreparedStatementCreator.class)、any(PreparedStatementCallback.class));
方法JdbcTemplate.execute()
是
因此,当您使用matcherany()
模拟它时,编译器根本不知道您实际指的是哪个方法,并抛出一个错误
要修复此问题,请在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());