-
Notifications
You must be signed in to change notification settings - Fork 750
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
Exclude inner classes annotated with @Nested from ClassCanBeStatic rule #956
Comments
Sadness :( |
Hi. Is there any chance this issue is going to be fixed? With the latest update, this now is also relevant to some production code. For example, I have a number of The same applies to the JUnit 5 factory methods. Those are not annotated with any kind of a special annotation. Instead, they are referenced by the name from method annotations in the same class. |
This problem still exists [UnusedMethod] Private method 'errorEnumsProvider' which returns Stream is never used. For @ParameterizedTest |
Exclude inner classes annotated with JUnit's `@Nested` annotation from the `ClassCanBeStatic` check. JUnit requires them to not be `static`. From the [JUnit docs](https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested): > Only non-static nested classes (i.e. inner classes) can serve as `@Nested` test classes. Fixes #956. Fixes #3654 FUTURE_COPYBARA_INTEGRATE_REVIEW=#3654 from ljrmorgan:junit_nested_test_classes_cannot_be_static 3a5bd67 PiperOrigin-RevId: 503544057
Please answer these questions before submitting your issue. Thanks!
What version of Error Prone are you using?
2.2.0 (with maven.plugin 2.8.2)
Does this issue reproduce with the latest release?
Yes
What did you do?
JUnit 5 provides nested tests using an inner class (not static): See Example at https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested
If I use the rule ClassCanBeStatic on all my classes, then all those tests are flagged.
What did you expect to see?
An inner class with the annotation
@org.junit.jupiter.api.Nested
should not be flagged as warning.What did you see instead?
[WARNING] /Users/hafner/Development/jenkins/workspace/Pipeline/src/test/java/edu/hm/hafner/analysis/parser/dry/CodeDuplicationTest.java:[64,5] [ClassCanBeStatic] Inner class is non-static but does not reference enclosing class
The text was updated successfully, but these errors were encountered: