01: package groovy.mock;
02:
03: import groovy.lang.Closure;
04: import com.mockobjects.constraint.Constraint;
05:
06: /**
07: *
08: * @author Joe Walnes
09: * @author Chris Stevenson
10: * @version $Revision: 2724 $
11: */
12: public class ClosureConstraintMatcher implements Constraint {
13: private Closure closure;
14: private String message = "closure";
15:
16: public ClosureConstraintMatcher(Closure closure) {
17: this .closure = closure;
18: }
19:
20: public boolean eval(Object object) {
21: try {
22: closure.call((Object[]) object);
23: return true;
24: } catch (AssertionError e) {
25: message = e.getMessage();
26: return false;
27: }
28: }
29:
30: public String toString() {
31: return message;
32: }
33:
34: }
|