Reputation: 1
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!
Upvotes: 0
Views: 1758
Reputation: 436
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);
}
Upvotes: 1