@Test public void test_error_description() { Matcher<Throwable> tMatcher = mock(Matcher.class); when(tMatcher.matches(anyObject())).thenReturn(true); DescribeAnswer.describe(tMatcher, "throwable-matcher msg"); Matcher<String> sMatcher = mock(Matcher.class); when(sMatcher.matches(anyObject())).thenReturn(false); DescribeAnswer.describe(sMatcher, "message-matcher msg"); DescribeAnswer.mismatch(sMatcher, "message-mismatch"); Matcher<Object> matcher = instanceOf(Throwable.class).that( tMatcher, new ExceptionMessage(sMatcher)); AssertionError ae = null; P0 throwIllegalArgument = new P0() { @Override protected Object run() throws Throwable { throw new IllegalArgumentException("No value!"); } }; try { assertThat(throwIllegalArgument, raises(matcher)); } catch (AssertionError e) { ae = e; } assertThat("Matching failed", ae, not(nullValue())); assertThat(ae.getMessage(), containsPattern("Expected" + ".*throwable-matcher msg and throwable message is message-matcher msg.*")); assertThat(ae.getMessage(), containsPattern("but: threw message message-mismatch")); }
public Raises(Matcher<? super Throwable> matcher) { super(Proc.class); exceptionMatcher = matcher; }
Raises extends TypesafeNestedResultMatcher<Proc> { public Raises(Matcher<? super Throwable> matcher) { super(Proc.class); exceptionMatcher = matcher; } }
Raises extends TypesafeNestedResultMatcher<Proc> { public Raises(Matcher<? super Throwable> matcher) { super(Proc.class); exceptionMatcher = matcher; } Raises(Matcher<? super Throwable> matcher); }
Raises extends TypesafeNestedResultMatcher<Proc> { public Raises(Matcher<? super Throwable> matcher) { super(Proc.class); exceptionMatcher = matcher; } Raises(Matcher<? super Throwable> matcher); @Override int getDescriptionPrecedence(); @Override void describeTo(Description description); @Factory static Matcher<Proc> raises(Matcher<? super Throwable> throwableMatcher); @Factory static Matcher<Proc> raises(Class<? extends Throwable> clazz); @Factory static Matcher<Proc> raises(String regex); @Factory static Matcher<Proc> raises(Class<? extends Throwable> clazz, String regex); @Factory static Matcher<Proc> raises(Class<? extends Throwable> clazz, Matcher<? super Throwable> matcher); @Factory static Matcher<Proc> raisesException(); @Factory static Matcher<Proc> raisesException(Matcher<? super Exception> matcher); @Factory static Matcher<Proc> raisesException(Class<? extends Exception> clazz); @Factory static Matcher<Proc> raisesException(String regex); @Factory static Matcher<Proc> raisesException(Class<? extends Exception> clazz, String regex); }
Raises extends TypesafeNestedResultMatcher<Proc> { public Raises(Matcher<? super Throwable> matcher) { super(Proc.class); exceptionMatcher = matcher; } Raises(Matcher<? super Throwable> matcher); @Override int getDescriptionPrecedence(); @Override void describeTo(Description description); @Factory static Matcher<Proc> raises(Matcher<? super Throwable> throwableMatcher); @Factory static Matcher<Proc> raises(Class<? extends Throwable> clazz); @Factory static Matcher<Proc> raises(String regex); @Factory static Matcher<Proc> raises(Class<? extends Throwable> clazz, String regex); @Factory static Matcher<Proc> raises(Class<? extends Throwable> clazz, Matcher<? super Throwable> matcher); @Factory static Matcher<Proc> raisesException(); @Factory static Matcher<Proc> raisesException(Matcher<? super Exception> matcher); @Factory static Matcher<Proc> raisesException(Class<? extends Exception> clazz); @Factory static Matcher<Proc> raisesException(String regex); @Factory static Matcher<Proc> raisesException(Class<? extends Exception> clazz, String regex);  }