Class ExceptionMatchers
java.lang.Object
com._4point.testing.matchers.javalang.ExceptionMatchers
Matchers used for testing `java.lang.Exception`s (and its subclasses).
Based on https://www.planetgeek.ch/2012/03/07/create-your-own-matcher/
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.hamcrest.Matcher<Throwable> exceptionMsgContainsAll(String firstExpectedString, String... expectedStrings) Matcher that validates that an exception's message contains all the expected strings.static org.hamcrest.Matcher<Throwable> Matcher that validates the cause of an exception is the cause exception provided.static org.hamcrest.Matcher<Throwable> hasCauseMatching(org.hamcrest.Matcher<Throwable> matcher, org.hamcrest.Matcher<Throwable>... matchers) Matcher that validates the cause of an exception matches all the matchers provided.
-
Method Details
-
exceptionMsgContainsAll
public static org.hamcrest.Matcher<Throwable> exceptionMsgContainsAll(String firstExpectedString, String... expectedStrings) Matcher that validates that an exception's message contains all the expected strings. At least one string must be specified.- Parameters:
firstExpectedString- string that is expected to be in the messageexpectedStrings- additional strings that are expected to be in the message- Returns:
- the matcher
-
hasCause
Matcher that validates the cause of an exception is the cause exception provided. The provided cause exception must be the same instance as cause in the exception being tested.- Parameters:
throwable- the expected cause exception- Returns:
- the matcher
-
hasCauseMatching
@SafeVarargs public static org.hamcrest.Matcher<Throwable> hasCauseMatching(org.hamcrest.Matcher<Throwable> matcher, org.hamcrest.Matcher<Throwable>... matchers) Matcher that validates the cause of an exception matches all the matchers provided.- Parameters:
matcher- matcher to test the exceptions causematchers- additional matchers to test the exceptions cause- Returns:
- the matcher
-