The simple test case below is failing with an exception.
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 3 matchers expected, 2 recorded:
I am 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); }
Mockito Argument Matcher - eq() When we use argument matchers, then all the arguments should use matchers. If we want to use a specific value for an argument, then we can use eq() method. when(mockFoo. bool(eq("false"), anyInt(), any(Object. class))).
Mockito requires you to either use only raw values or only matchers when stubbing a method call. The full exception (not posted by you here) surely explains everything.
Simple change the line:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With