我正在尝试模拟(Spring boot、JUnit、Oracle)
jdbcTemplate.execute(CallableStatementCreator, CallableStatementCallback);
public class ExceptionTest
{
@Autowired
private SecurityDAOImpl securityDAOImplMock;
@Mock
private JdbcTemplate jdbcTemplate;
@Autowired
private JdbcTemplate resetJdbcTemplate;
@Before
public void init() throws Exception
{
securityDAOImplMock = spy(new SecurityDAOImpl());
MockitoAnnotations.initMocks(this);
}
@SuppressWarnings("unchecked")
@Test(expected = SecurityDAOException.class)
public void testUpdateProfileException()
{
DataAccessException dataAccessException = new DataAccessException("Mock Exception",
new Exception("Mocked DataAccessException"))
{
private static final long serialVersionUID = 1L;
};
ReflectionTestUtils.setField(securityDAOImplMock, "jdbcTemplate", jdbcTemplate);
doThrow(dataAccessException).when(jdbcTemplate).execute(any(), any());
securityDAOImplMock.isTooManyFailedAttempt("", 7, "", "");
}
@After
public void reset()
{
ReflectionTestUtils.setField(securityDAOImplMock, "jdbcTemplate", resetJdbcTemplate);
}
}
我收到以下编译时异常:
The method execute(PreparedStatementCreator, PreparedStatementCallback<Object>) is ambiguous for the type
在这条线上
doThrow(securityDAOException).when(jdbcTemplate).execute(any(), any());
如何模拟 jdbcTemplate.execute(callableStatementCreator, callableStatementCallback)。如何让它工作?
慕斯王
相关分类