/** * 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); }
/** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. */ public static Matcher<String> matchesPattern(String regex) { return new MatchesPattern(Pattern.compile(regex)); } }
@Test public void describesAMismatch() { final Matcher<String> matcher = new MatchesPattern(Pattern.compile("a")); assertMismatchDescription("was \"Cheese\"", matcher, "Cheese"); }
@Test public void hasAReadableDescription() { Matcher<?> m = new MatchesPattern(Pattern.compile("a[bc](d|e)")); assertDescription("a string matching the pattern 'a[bc](d|e)'", m ); }
@Test public void doesNotMatchADifferentString() { assertDoesNotMatch("A different string does not match", new MatchesPattern(Pattern.compile("a")), "b"); }
@Test public void doesNotMatchSubstring() { assertDoesNotMatch("A substring does not match", new MatchesPattern(Pattern.compile("a")), "ab"); }
@Test public void matchesExactString() { assertThat("a", new MatchesPattern(Pattern.compile("a"))); }
@Test public void copesWithNullsAndUnknownTypes() { Matcher<String> matcher = new MatchesPattern(Pattern.compile(".")); assertNullSafe(matcher); assertUnknownTypeSafe(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<String> matchesPattern(Pattern pattern) { return new MatchesPattern(pattern); }
/** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. */ public static Matcher<String> matchesPattern(String regex) { return new MatchesPattern(Pattern.compile(regex)); } }
/** * 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); }
/** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. */ public static Matcher<String> matchesPattern(String regex) { return new MatchesPattern(Pattern.compile(regex)); } }