java - 仅使用 Mockito 模拟新对象
问题描述
我在一个类中有这样的方法代码
public List<Auth_token> getAuthToken(String User) throws SQLException {
List<Auth_token> usersList = new ArrayList<Auth_token>();
Connection connection = null;
PreparedStatement ps = null;
ResultSet rset = null;
try {
OracleDataSource dataSource = new OracleDataSource();
dataSource.setURL("blah blah");
dataSource.setUser("blah");
//LOGGER.log(Level.INFO,"username +: "+config.getUsername());
dataSource.setPassword("blah");
Connection conn = dataSource.getConnection();
String query = "blah query";
//more code
}
我只需要使用 mockito 来模拟 oracle 数据源。我知道如何使用 power mockito,但我只能使用 mockito 来做到这一点。请帮我。
解决方案
推荐阅读
- python-3.x - 从 python 生成 Faker 数据并将其加载到 BigQuery 嵌套表中
- c - 编码/解码程序的逻辑错误 (C)
- javascript - 克隆和换行时如何防止单词溢出?
- javascript - 以角度 8 加载子组件时更改父组件高度样式
- python - 运行进程如何在python中动态重新加载新的lib文件代码?
- python - 如何计算神经网络模型中的准确率、召回率和 F1 分数?
- r - 使用 R 提取单个国家/地区的 WORLDCLIM 数据
- php - 动态访问嵌套数组中的值的更好方法
- python - python中的virtualenv:无法创建完整文件并激活不起作用
- php - 如何在 docker 容器中连接我的主机 mysql?