java runtime_error ai_generated true

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 0 matchers expected, 1 recorded

ID: java/mockito-wrong-type-argument

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-06-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8+ active

Root Cause

Mixing matchers and exact values in same method call, or using matchers outside of when/verify.

generic

中文

在同一方法调用中混合使用匹配器和精确值,或在 when/verify 之外使用匹配器。

Workarounds

  1. 95% success Use matchers for all parameters consistently
    when(mock.method(anyString(), anyInt())).thenReturn(value);
  2. 90% success Use eq() for exact values with matchers
    when(mock.method(eq("exact"), anyInt())).thenReturn(value);

Dead Ends

Common approaches that don't work:

  1. Using any() for all parameters 50% fail

    May cause UnnecessaryStubbingException if not all used.

  2. Removing matchers and using exact values only 40% fail

    Reduces test flexibility; may not match actual calls.