assertj-automation icon indicating copy to clipboard operation
assertj-automation copied to clipboard

Prefer AssertJ does not convert exceptions returned from Junit assertThrows

Open fawind opened this issue 5 years ago • 0 comments

What happened?

If the returned Throwable of Junit's assertThrows is used for further checks, the build breaks when the "Prefer AssertJ" conversion is applied. This is because AssertJ's assertThatThrownBy does not return a Throwable.

Example from a PR:

- Throwable throwed = assertThrows(() -> foo());
- assertThat(throwed.getMessage()).contains("My error msg");

+ Throwable throwed = assertThatThrownBy(() -> foo());  // This breaks
+ assertThat(throwed.getMessage()).contains("My error msg");

fawind avatar Feb 19 '20 11:02 fawind