Skip to content

Add checkstyle rule to ensure AssertJ assertions always check for underlying exception message #7040

Closed
@nastra

Description

@nastra

Feature Request / Improvement

We should ensure that test code asserting on exceptions should always check for the underlying exception message as shown below:

// should fail because it doesn't check for the underlying message
Assertions.assertThatThrownBy(() -> ...)
        .isInstanceOf(ValidationException.class);

// should not fail as it checks for the exception message
Assertions.assertThatThrownBy(() -> ...)
        .isInstanceOf(ValidationException.class)
        .hasMessageContaining(...);

// should fail because it doesn't check for the underlying message
Assertions.assertThatExceptionOfType(NotFoundException.class)
        .isThrownBy(() -> ...);

// should not fail as it checks for the exception message
Assertions.assertThatExceptionOfType(NotFoundException.class)
        .isThrownBy(() -> ...)
        .withMessageContaining(...);

Query engine

None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions