01: package net.sf.mockcreator.expectable;
02:
03: /**
04: * @author Ben Rosenbaum
05: *
06: * Expects a String matching the given regular expression
07: */
08: public class ExpectRegexp implements ExpectableParameter {
09: private String regex;
10:
11: /**
12: * Construct expectable by regular expression.
13: * @param regexp Expected regexp
14: */
15: public ExpectRegexp(String regex) {
16: if (regex == null) {
17: throw new IllegalArgumentException(
18: "null regex has no sense");
19: }
20:
21: this .regex = regex;
22: }
23:
24: public boolean isExpected(Object actual) {
25: if (actual == null) {
26: return false;
27: }
28:
29: if (!(actual instanceof String)) {
30: return false;
31: }
32:
33: String act = (String) actual;
34:
35: return act.matches(regex);
36: }
37:
38: public String toString() {
39: return "ExpectString( like /" + regex + "/)";
40: }
41: }
|