Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer plugin rule: proper use of named argument matchers #183

Open
srawlins opened this issue Jan 8, 2019 · 0 comments
Open

Analyzer plugin rule: proper use of named argument matchers #183

srawlins opened this issue Jan 8, 2019 · 0 comments
Labels
P2 A bug or feature request we're likely to work on S2 type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

srawlins commented Jan 8, 2019

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));
@srawlins srawlins added P2 A bug or feature request we're likely to work on S2 type-enhancement A request for a change that isn't a bug labels Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on S2 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

1 participant