I’m trying to write a unit test and I can’t seem to figure out how to write a Mockito matcher for Integer.class.
I’m trying to test the following method:
public List<Integer> getAllParticipatingChallengesByTeamId(int teamId) {
List<Integer> challengeIds = new ArrayList<Integer>();
MapSqlParameterSource args = new MapSqlParameterSource();
args.addValue("teamId", teamId);
try {
challengeIds = jdbcTemplate.queryForList(SQL_STRING, args, Integer.class);
} catch (Exception e) {
challengeIds = null;
}
return challengeIds;
}
by stubbing my mocked jdbcTemplate to return a value using matchers like this:
when(mockJdbc.queryForList(anyString(), any(SqlParameterSource.class), any(Integer.class)).thenReturn(integerList);
But of course that matches any Integer, not any class! I tried Class.class, and such, but I couldn’t seem to figure it out online or through my own means.
Use
eq(Integer.class)which is the equality matcher in Mockito