How to mock JdbcTemplate.queryForObject() method
问题 My method looks like this: public class Decompile extends JdbcDaoSupport public void getRunner(){ String val = this.getJdbcTemplate().queryForObject(sql,String.class, new Object[]{1001}); } } Please suggest how I would mock this. 回答1: an EasyMock-3.0 example String sql = "select * from t1"; Object[] params = new Object[] { 1001 }; JdbcTemplate t = EasyMock.createMock(JdbcTemplate.class); EasyMock.expect( t.queryForObject(sql, String.class, params)).andReturn("res"); EasyMock.replay(t); 回答2: