[英]Mockito Error :.InvalidUseOfMatchersException: Invalid use of argument matchers
@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参数匹配器的使用无效,预期 2 个匹配器:已记录 3 个
Any suggestions?有什么建议么?
ps I had to add ArgumentMatcher.eq() because of a sonar rule "Add an "eq()" argument matcher on this parameter." ps 我不得不添加 ArgumentMatcher.eq() 因为声纳规则“在这个参数上添加一个“eq()”参数匹配器。”
Using any()
in the response thenReturn(new ResponseEntity<>(any(), HttpStatus.OK));
在响应中使用
any()
thenReturn(new ResponseEntity<>(any(), HttpStatus.OK));
is illegal and causes a mess with subsequent stubbing是非法的,并导致后续存根混乱
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.