/** * Returns a matcher that verifies that the outer exception has a cause for which the supplied matcher * evaluates to true. * * @param matcher to apply to the cause of the outer exception * @param <T> type of the outer exception */ @Factory public static <T extends Throwable> Matcher<T> hasCause(final Matcher<?> matcher) { return new ThrowableCauseMatcher<T>(matcher); } }
@Factory public static <T extends Throwable> Matcher<T> isThrowable( Matcher<T> throwableMatcher) { return new StacktracePrintingMatcher<T>(throwableMatcher); }
@Factory public static <T extends Exception> Matcher<T> isException( Matcher<T> exceptionMatcher) { return new StacktracePrintingMatcher<T>(exceptionMatcher); } }
@Factory public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<String> matcher) { return new ThrowableMessageMatcher<T>(matcher); } }
@Factory public static <T extends Throwable> Matcher<T> hasCause(final Matcher<T> matcher) { return new ThrowableCauseMatcher<T>(matcher); } }
@Factory public static <T extends Exception> Matcher<T> isException( Matcher<T> exceptionMatcher) { return new StacktracePrintingMatcher<T>(exceptionMatcher); } }
/** * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers. * <p/> * For example: * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre> */ @Factory public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers) { return new AnyOf<T>(matchers); }
/** * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers. * <p/> * For example: * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre> */ @Factory public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers) { return new AllOf<T>(matchers); }
/** * Creates a matcher that always matches, regardless of the examined object. */ @Factory public static Matcher<Object> anything() { return new IsAnything<Object>(); }
/** * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers. * <p/> * For example: * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre> */ @Factory public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers) { return anyOf(Arrays.asList(matchers)); }
/** * Creates a matcher that matches only when the examined object is the same instance as * the specified target object. * * @param target * the target instance against which others should be assessed */ @Factory public static <T> Matcher<T> sameInstance(T target) { return new IsSame<T>(target); }
/** * Creates a matcher that matches only when the examined object is the same instance as * the specified target object. * * @param target * the target instance against which others should be assessed */ @Factory public static <T> Matcher<T> theInstance(T target) { return new IsSame<T>(target); } }
@Factory public static <T extends Throwable> Matcher<T> isThrowable( Matcher<T> throwableMatcher) { return new StacktracePrintingMatcher<T>(throwableMatcher); }
/** * Creates a matcher that matches when both of the specified matchers match the examined object. * <p/> * For example: * <pre>assertThat("fab", both(containsString("a")).and(containsString("b")))</pre> */ @Factory public static <LHS> CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher) { return new CombinableBothMatcher<LHS>(matcher); }
@Factory public static RingBufferEventMatcher ringBufferWithEvents(final Matcher<?>... valueMatchers) { return new RingBufferEventMatcher(valueMatchers); }
@Factory public static RingBufferEventMatcher ringBufferWithEvents(final Object... values) { Matcher<?>[] valueMatchers = new Matcher[values.length]; for (int i = 0; i < values.length; i++) { final Object value = values[i]; valueMatchers[i] = is(value); } return new RingBufferEventMatcher(valueMatchers); }
@Factory public static Matcher<String> endsWith( String pattern ) { return new RegExp( pattern, MatchType.end ); }
@Factory public static Matcher matchesPattern( Pattern pattern ) { return new RegularExpressionMatcher( pattern ); }
@Factory public static <T> Contains<T> contains( T... expectedItems ) { return new Contains<>( expectedItems ); } }
@Factory public static Matcher matchesPattern( String pattern ) { return new RegularExpressionMatcher( pattern ); } }