/** * Creates a matcher of {@link String} that matches when the examined string is equal to * the specified expectedString, ignoring case. * <p/> * For example: * <pre>assertThat("Foo", equalToIgnoringCase("FOO"))</pre> * * @param expectedString * the expected value of matched strings */ public static org.hamcrest.Matcher<java.lang.String> equalToIgnoringCase(java.lang.String expectedString) { return org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase(expectedString); }
/** * Creates a matcher of {@link String} that matches when the examined string has zero length. * <p/> * For example: * <pre>assertThat("", isEmptyString())</pre> */ public static org.hamcrest.Matcher<java.lang.String> isEmptyString() { return org.hamcrest.text.IsEmptyString.isEmptyString(); }
/** * 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> */ public static org.hamcrest.Matcher<java.lang.String> isEmptyOrNullString() { return org.hamcrest.text.IsEmptyString.isEmptyOrNullString(); }
public void testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() { assertMatches("substrings in order", matcher, "abcc"); assertMatches("substrings separated", matcher, "1a2b3c4c5"); assertDoesNotMatch("can detect repeated strings for matching", stringContainsInOrder("abc", "abc"), "---abc---"); assertDoesNotMatch("substrings in order missing a repeated pattern", matcher, "abc"); assertDoesNotMatch("substrings out of order", matcher, "cab"); assertDoesNotMatch("no substrings in string", matcher, "xyz"); assertDoesNotMatch("substring missing", matcher, "ac"); assertDoesNotMatch("empty string", matcher, ""); }
/** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given {@link java.util.regex.Pattern}. */ public static Matcher<java.lang.String> matchesPattern(java.util.regex.Pattern pattern) { return org.hamcrest.text.MatchesPattern.matchesPattern(pattern); }
/** * Creates a matcher of {@link String} that matches when the examined string contains all of * the specified substrings, regardless of the order of their appearance. * <p/> * For example: * <pre>assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))</pre> * * @param substrings * the substrings that must be contained within matching strings */ public static org.hamcrest.Matcher<java.lang.String> stringContainsInOrder(java.lang.Iterable<java.lang.String> substrings) { return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); }
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 String} that matches when the examined string is equal to * the specified expectedString, ignoring case. * For example: * <pre>assertThat("Foo", equalToIgnoringCase("FOO"))</pre> * * @param expectedString * the expected value of matched strings */ public static Matcher<String> equalToIgnoringCase(String expectedString) { return new IsEqualIgnoringCase(expectedString); }
/** * Creates a matcher of {@link String} that matches when the examined string contains all of * the specified substrings, considering the order of their appearance. * For example: * <pre>assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))</pre> * fails as "foo" occurs before "bar" in the string "myfoobarbaz" * * @param substrings * the substrings that must be contained within matching strings */ public static Matcher<String> stringContainsInOrder(Iterable<String> substrings) { return new StringContainsInOrder(substrings); }
/** * Creates a matcher of {@link String} that matches when the examined string has zero length. * For example: * <pre>assertThat("", is(emptyString()))</pre> */ public static Matcher<java.lang.String> emptyString() { return org.hamcrest.text.IsEmptyString.emptyString(); }
/** * Creates a matcher of {@link String} that matches when the examined string is <code>null</code>, or * has zero length. * For example: * <pre>assertThat(((String)null), is(emptyOrNullString()))</pre> */ public static Matcher<java.lang.String> emptyOrNullString() { return org.hamcrest.text.IsEmptyString.emptyOrNullString(); }
/** * Creates a matcher of {@link String} that matches when the examined string contains * zero or more whitespace characters and nothing else. * For example: * <pre>assertThat(" ", is(blankString()))</pre> */ public static Matcher<java.lang.String> blankString() { return org.hamcrest.text.IsBlankString.blankString(); }
/** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given {@link java.util.regex.Pattern}. */ public static Matcher<String> matchesPattern(Pattern pattern) { return new MatchesPattern(pattern); }
/** * @deprecated {@link #equalToCompressingWhiteSpace(String)} * @param expectedString * the expected value of matched strings */ public static Matcher<String> equalToIgnoringWhiteSpace(String expectedString) { return new IsEqualCompressingWhiteSpace(expectedString); }
public void testFailsIfTextOtherThanWhitespaceDiffers() { assertDoesNotMatch(matcher, "Hello PLANET how are we?"); assertDoesNotMatch(matcher, "Hello World how are we"); }
public void testHasAReadableDescription() { assertDescription("a string equal to \" Hello World how\\n are we? \" compressing white space", matcher); } }
/** * Creates a matcher of {@link String} that matches when the examined string is equal to * the specified expectedString, ignoring case. * For example: * <pre>assertThat("Foo", equalToIgnoringCase("FOO"))</pre> * * @param expectedString * the expected value of matched strings */ public static Matcher<java.lang.String> equalToIgnoringCase(java.lang.String expectedString) { return org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase(expectedString); }
/** * Creates a matcher of {@link String} that matches when the examined string is <code>null</code>, or * has zero length. * For example: * <pre>assertThat(((String)null), isEmptyOrNullString())</pre> * * @deprecated use is(emptyOrNullString()) instead */ @SuppressWarnings("deprecation") public static Matcher<java.lang.String> isEmptyOrNullString() { return org.hamcrest.text.IsEmptyString.isEmptyOrNullString(); }
/** * Creates a matcher of {@link String} that matches when the examined string contains all of * the specified substrings, considering the order of their appearance. * For example: * <pre>assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))</pre> * fails as "foo" occurs before "bar" in the string "myfoobarbaz" * * @param substrings * the substrings that must be contained within matching strings */ public static Matcher<java.lang.String> stringContainsInOrder(java.lang.Iterable<java.lang.String> substrings) { return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); }
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"); }