Invalid use of arguments

The following is a simple example of an error test.

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 3 matchers expected, 2 recorded:

I'm not sure what is wrong.

 @Test public void testGetStringTest(){ final long testId = 1; String dlrBAC = null; NamedParameterJdbcTemplate jdbcTemplate = mock(NamedParameterJdbcTemplate.class); when(this.dao.getNamedParameterJdbcTemplate()).thenReturn(jdbcTemplate); when(jdbcTemplate.queryForObject(anyString(), any(SqlParameterSource.class), String.class )).thenReturn("Test"); dlrBAC = dao.getStringTest(testId); assertNotNull(dlrBAC); } 
+6
source share
1 answer

Mockito requires that you use only raw values ​​or only matches when making a method call. The full exception (not posted by you here) certainly explains everything.

Simple line change:

 when(jdbcTemplate.queryForObject(anyString(), any(SqlParameterSource.class), String.class )).thenReturn("Test"); 

to

 when(jdbcTemplate.queryForObject(anyString(), any(SqlParameterSource.class), eq(String.class) )).thenReturn("Test"); 

and it should work.

+17
source

Source: https://habr.com/ru/post/971465/


All Articles