JavaHamcrest
JavaHamcrest copied to clipboard
Implement matchers for thrown exceptions in `Runnable`
Fixes #329
This PR is inspired by @peterdemaeyer's #330, which fell through the cracks two years ago. I want to rekindle this effort to have matchers for exceptions thrown in Runnable
.
The goal of this matcher is to provide an easy way to verify that some code will throw some expected exception by wrapping it inside a Runnable that's executed safely by the matcher and tests the thrown exception with the provided matchers, as in:
assertThat(() -> SomeCode.thatThrows(), throwsException(withMessage("Boom!")));
This is my first contribution to this repo, so I expect my changes won't align with current conventions. I've tried to imitate patterns I've seen in other TypeSafeMatcher
subclasses, but I can't be sure if the result is 100% acceptable. Please point me in the right direction, and I'll apply any changes needed to merge this PR.
In this PR:
- New
throwsException
type-safe matcher forRunnable
- New
throwsExceptionEqualTo
type-safe matcher forThrowable
- New
throwsExceptionWithMessage
type-safe matcher forThrowable