Line | |
---|
1 | package geniusweb.issuevalue;
|
---|
2 |
|
---|
3 | import org.hamcrest.Description;
|
---|
4 | import org.hamcrest.Matcher;
|
---|
5 |
|
---|
6 | public class PatternMatch implements Matcher<String> {
|
---|
7 |
|
---|
8 | private String regex;
|
---|
9 |
|
---|
10 | public PatternMatch(String regex) {
|
---|
11 | this.regex = regex;
|
---|
12 | }
|
---|
13 |
|
---|
14 | @Override
|
---|
15 | public void describeTo(Description description) {
|
---|
16 | description.appendText("'" + regex + "'");
|
---|
17 | }
|
---|
18 |
|
---|
19 | @Override
|
---|
20 | public boolean matches(Object item) {
|
---|
21 | if (!(item instanceof String))
|
---|
22 | throw new IllegalArgumentException(
|
---|
23 | "item is not a string:" + item.toString());
|
---|
24 | return ((String) item).matches(regex);
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public void describeMismatch(Object text, Description mismatchDescription) {
|
---|
29 | mismatchDescription.appendText("'" + text
|
---|
30 | + "' does not match regular expression '" + regex + "'");
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
|
---|
35 | }
|
---|
36 |
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.