javamockitojmockjmockitspringmockito

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.


Solution

  • 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);