使用mockito模拟数据库连接

时间:2017-10-10 18:59:12

标签: junit mockito ibatis

public List<Prisma> getProductCharacteristics(ResultSetLoadHandler<Prisma> rsLoadHandler, SqlSession sqlSession) throws Exception {
    List<Prisma> ptos = null;
    try {
        sqlSession.select("Product.getProductInformation", params, rsLoadHandler);
        ptos = rsLoadHandler.getResults();
    } catch (Exception e) {
        throw e;
    }
    return ptos;
}

我正在尝试模拟选择方法

Mockito.doAnswer(new Answer() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
        return rsLoadHandler;
    }
}).when(sqlSession).select(rsLoadHandler, sqlSession);

但无法在 mockito 框架中模拟sqlSession.select(String statement, Object parameter, ResultHandler handler);

获得此问题:

  

org.springframework.jdbc.CannotGetJdbcConnectionException:无法   获取JDBC连接;嵌套异常是   org.apache.commons.dbcp.SQLNestedException:无法创建   PoolableConnectionFactory(ORA-28000:帐户被锁定)

我正在使用 ibatis 数据库,我需要模拟db调用 我不应该点击数据库并返回列表大小大于零。

0 个答案:

没有答案