Skip to content

[java] JUnitAssertionsShouldIncludeMessage false positive with AssertJ #1565

@golszewski86

Description

@golszewski86

Affects PMD Version: 6.10.0

Rule: JUnitAssertionsShouldIncludeMessage

Description: PMD reports "JUnit assertions should include a message" for AssertJ assertions with message. AssertJ assertions are described in a different way than JUnit or Hamcrest assertions, e.g.

assertThat(actual).as("Assertion message").isEqualTo(expected);

See: http://joel-costigliola.github.io/assertj/assertj-core-features-highlight.html#describe-assertion

Code Sample demonstrating the issue:

    @Test
    public void shouldMapResult() throws SQLException {
        new JdbcSession(this.database.dataSource()).sql(
            "insert into test values (1, 2), (2, 3), (3, 4)"
        ).update(Outcome.VOID);
        assertThat(
            new JdbcSession(this.database.dataSource()).sql("select * from test")
                .select(new MapOutcome<>(rset -> rset.getInt(1), rset -> rset.getInt(2)))
        ).as("Should return database entries as map")
            .hasSize(3)
            .containsEntry(1, 2)
            .containsEntry(2, 3)
            .containsEntry(3, 4);
    }

Running PMD through: Maven

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