Nitish
Nitish

Reputation: 101

How to mock a jdbctemplate with rowmapper with parameters, using mockito only

Hi i need help mocking the below statement.

List<String> testString= jdbcTemplate.query(queryString, new Object[] { someStringParameter }, new testMapper());

Upvotes: 5

Views: 14140

Answers (2)

JayDee101
JayDee101

Reputation: 81

Mock JdbcTemplate method query(String, Object[], RowMapper<T>) using a RowMapper and ArgumentMatchers:

List<Model> list = new ArrayList<>();
list.add(someModel);

when(this.jdbcTemplate.query(anyString(), ArgumentMatchers.<Object[]>any(),
                ArgumentMatchers.<RowMapper<Model>>any())).thenReturn(list);

Upvotes: 7

Nitish
Nitish

Reputation: 101

Got this working using the below mock
when(jdbcTemplateMock.query(anyString(), Matchers.<Object[]> anyVararg(), Matchers.any(testMapper.class)))

Upvotes: 5

Related Questions