/** * Creates a matcher of {@link String} that matches when the examined string has zero length. * <p/> * For example: * <pre>assertThat("", isEmptyString())</pre> * */ @Factory public static Matcher<String> isEmptyString() { return INSTANCE; }
/** * 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(Matcher<? super T>... matchers) { return allOf(Arrays.asList(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 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(Matcher<? super T>... matchers) { return allOf(Arrays.asList(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 of {@link String} that matches when the examined string is <code>null</code>, or * has zero length. * <p/> * For example: * <pre>assertThat(((String)null), isEmptyString())</pre> * */ @Factory public static Matcher<String> isEmptyOrNullString() { return NULL_OR_EMPTY_INSTANCE; } }
/** * This is a shortcut to the frequently used hasSize(equalTo(x)). * * For example, assertThat(hasSize(equal_to(x))) * vs. assertThat(hasSize(x)) */ @Factory public static <E> Matcher<? super Collection<? extends E>> hasSize(int size) { Matcher<? super Integer> matcher = equalTo(size); return IsCollectionWithSize.<E>hasSize(matcher); } }
/** * 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(Matcher<? super T> first, Matcher<? super T> second) { List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2); matchers.add(first); matchers.add(second); return allOf(matchers); }
/** * 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); } }
/** * 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(Matcher<? super T> first, Matcher<? super T> second) { List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2); matchers.add(first); matchers.add(second); return allOf(matchers); }
@Factory public static <T extends Throwable> Matcher<T> isThrowable( Matcher<T> throwableMatcher) { return new StacktracePrintingMatcher<T>(throwableMatcher); }
/** * 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(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third) { List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(3); matchers.add(first); matchers.add(second); matchers.add(third); return allOf(matchers); }
@Factory public static <T extends Exception> Matcher<T> isException( Matcher<T> exceptionMatcher) { return new StacktracePrintingMatcher<T>(exceptionMatcher); } }
/** * Creates a matcher for arrays that matches when the <code>length</code> of the array * equals the specified <code>size</code>. * <p/> * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))</pre> * * @param size * the length that an examined array must have for a positive match */ @Factory public static <E> Matcher<E[]> arrayWithSize(int size) { return arrayWithSize(equalTo(size)); }
/** * 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(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third) { List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(3); matchers.add(first); matchers.add(second); matchers.add(third); return allOf(matchers); }
@Factory public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<String> matcher) { return new ThrowableMessageMatcher<T>(matcher); } }