Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Created January 25, 2011 20:35
Show Gist options
  • Save webdevwilson/795600 to your computer and use it in GitHub Desktop.
Save webdevwilson/795600 to your computer and use it in GitHub Desktop.
Regular Expression Matcher for Unit testing
public class RegexMatcher extends BaseMatcher{
private final String regex;
public RegexMatcher(String regex){
this.regex = regex;
}
public boolean matches(Object o){
return ((String)o).matches(regex);
}
public void describeTo(Description description){
description.appendText("matches regex=");
}
public static RegexMatcher matches(String regex){
return new RegexMatcher(regex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment