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

Add isNotThrownBy() method as opposite to isThrownBy() #3378

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Feb 26, 2024

It can be used like:

    assertThatExceptionOfType(IllegalArgumentException.class).isNotThrownBy(() -> {
      // no exception
    });

    assertThatExceptionOfType(IllegalArgumentException.class).isNotThrownBy(() -> {
      throw new IllegalStateException();
    });

Check List:

  • Unit tests : YES
  • Javadoc with a code example (on API only) : YES

It can be used like:
```
    assertThatExceptionOfType(IllegalArgumentException.class).isNotThrownBy(() -> {
      // no exception
    });

    assertThatExceptionOfType(IllegalArgumentException.class).isNotThrownBy(() -> {
      throw new IllegalStateException();
    });
```

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@quaff
Copy link
Contributor Author

quaff commented Feb 27, 2024

Do I need create a separate issue before submit PR? @scordio

@scordio
Copy link
Member

scordio commented Feb 27, 2024

No, that's ok @quaff, and thanks a lot for the proposal!

Your intention is clear. I would like to double-check the user experience in case of errors, i.e., when the code doesn't throw anything vs. when the code throws the exception that shouldn't be thrown.

Would you have time to try these two cases and post the results here? It would help us get on board faster 🙂

@quaff
Copy link
Contributor Author

quaff commented Feb 28, 2024

Your intention is clear. I would like to double-check the user experience in case of errors, i.e., when the code doesn't throw anything vs. when the code throws the exception that shouldn't be thrown.

Would you have time to try these two cases and post the results here? It would help us get on board faster 🙂

If I understand correctly, the test case should cover that, the assertion will success if the code doesn't throw anything or throws the exception that shouldn't be thrown.

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

Successfully merging this pull request may close these issues.

None yet

2 participants