Class ExceptionMatchers

java.lang.Object
com._4point.testing.matchers.javalang.ExceptionMatchers

public class ExceptionMatchers extends Object
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 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 message
      expectedStrings - additional strings that are expected to be in the message
      Returns:
      the matcher
    • hasCause

      public static org.hamcrest.Matcher<Throwable> hasCause(Throwable throwable)
      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 cause
      matchers - additional matchers to test the exceptions cause
      Returns:
      the matcher