首页 > 解决方案 > 如何在单元测试中使用准备好的语句模拟 jdbctemplate

问题描述

嗨,我正在尝试在我的 mockito 单元测试用例中模拟以下代码,有人可以就如何模拟它提出可能的解决方案。谢谢

String prasobhName = 
        jdbcTemplate.query(
           "select first_name from customer where last_name like ?",
            new PreparedStatementSetter() {
              public void setValues(PreparedStatement preparedStatement) throws
                SQLException {
                  preparedStatement.setString(1, "nair%");
              }
            }, 
            new ResultSetExtractor<Long>() {
              public Long extractData(ResultSet resultSet) throws SQLException,
                DataAccessException {
                  if (resultSet.next()) {
                      return resultSet.getLong(1);
                  }
                  return null;
              }
            }
        );

标签: javajunitmockito

解决方案


推荐阅读