Created
July 30, 2012 17:21
-
-
Save jashatton/3208504 to your computer and use it in GitHub Desktop.
Hamcrest Regular Expression Matcher.Copied from http://piotrga.wordpress.com/2009/03/27/hamcrest-regex-matcher/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.hamcrest.BaseMatcher; | |
import org.hamcrest.Description; | |
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