-
Notifications
You must be signed in to change notification settings - Fork 379
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 declarative equivalent of JUnit's assertThrows #329
Comments
The functionality I desire could really benefit from Java 1.8 lambda expressions, while Hamcrest is still on Java 1.7. |
peterdemaeyer
added a commit
to peterdemaeyer/JavaHamcrest
that referenced
this issue
Feb 21, 2021
peterdemaeyer
added a commit
to peterdemaeyer/JavaHamcrest
that referenced
this issue
Feb 21, 2021
I've prepared a fix that adds the desired functionality.
Illustration of use (using Java 1.8 lambda expressions):
|
I created a PR for my changes, but it doesn't link correctly. |
peterdemaeyer
added a commit
to peterdemaeyer/JavaHamcrest
that referenced
this issue
Feb 21, 2021
…failures with some JDKs
peterdemaeyer
added a commit
to peterdemaeyer/JavaHamcrest
that referenced
this issue
Dec 26, 2021
peterdemaeyer
added a commit
to peterdemaeyer/JavaHamcrest
that referenced
this issue
Dec 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since version 4.13, JUnit has added
assertThrows
, with typical JUnit style "expected first argument, actual second argument".Hamcrest does not have a declarative equivalent.
As a developer, I want to have a declarative equivalent of Junit's
assertThrows
, so that I can consistently use Hamcrest's declarative syntax when writing unit tests.So, given the JUnit syntax:
assertThrows(Throwable.class, () -> methodThatThrows())
I would like to be able to write something like this in Hamcrest syntax:
assertThat(() -> methodThatThrows(), throws(instanceOf(Throwable.class)));
Of course,
throws
is a reserved keyword in Java, so that would have to become for exampledoesThrow
instead.The text was updated successfully, but these errors were encountered: