Skip to content

[java] UnnecessaryBooleanAssertion overlaps with SimplifiableTestAssertion #3087

@testation21

Description

@testation21

Affects PMD Version: 6.30

Rule: UnnecessaryBooleanAssertion
https://pmd.github.io/pmd-6.30.0/pmd_rules_java_errorprone.html#unnecessarybooleanassertion

Description: There is a problem when the boolean value is used with ! after a function call to test the function.
Please, check this case.

Thank you.

Code Sample demonstrating the issue:

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

class TestUnnecessaryBooleanAssertion {
        @Test
        public void testPMD(){
                test(foo);
        }

        protected void test(Foo foo) {
                boolean testResult = testFunction(foo);

                assertTrue(!testResult);    //an alarm is generated
                assertTrue(testResult);    //an alarm isn't generated
    }
}

Expected outcome:
Don't show any alarms.

Running PMD through: [CLI]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions