Mocking SqlRowSet

1.5k Views Asked by At

Hey guys I have a question about SqlRowSet in junit testing. Does anyone have examples or ways to mock an SqlRowSet. To add fake values to it and using it to test your method? I know I am being a little vague here but I have never worked with an SqlRowSet till now so it is confusing to me. Thank you!

1

There are 1 best solutions below

0
Veeresham Tammali On

There are many frameworks for mocking the real objects for example Mockito, PowerMockito. Below snippet is written in Mockito. Update the test case as per your requirements.

@Test
    public void testSqlRowSet() {
        SqlRowSet sqlRowSet = Mockito.mock(SqlRowSet.class);
        JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);
        Mockito.when(jdbcTemplate.queryForRowSet(Mockito.anyString(), Mockito.eq(Integer.class))).thenReturn(sqlRowSet);//Change the method parameters accordingly
        Mockito.when(sqlRowSet.next()).thenReturn(true);
    }