2018-09-19 15:54:24 +02:00
|
|
|
package sonia.scm.it.utils;
|
2018-08-03 09:38:13 +02:00
|
|
|
|
|
|
|
|
import org.hamcrest.BaseMatcher;
|
|
|
|
|
import org.hamcrest.Description;
|
|
|
|
|
import org.hamcrest.Matcher;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
2018-09-19 15:54:24 +02:00
|
|
|
public class RegExMatcher extends BaseMatcher<String> {
|
2018-08-03 09:38:13 +02:00
|
|
|
public static Matcher<String> matchesPattern(String pattern) {
|
|
|
|
|
return new RegExMatcher(pattern);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final String pattern;
|
|
|
|
|
|
|
|
|
|
private RegExMatcher(String pattern) {
|
|
|
|
|
this.pattern = pattern;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void describeTo(Description description) {
|
|
|
|
|
description.appendText("matching to regex pattern \"" + pattern + "\"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matches(Object o) {
|
|
|
|
|
return Pattern.compile(pattern).matcher(o.toString()).matches();
|
|
|
|
|
}
|
|
|
|
|
}
|