簡體   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"));
}

當我運行此代碼時,出現以下錯誤。

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 

參數匹配器的使用無效,預期 2 個匹配器:已記錄 3 個

有什么建議么?

ps 我不得不添加 ArgumentMatcher.eq() 因為聲納規則“在這個參數上添加一個“eq()”參數匹配器。”

在響應中使用any() thenReturn(new ResponseEntity<>(any(), HttpStatus.OK)); 是非法的,並導致后續存根混亂

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM