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

Invalid refactor to assertThatThrownBy when returning exception

Open fawind opened this issue 10 months ago • 0 comments

What happened?

assertj-automation would try to convert org.junit.jupiter.api.Assertions.assertThrows to an assertThatThrownBy assertion when the return value of assertThrows is used:

MyException e = assertThatThrownBy(() -> throwingMethod()).isInstanceOf(MyException.class);

However assertThatThrownBy does not return the exception.

What did you want to happen?

Maybe use catchThrowableOfType instead when the returned exception is used in follow-up code. Arguably, it could also be a hint to refactor the test code to do follow up assertions on the exception with chained methods on the assertThatThrownBy clause.

fawind avatar Apr 10 '24 16:04 fawind