Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixes unchecked warnings when calling Mockito.mock(Class)#4413

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
matthieu-vergne wants to merge2 commits intojavaparser:master
base:master
Choose a base branch
Loading
frommatthieu-vergne:fix_warnings_mock

Conversation

@matthieu-vergne
Copy link
Contributor

This is an issue well known by the Mockito community, but prone to not be fixed:
mockito/mockito#1531

Generics allow to ensure type-safety at compile time instead of runtime. However, here it is used mainly to auto-cast the created object, thus avoiding this burden on the developer. Indeed, it is in a context where type safety is usually not a requirement, since the use of this method is often the most trivial we can have: provide a class and expect a very instance of this class in return.

This commit thus creates a less constrained mock method which builds on Mockito's one, but without the constraint inducing this warning.

@jlerbsc
Copy link
Collaborator

Thank you for this PR, but the problem with this fix is that once the Mockito project has taken this problem into account, we'll still have a method that's of no use. Rather than bypassing the problem in JP, it would be better to insist that the Mockito project take this problem into account.

@matthieu-vergne
Copy link
ContributorAuthor

I agree on the principle that "it would be better to insist that the Mockito project take this problem into account". But at the current state of things, it seems to be a rather speculative argument:

  • the issue is open since 2018 (6 years)
  • a core developer of Mockito clearly stated that it is prone to stay like that4 years ago
  • the issue is still open despite a strongly supported suggestion4 years ago too

In short, it looks like neither the Mockito team is willing to do it, nor any one in the open source community able to provide a satisfying solution for it after 6 years.

We could have argued that it was a niche issue having low attention, but it is not: any Mockito user faces it from the start, since mock() is a core method, used massively, and the warning comes as soon as we mock a generic class, which is rather frequent. So it is a systematic issue that still has no solution after 6 years, which is prone to support that it is a design flow that cannot be fixed easily.

I am a newbie in JavaParser, so it might be not a good comparison, but it makes me think about the LexicalPreservingPrinter and its limits in keeping the formatting also for inserted code. Even if someone "insisted" that the JavaParser project should take this problem into account, it does not look like it would solve itself.

If we discard the idea of getting anything from Mockito itself, then it comes down to what JavaParser would do. Here we speak about 100 warnings in GenericVisitorAdapterTest and 100 warnings in GenericListVisitorAdapterTest. I don't know how you managed to keep them at exactly 100 each, but good job! {^o^}

200 warnings is a lot, though. Enough to say that one or two more warnings won't change anything, which breaks the incentive to fix them at all. So it looks to me that if you don't do anything here, there is barely any point to fix any other warning, since we will remain with a lot of them anyway.

Given how trivial is your use of Mockito, I think that the proposed solution gives a rather compelling warning fix:

  • it is quick and easy and covers all the unchecked warnings in the class,
  • it still looks like we use Mockito directly, so it does not disrupt the current practices
  • if Mockito happens to fix it, it will be easy to revert this change

There is other ways to make these warnings disappear, but this compromise seems the most reasonable to me.

This is an issue well known by the Mockito community, but prone to notbefixed:mockito/mockito#1531Generics allow to ensure type-safety at compile time instead of runtime.However, here it is used mainly to auto-cast the created object, thusavoiding this burden on the developer. Indeed, it is in a context wheretype safety is usually not a requirement, since the use of this methodis often the most trivial we can have: provide a class and expect a veryinstance of this class in return.This commit thus creates a less constrained mock method which builds onMockito's one, but without the constraint inducing this warning.
@matthieu-vergne
Copy link
ContributorAuthor

By the way, if Mockito happens to fix it, it means that the@SuppressWarnings("unchecked") will be irrelevant, which will generate a warning on it. So you will quickly spot that the "unwanted" method should be fixed, then that the comment associated to it is not true anymore, and so remove it.

@codecov
Copy link

codecovbot commentedMay 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.967%. Comparing base(c3b7bdc) to head(a38936d).
Report is 3 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@##            master     #4413   +/-   ##=========================================  Coverage   51.967%   51.967%           =========================================  Files          505       505             Lines        28456     28456             Branches      4930      4930           =========================================  Hits         14788     14788             Misses       11616     11616             Partials      2052      2052
FlagCoverage Δ
AlsoSlowTests51.967% <ø> (ø)
javaparser-core51.967% <ø> (ø)
javaparser-symbol-solver51.967% <ø> (ø)
jdk-1051.953% <ø> (ø)
jdk-1151.964% <ø> (ø)
jdk-1251.953% <ø> (ø)
jdk-1351.964% <ø> (+0.007%)⬆️
jdk-1451.953% <ø> (ø)
jdk-1551.964% <ø> (+0.010%)⬆️
jdk-1651.964% <ø> (+0.010%)⬆️
jdk-1751.964% <ø> (+0.010%)⬆️
jdk-1851.953% <ø> (-0.011%)⬇️
jdk-851.952% <ø> (ø)
jdk-951.953% <ø> (+0.007%)⬆️
macos-latest51.957% <ø> (ø)
ubuntu-latest51.950% <ø> (ø)
windows-latest51.946% <ø> (ø)

Flags with carried forward coverage won't be shown.Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updatef873010...a38936d. Read thecomment docs.

@johannescoetzee
Copy link
Collaborator

Please see#4408 for a guide on how to resolve the git conflicts with the recent reformatting.

@matthieu-vergne
Copy link
ContributorAuthor

@johannescoetzee what about new PRs? Do we need to execute./mvnw spotless:apply systematically to preserve formatting?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@matthieu-vergne@jlerbsc@johannescoetzee

[8]ページ先頭

©2009-2025 Movatter.jp