mardi 30 juin 2015

How to mock getNamedParameterJdbcTemplate()

I am trying to mock a DAO implementation class that extends NamedParameterJdbcDaoSupport

This is how my DAO interface looks like:

public interface TestDAO{

List<String> search();

}

This is how my implementation class is:

    public class TestDAOImpl extends NamedParameterJdbcDaoSupport implements TestDAO {

    public List<String> search(){

    return getNamedParameterJdbcTemplate().query(mySQLQuery,myMapSqlParameterSource, myRowMapper);
    }
}

What I am trying to achieve is that write a mock test case to mock the behaviour of the call

getNamedParameterJdbcTemplate().query(mySQLQuery,myMapSqlParameterSource, myRowMapper)

So I want to implemented something like

when(getNamedParameterJdbcTemplate().query(mySQLQuery,myMapSqlParameterSource, myRowMapper)).thenReturn(whatIWantToReturn);

I am unable to find any information on this. Can someone guide me. How to do this?

public class TestDAOImplTestCase{

    @Test
    public void testSearch(){
        when(getNamedParameterJdbcTemplate().query(mySQLQuery,myMapSqlParameterSource, myRowMapper)).thenReturn(whatIWantToReturn); 
    } 
}

Aucun commentaire:

Enregistrer un commentaire