Open
Description
Unfortunately, mockito cannot catch a bug like this during runtime:
when(a.m1(x: argThat(contains('foo'), 'y'), y: argThat(contains('bar'), 'x')))
.thenReturn(0);
noSuchMethod receives an arg (null) for x
, and an argument matcher for x
(contains('foo')
), and an arg (null) for y
, and an argument matcher for y
(contains('bar')
), so it thinks everything is kosher.
In addition, mockito does detect that the following are bugs, and reports them, but it would be much more helpful if the user's IDE reported the bug earlier:
// `any` should be `anyNamed('x')`.
when(a.m1(x: any)).thenReturn(0);
// `anyNamed('y')` should be `anyNamed('x')`.
when(a.m1(x: anyNamed('y'))).thenReturn(0);
// `anyNamed('x')` should be `any`.
when(a.m1(anyNamed('x'))).thenReturn(0);
// `argThat(equals(7))` should be `argThat(equals(7), named: 'x')`.
when(a.m1(x: argThat(equals(7))).thenReturn(0);
// `captureAny` should be `captureAnyNamed('x')`.
verify(a.m1(x: captureAny));