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

[java] CommentDefaultAccessModifier - False Positive with JUnit5's ParameterizedTest #4645

Closed
koalalam opened this issue Aug 15, 2023 · 3 comments · Fixed by #4705
Closed
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@koalalam
Copy link

koalalam commented Aug 15, 2023

Affects PMD Version: 6.55.0, 7.0.0-rc4

Rule: CommentDefaultAccessModifier

Description:

Package defined in ignoredAnnotations is not correct.

Should: org.junit.jupiter.params.ParameterizedTest
But: org.junit.jupiter.api.ParameterizedTest

@koalalam koalalam added the a:false-positive PMD flags a piece of code that is not problematic label Aug 15, 2023
@oowekyala
Copy link
Member

@oowekyala oowekyala added this to the 7.0.0 milestone Aug 16, 2023
@koalalam
Copy link
Author

koalalam commented Oct 3, 2023

Hi @oowekyala ,

To clarify:

  1. org.junit.jupiter.params.ParameterizedTest is not listed on the doc page
  2. Is this the implementation in v7? https://github.com/pmd/pmd/blob/pmd_releases/7.0.0-rc4/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/CommentDefaultAccessModifierRule.java#L57
    private static final PropertyDescriptor<List<String>> IGNORED_ANNOTS =
        JavaPropertyUtil.ignoredAnnotationsDescriptor(
            "com.google.common.annotations.VisibleForTesting",
            "android.support.annotation.VisibleForTesting",
            "co.elastic.clients.util.VisibleForTesting",
            "org.junit.jupiter.api.Test",
            "org.junit.jupiter.api.extension.RegisterExtension",
            "org.junit.jupiter.api.ParameterizedTest",  // "org.junit.jupiter.params.ParameterizedTest" is not there

@adangel adangel changed the title False Positive - CommentDefaultAccessModifier with JUnit5's ParameterizedTest [java] CommentDefaultAccessModifier - False Positive with JUnit5's ParameterizedTest Oct 5, 2023
@adangel
Copy link
Member

adangel commented Oct 5, 2023

You are right, the annotation is wrong, it is in the package org.junit.jupiter.params and not in org.junit.jupiter.api: https://junit.org/junit5/docs/current/api/org.junit.jupiter.params/org/junit/jupiter/params/ParameterizedTest.html

The rule CommentDefaultAccessModifier seems to be the only one, that uses the wrong package - other rules, that mention this annotation are correct.

When fixing this, also the test case needs to be fixed:

Note: If you don't want to wait for a new PMD release, you can simply configure the rule yourself, see https://docs.pmd-code.org/latest/pmd_userdocs_configuring_rules.html

In this special case, you can use:

<rule ref="category/java/codestyle.xml/CommentDefaultAccessModifier">
    <properties>
        <property name="ignoredAnnotations" value="android.support.annotation.VisibleForTesting,co.elastic.clients.util.VisibleForTesting,com.google.common.annotations.VisibleForTesting,org.junit.jupiter.api.AfterAll,org.junit.jupiter.api.AfterEach,org.junit.jupiter.api.BeforeAll,org.junit.jupiter.api.BeforeEach,org.junit.jupiter.params.ParameterizedTest,org.junit.jupiter.api.RepeatedTest,org.junit.jupiter.api.Test,org.junit.jupiter.api.TestFactory,org.junit.jupiter.api.TestTemplate,org.junit.jupiter.api.extension.RegisterExtension,org.testng.annotations.AfterClass,org.testng.annotations.AfterGroups,org.testng.annotations.AfterMethod,org.testng.annotations.AfterSuite,org.testng.annotations.AfterTest,org.testng.annotations.BeforeClass,org.testng.annotations.BeforeGroups,org.testng.annotations.BeforeMethod,org.testng.annotations.BeforeSuite,org.testng.annotations.BeforeTest,org.testng.annotations.Test" />
        <property name="regex" value="\/\*\s*(default|package)\s*\*\/" />
        <property name="checkTopLevelTypes" value="false" />
    </properties>
</rule>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants