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 example doesThrow instead.
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,
throwsis a reserved keyword in Java, so that would have to become for exampledoesThrowinstead.