11package org .hamcrest .text ;
22
3+ import org .hamcrest .Description ;
34import org .hamcrest .Matcher ;
45import org .hamcrest .Matchers ;
56
67import java .util .Arrays ;
78import java .util .regex .Pattern ;
89
10+ import static org .hamcrest .core .AnyOf .anyOf ;
911import static org .hamcrest .core .IsNull .nullValue ;
12+ import static org .hamcrest .text .IsEmptyString .IS_EMPTY_STRING ;
1013
1114public class MatchStrings {
15+ private static final Pattern REGEX_WHITESPACE = Pattern .compile ("\\ s*" );
16+ public static final Matcher <String > IS_BLANK_STRING = new MatchesPattern (REGEX_WHITESPACE ) {
17+ @ Override
18+ public void describeTo (Description description ) {
19+ description .appendText ("a blank string" );
20+ }
21+ };
22+ public static final Matcher <String > IS_BLANK_OR_NULL_STRING = anyOf (IS_BLANK_STRING , nullValue ());
23+
1224 /**
1325 * Creates a matcher of {@link String} that matches when the examined string is equal to
1426 * the specified expectedString, ignoring case.
@@ -45,7 +57,7 @@ public static Matcher<java.lang.String> equalToIgnoringWhiteSpace(java.lang.Stri
4557 * <pre>assertThat(((String)null), is(emptyOrNullString()))</pre>
4658 */
4759 public static Matcher <java .lang .String > emptyOrNullString () {
48- return Matchers .anyOf (nullValue (), IsEmptyString . INSTANCE );
60+ return Matchers .anyOf (nullValue (), IS_EMPTY_STRING );
4961 }
5062
5163 /**
@@ -54,7 +66,7 @@ public static Matcher<java.lang.String> emptyOrNullString() {
5466 * <pre>assertThat("", is(emptyString()))</pre>
5567 */
5668 public static Matcher <java .lang .String > emptyString () {
57- return IsEmptyString . INSTANCE ;
69+ return IS_EMPTY_STRING ;
5870 }
5971
6072 /**
@@ -64,7 +76,7 @@ public static Matcher<java.lang.String> emptyString() {
6476 * <pre>assertThat(((String)null), is(blankOrNullString()))</pre>
6577 */
6678 public static Matcher <java .lang .String > blankOrNullString () {
67- return Matchers . anyOf ( nullValue (), IsBlankString . INSTANCE ) ;
79+ return IS_BLANK_OR_NULL_STRING ;
6880 }
6981
7082 /**
@@ -74,7 +86,7 @@ public static Matcher<java.lang.String> blankOrNullString() {
7486 * <pre>assertThat(" ", is(blankString()))</pre>
7587 */
7688 public static Matcher <java .lang .String > blankString () {
77- return IsBlankString . INSTANCE ;
89+ return IS_BLANK_STRING ;
7890 }
7991
8092 /**
0 commit comments