/** * 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 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<java.lang.String> matchesPattern(java.lang.String regex) { return org.hamcrest.text.MatchesPattern.matchesPattern(regex); }
/** * 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 factoryMethodAllowsCreationWithPattern() { Matcher<?> m = MatchesPattern.matchesPattern(Pattern.compile("a[bc](d|e)")); assertDescription("a string matching the pattern 'a[bc](d|e)'", m ); }
@Test public void describesAMismatch() { final Matcher<String> matcher = new MatchesPattern(Pattern.compile("a")); assertMismatchDescription("was \"Cheese\"", matcher, "Cheese"); }
@Test public void factoryMethodAllowsCreationWithString() { Matcher<?> m = MatchesPattern.matchesPattern("a[bc](d|e)"); assertDescription("a string matching the pattern 'a[bc](d|e)'", m ); } }
@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 ); }
/** * 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 org.hamcrest.Matcher<java.lang.String> matchesPattern(java.lang.String regex) { return org.hamcrest.text.MatchesPattern.matchesPattern(regex); }
@Test public void doesNotMatchADifferentString() { assertDoesNotMatch("A different string does not match", new MatchesPattern(Pattern.compile("a")), "b"); }
/** * 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 org.hamcrest.Matcher<java.lang.String> matchesPattern(java.util.regex.Pattern pattern) { return org.hamcrest.text.MatchesPattern.matchesPattern(pattern); }
@Test public void doesNotMatchSubstring() { assertDoesNotMatch("A substring does not match", new MatchesPattern(Pattern.compile("a")), "ab"); }
/** * 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<java.lang.String> matchesPattern(java.lang.String regex) { return org.hamcrest.text.MatchesPattern.matchesPattern(regex); }
@Test public void matchesExactString() { assertThat("a", new MatchesPattern(Pattern.compile("a"))); }
/** * 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); }
@Test public void copesWithNullsAndUnknownTypes() { Matcher<String> matcher = new MatchesPattern(Pattern.compile(".")); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); }
@Test public void testToString() { //GIVEN ScopeImpl scope = new ScopeImpl("root"); scope.installModules(new TestModule1()); ScopeImpl childScope = new ScopeImpl("child"); scope.addChild(childScope); //WHEN childScope.getInstance(Bar.class); String dump = scope.toString(); //THEN Pattern expected = Pattern.compile("root:\\d+.*" + "Providers: \\[toothpick.Scope,toothpick.data.Foo\\].*" + "\\\\---child:\\d+.*" + "Providers:.*\\[toothpick.Scope\\].*" + "Unbound providers: \\[toothpick.data.Bar\\].*", Pattern.DOTALL); assertThat(dump, MatchesPattern.matchesPattern(expected)); }
/** * 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); }
@Test public void nullMessage() { LoggingEvent event = new LoggingEvent("", logger, Level.INFO, null, null, null); event.setTimeStamp(0); String result = layout.doLayout(event); String firstLine = result.split(CoreConstants.LINE_SEPARATOR)[0]; assertThat(firstLine, matchesPattern(TTLL_PREFIX_PATTERN + " - null")); } }
/** * 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)); } }