Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid refactor to assertThatThrownBy when returning exception #633

Open
fawind opened this issue Apr 10, 2024 · 0 comments
Open

Invalid refactor to assertThatThrownBy when returning exception #633

fawind opened this issue Apr 10, 2024 · 0 comments

Comments

@fawind
Copy link
Contributor

fawind commented Apr 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant