java
runtime_error
ai_generated
true
org.mockito.exceptions.base.MockitoException: ArgumentCaptor's capture() method was never invoked
ID: java/mockito-argumentcaptor-not-invoked
80%Fix Rate
87%Confidence
0Evidence
2024-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 8+ | active | — | — | — |
Root Cause
ArgumentCaptor used without verifying that the method was actually called with the captured argument.
generic中文
使用了 ArgumentCaptor,但未验证方法是否实际使用捕获的参数被调用。
Workarounds
-
95% success Use verify with captor
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(mock).method(captor.capture()); assertEquals("expected", captor.getValue()); -
90% success Use @Captor annotation
@Captor ArgumentCaptor<String> captor; verify(mock).method(captor.capture());
Dead Ends
Common approaches that don't work:
-
Calling captor.getValue() without verify
90% fail
Capture only happens during verification, so value is null.
-
Using captor.capture() in when() instead of verify()
70% fail
capture() is for verification, not stubbing.