请帮我模拟下面的代码.Not,它能够模拟调用JdbcTemplate对象的getDataSource()。
@Override
public List<AttributeThresholdRange> getThresholdsRangeForXHS(QueryThresholdsRequest queryThresholdsRequest) {
ArrayOfString attributeGroupIds = queryThresholdsRequest.getAttributeGroupIds();
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("groupids", attributeGroupIds.getStrings());
return new NamedParameterJdbcTemplate(admDatabaseConnector.getJdbcTemplate().getDataSource())
.query(DBQueryConstants.ADM_QUERY_GET_THRESHOLDS_RANGE_FOR_XHS,
queryParams,
new ResultSetExtractor<List<AttributeThresholdRange>>() {
@Override
public List<AttributeThresholdRange> extractData(ResultSet resultSet) throws SQLException,DataAccessException {
return null;
}
});
}发布于 2017-03-08 20:45:49
你使用的是什么Mock框架?
如果您正在使用Mockito,只需模拟jdbcTemplate并将此方法放入when()子句中即可。
when(admDatabaseConnector.getJdbcTemplate().getDataSource())
.query(anyObject(), anyObject(), anyObject())).thenReturn("Your return queryobject");您必须在模拟中声明admDatabaseConnector。
https://stackoverflow.com/questions/42664509
复制相似问题