Skip to content

Invalid refactor to assertThatThrownBy when returning exception #633

Open
@fawind

Description

@fawind

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions