/** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the length * of the specified <code>argument</code>. * For example: * * <pre> * assertThat("text", length(4)) * </pre> * * @param length the expected length of the string */ public static Matcher<CharSequence> hasLength(int length) { return org.hamcrest.text.CharSequenceLength.hasLength(length); }
/** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length * For example: * * <pre> * assertThat("text", hasLength(lessThan(4))) * </pre> * * @param lengthMatcher the expected length of the string */ @SuppressWarnings("WeakerAccess") public static Matcher<CharSequence> hasLength(Matcher<? super Integer> lengthMatcher) { return new CharSequenceLength(lengthMatcher); } }
@Override protected Matcher<?> createMatcher() { return hasLength(4); }
/** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length * For example: * * <pre> * assertThat("text", hasLength(4)) * </pre> * * @param length the expected length of the string */ public static Matcher<CharSequence> hasLength(int length) { return new CharSequenceLength(equalTo(length)); }
public void test_matchesExactLengthOf_CharSequence() { final Matcher<CharSequence> matcher = hasLength(4); assertMatches(matcher, "aaaa"); assertMatches(matcher, "a b "); assertMismatchDescription("length was <6>", matcher, "aaaaaa"); }
/** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length * For example: * * <pre> * assertThat("text", hasLength(lessThan(4))) * </pre> * * @param lengthMatcher the expected length of the string */ @SuppressWarnings("WeakerAccess") public static Matcher<CharSequence> hasLength(Matcher<? super Integer> lengthMatcher) { return new CharSequenceLength(lengthMatcher); } }
public void test_matchesRelativeLengthOf_CharSequence() { final Matcher<CharSequence> matcher = hasLength(lessThan(4)); assertMatches(matcher, "aaa"); assertMatches(matcher, "a b"); assertMismatchDescription("length <4> was equal to <4>", matcher, "aaaa"); assertMismatchDescription("length <5> was greater than <4>", matcher, "aaaaa"); }
/** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length * For example: * * <pre> * assertThat("text", hasLength(4)) * </pre> * * @param length the expected length of the string */ public static Matcher<CharSequence> hasLength(int length) { return new CharSequenceLength(equalTo(length)); }
/** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the length * of the specified <code>argument</code>. * For example: * * <pre> * assertThat("text", length(4)) * </pre> * * @param length the expected length of the string */ public static Matcher<CharSequence> hasLength(int length) { return org.hamcrest.text.CharSequenceLength.hasLength(length); }