Unlike similar AssertJ methods testing exceptions (
assertThatExceptionOfType(), …), the
assertThatThrownBy() method can be used alone, failing if the code did not raise any exception.
Still, only testing that an exception was raised is not enough to guarantee that it was the expected one, and you should test the exception type or
content further. In addition, it will make explicit what you are expecting, without relying on side-effects.
This rule raises an issue when
assertThatThrownBy is used, without testing the exception further.
Noncompliant Code Example
assertThatThrownBy(() -> shouldThrow()); // Noncompliant, is it really the exception you expected?
assertThatThrownBy(() -> shouldThrow()).isInstanceOf(IOException.class);
assertThatThrownBy(() -> shouldThrow()).hasMessage("My exception");