Ruby\'s Test::Unit has a nice assert_matches method that can be used in unit tests to assert that a regex matches a string.
Is there anythi
You can use Hamcrest, but you have to write your own matcher:
public class RegexMatcher extends TypeSafeMatcher {
private final String regex;
public RegexMatcher(final String regex) {
this.regex = regex;
}
@Override
public void describeTo(final Description description) {
description.appendText("matches regex=`" + regex + "`");
}
@Override
public boolean matchesSafely(final String string) {
return string.matches(regex);
}
public static RegexMatcher matchesRegex(final String regex) {
return new RegexMatcher(regex);
}
}
usage
import org.junit.Assert;
Assert.assertThat("test", RegexMatcher.matchesRegex(".*est");