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] JUnitTestsShouldIncludeAssert: Add support for Hamcrest MatcherAssert.assertThat #2288

Closed
TheBoegl opened this issue Feb 13, 2020 · 1 comment · Fixed by #2479
Closed
Labels
an:enhancement An improvement on existing features / rules
Milestone

Comments

@TheBoegl
Copy link

TheBoegl commented Feb 13, 2020

Affects PMD Version: 6.20.0
Rule: JUnitTestsShouldIncludeAssert
Description:
the MatcherAssert.assertThat is not counted as assertion rule

Code Sample demonstrating the issue:

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

class JUnitTestsShouldIncludeAssertRule {
    @Test
    void hamcrest_assert_should_pass_include_test() {
        MatcherAssert.assertThat("java/rule/bestpractices/JUnitTestsShouldIncludeAssertRule should pass for MatcherAssert.assertThat", "PMD 6.20.0", Matchers.is("PMD 6.20.0"));
    }
}

Running PMD through: Gradle 6.1.1

@adangel
Copy link
Member

adangel commented Feb 15, 2020

It makes sense, to enhance the rule to support hamcrest matchers as well. We currently support the JUnit asserts, aspectj soft asserts, Mockito calls.

In any case, we should update the rule description to clearly say, which assertion frameworks are recognized.

@adangel adangel added the an:enhancement An improvement on existing features / rules label Feb 15, 2020
@adangel adangel changed the title [java] JUnitTestsShouldIncludeAssert: MatcherAssert.assertThat false positive [java] JUnitTestsShouldIncludeAssert: Add support for Hamcrest MatcherAssert.assertThat Feb 15, 2020
andreoss added a commit to andreoss/pmd that referenced this issue May 12, 2020
@adangel adangel added the has:pr label May 14, 2020
@adangel adangel added this to the 6.24.0 milestone May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
an:enhancement An improvement on existing features / rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants