Class ExceptionCauseMatcher

  • All Implemented Interfaces:
    org.hamcrest.Matcher<java.lang.Throwable>, org.hamcrest.SelfDescribing

    @Immutable
    public class ExceptionCauseMatcher
    extends org.hamcrest.TypeSafeMatcher<java.lang.Throwable>
    Matchers designed to be used as an argument of ExpectedException.expectCause(Matcher) such as:
     expectedException.expect(VisitException.class);
     expectedException.expectCause(hasType(IllegalArgumentException.class).andMessage("file and otherFile Components can not be the same"));
     
    Class strongly inspired from CauseMatcher class from http://blog.codeleak.pl/2014/03/junit-expectedexception-rule-beyond.html
    • Method Detail

      • hasType

        public static ExceptionCauseMatcher hasType​(java.lang.Class<? extends java.lang.Throwable> type)
      • matchesSafely

        protected boolean matchesSafely​(java.lang.Throwable item)
        Specified by:
        matchesSafely in class org.hamcrest.TypeSafeMatcher<java.lang.Throwable>
      • describeTo

        public void describeTo​(org.hamcrest.Description description)