35 lines
2.2 KiB
Plaintext
35 lines
2.2 KiB
Plaintext
-------------------------------------------------------------------------------
|
|
Test set: com.example.service.unit_testing.QuickReplyContentServiceTest
|
|
-------------------------------------------------------------------------------
|
|
Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.583 s <<< FAILURE! -- in com.example.service.unit_testing.QuickReplyContentServiceTest
|
|
com.example.service.unit_testing.QuickReplyContentServiceTest.getQuickReplies_success -- Time elapsed: 0.122 s <<< ERROR!
|
|
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
|
|
|
|
Misplaced or misused argument matcher detected here:
|
|
|
|
-> at com.example.service.unit_testing.GeminiClientServiceTest.generateContent_whenApiResponseIsNull_throwsGeminiClientException(GeminiClientServiceTest .java:72)
|
|
-> at com.example.service.unit_testing.GeminiClientServiceTest.generateContent_whenApiResponseIsNull_throwsGeminiClientException(GeminiClientServiceTest .java:72)
|
|
-> at com.example.service.unit_testing.GeminiClientServiceTest.generateContent_whenApiResponseIsNull_throwsGeminiClientException(GeminiClientServiceTest .java:72)
|
|
|
|
You cannot use argument matchers outside of verification or stubbing.
|
|
Examples of correct usage of argument matchers:
|
|
when(mock.get(anyInt())).thenReturn(null);
|
|
doThrow(new RuntimeException()).when(mock).someVoidMethod(any());
|
|
verify(mock).someMethod(contains("foo"))
|
|
|
|
This message may appear after an NullPointerException if the last matcher is returning an object
|
|
like any() but the stubbed method signature expect a primitive argument, in this case,
|
|
use primitive alternatives.
|
|
when(mock.get(any())); // bad use, will raise NPE
|
|
when(mock.get(anyInt())); // correct usage use
|
|
|
|
Also, this error might show up because you use argument matchers with methods that cannot be mocked.
|
|
Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
|
|
Mocking methods declared on non-public parent classes is not supported.
|
|
|
|
at com.example.service.unit_testing.QuickReplyContentServiceTest.setUp(QuickReplyContentServiceTest.java:49)
|
|
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
|
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
|
|
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
|
|
|