-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
Version
Mockito version: 3.5.13
Description
Relates to #1932
When using a lambda or method reference expression as ArgumentMatcher and the matcher fails, the error message contains the lambda / method reference class name in "decamelized" form which is rather irritating, e.g.:
myInterface.doSomething(
<Mockito test$$ lambda$ 4 8/ 0x 0 0 0 0 0 0 0 8 0 0c 8f 4 4 0>
);
Expected would be that similar to anonymous classes the error output says "<custom argument matcher>". This could probably be achieved by testing for Class.isSynthetic() in org.mockito.internal.matchers.text.MatcherToString.toString(ArgumentMatcher<?>) before calling decamelizeMatcher there.
Test case
public class MockitoTest {
interface MyInterface {
void doSomething(String s);
}
private static boolean matches(String s) {
return false;
}
public static void main(String[] args) {
MyInterface mock = mock(MyInterface.class);
try {
verify(mock).doSomething(argThat(arg -> false));
} catch (Error e) {
e.printStackTrace();
}
try {
verify(mock).doSomething(argThat(MockitoTest::matches));
} catch (Error e) {
e.printStackTrace();
}
// When an anonymous class is used the output is '<custom argument matcher>'
// (as expected)
verify(mock).doSomething(argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(String argument) {
return false;
}
}));
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels