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

Inspection: Report and convert MockSettings based mock creations to their simpler variants #58

Closed
picimako opened this issue Jul 12, 2023 · 1 comment
Assignees
Labels
feature New functionality
Milestone

Comments

@picimako
Copy link
Owner

picimako commented Jul 12, 2023

Summary

The javadoc of some methods in org.mockito.MockSettings states that they have simpler versions of creating and configuring the mock:

  • spiedInstance
    Foo foo = spy(fooInstance);
    //does exactly the same as:
    Foo foo = mock(Foo.class, withSettings().spiedInstance(fooInstance));
  • name
    Foo foo = mock(Foo.class, "foo");
    //does exactly the same as:
    Foo foo = mock(Foo.class, withSettings().name("foo"));
  • defaultAnswer
    Foo mockTwo = mock(Foo.class, new YourOwnAnswer());
    //does exactly the same as:
    Foo mockTwo = mock(Foo.class, withSettings().defaultAnswer(new YourOwnAnswer()));

Tasks

  • Create an inspection that can report the withSettings() based mock creation.
  • Provide a quick fix to convert them to their simpler variants.
@picimako picimako added the feature New functionality label Jul 12, 2023
@picimako picimako self-assigned this Jul 12, 2023
@picimako picimako added this to the v0.11.0 milestone Jul 13, 2023
@picimako picimako changed the title Inspection: Report and convert MockSettings.spiedInstance() based spies to Mock.spy() Inspection: Report and convert MockSettings based mock creations to their simpler variants Jul 14, 2023
@picimako
Copy link
Owner Author

Completed in v0.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality
Projects
None yet
Development

No branches or pull requests

1 participant