@Test
@DisplayName("Success scenario for Card Replace for Lost")
void testcardReplaceLostSuccess() throws Exception {
final CardReplaceRqst cardReplaceRqst = mockCardReplaceRequest("Lost");
when(cardBlockService.sendBlockRequest(cardReplaceRqst)).thenReturn(new ResponseEntity<>(any(), HttpStatus.OK));
when(cardReplaceService.replaceCard(ArgumentMatchers.eq(cardReplaceRqst), any(CardType.class)))
.thenReturn(mockCardReplaceResponse());
mockMvc
.perform(MockMvcRequestBuilders.post(REPLACE_REQUEST_URL).contentType(MediaType.APPLICATION_JSON_VALUE)
.content(TestUtils.toJson(cardReplaceRqst)).characterEncoding("utf-8"))
.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$.successCode").value("Success"));
}
When I run this code, I get the below error.
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers, 2 matchers expected: 3 recorded
Any suggestions?
ps I had to add ArgumentMatcher.eq() because of a sonar rule "Add an "eq()" argument matcher on this parameter."
Using any()
in the response thenReturn(new ResponseEntity<>(any(), HttpStatus.OK));
is illegal and causes a mess with subsequent stubbing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.