FP for S6103 when using helper methods for assertions

If calling a static method in another class to create the consumer with the assertions the rule seems to fail to find them.

  • versions used 9.3.0
class ExampleTest {
	@Test
	void test6103() throws Exception {
		assertThatThrownBy(() -> {
			throw new IllegalArgumentException("Message");
		}).isInstanceOfSatisfying(IllegalArgumentException.class, hasMessage("Message"));  //No violation
	}

	@Test
	void test6103Outside() throws Exception {
		assertThatThrownBy(() -> {
			throw new IllegalArgumentException("Message");
		}).isInstanceOfSatisfying(IllegalArgumentException.class, IllegalArgumentExceptionAssertion.hasMessage("Message")); //FP?
	}

	public static Consumer<IllegalArgumentException> hasMessage(String message) {
		return e -> {
			AssertionsForClassTypes.assertThat(e.getMessage()).isEqualTo(message);
		};
	}
}

Where IllegalArgumentExceptionAssertion is a class containing the exact same static method “hasMessage”.

1 Like

Hello @fassen,

There are known limitations in some of our rules that prevent them from checking the code declared in other files.

Just to be sure that we are not missing anything: Do you still have the issue if you import hasMessage statically from IllegalArgumentExceptionAssertion?

Hi!

Having a static import of “hasMessage” unfortunately made no difference.

Thanks for reporting the issue, a ticket has been created to get rid of this type of FP.

Thanks Dorian!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.