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

Allow JUnit ClassRule to be public #2987

Closed
avano opened this issue Feb 29, 2016 · 1 comment
Closed

Allow JUnit ClassRule to be public #2987

avano opened this issue Feb 29, 2016 · 1 comment

Comments

@avano
Copy link
Contributor

avano commented Feb 29, 2016

The JUnit ClassRule should be treated the same way as JUnit Rule, as must should be declared public.

Currently only @rule is ignored from the check and latest version complains about:
Variable 'myClassRule' must be private and have accessor methods. [VisibilityModifier]

Class:

/tmp/checkstyle :: cat Example.java
public class Class {
@org.junit.Rule
public Rule rule = new Rule();

@org.junit.ClassRule
public static Rule classRule = new ClassRule();
}

XML:

/tmp/checkstyle :: cat checkstyle.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="TreeWalker">
    <module name="VisibilityModifier"/>
</module>

Outcome:

/tmp/checkstyle :: java -jar checkstyle-6.16-all.jar -c checkstyle.xml Example.java
Starting audit...
[ERROR] /tmp/checkstyle/Example.java:6:28: Variable 'classRule' must be private and have accessor methods. [VisibilityModifier]
Audit done.
Checkstyle ends with 1 errors.

JUnit rule is in the 'whitelist' in VisibilityModifierCheck class:

/** Default ignore annotations canonical names. */
private static final List<String> DEFAULT_IGNORE_ANNOTATIONS = ImmutableList.of(
    "org.junit.Rule",
    "com.google.common.annotations.VisibleForTesting"
);

but the ClassRule is not, even if it's the same principle.

avano added a commit to avano/checkstyle that referenced this issue Feb 29, 2016
avano added a commit to avano/checkstyle that referenced this issue Feb 29, 2016
avano added a commit to avano/checkstyle that referenced this issue Feb 29, 2016
avano added a commit to avano/checkstyle that referenced this issue Feb 29, 2016
@romani romani added the approved label Mar 1, 2016
@romani romani added the bug label Mar 1, 2016
@romani romani added this to the 6.17 milestone Mar 1, 2016
@romani
Copy link
Member

romani commented Mar 1, 2016

fix is merged,
thank a lot for full update (code + documentation).

@romani romani closed this as completed Mar 1, 2016
@romani romani modified the milestones: 6.16.1, 6.17 Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants