简体   繁体   English

Mockito 错误:.InvalidUseOfMatchersException:参数匹配器的使用无效

[英]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.

相关问题 org.mockito.exceptions.misusing.InvalidUseOfMatchersException:参数匹配器的无效使用 - org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers Mockito org.mockito.exceptions.misusing.InvalidUseOfMatchersException:无效使用参数匹配器! 预计有0个符合条件的记录,有1个记录: - Mockito org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 0 matchers expected, 1 recorded: mockito 测试错误无效使用参数匹配器 - mockito test error Invalid use of argument matchers org.mockito.exceptions.misusing.InvalidUseOfMatchersException:参数匹配器的无效使用! 春季靴 - org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! Spring Boot 如何修复 Mockito Invalid use of argument matchers 错误 - How to fix Mockito Invalid use of argument matchers error Java Mockito useConstructor withSettings,错误参数匹配器的无效使用 - Java Mockito useConstructor withSettings, error Invalid use of argument matchers Mockito 单元测试:参数匹配器的使用无效 - Mockito unit testing: Invalid use of argument matchers Mockito中的anyString()抛出参数匹配器的无效使用 - anyString() in mockito is throwing an invalid use of argument matchers Java Mockito 参数匹配器的无效使用 - Java Mockito Invalid use of argument matchers Mockito varargs参数匹配器的无效使用 - Mockito varargs Invalid use of argument matchers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM