1 package groovy.mock;
2
3 import groovy.lang.Closure;
4 import groovy.lang.ParameterArray;
5
6 import com.mockobjects.constraint.Constraint;
7
8 /***
9 *
10 * @author Joe Walnes
11 * @author Chris Stevenson
12 * @version $Revision: 1.2 $
13 */
14 public class ClosureConstraintMatcher implements Constraint {
15 private Closure closure;
16 private String message = "closure";
17
18 public ClosureConstraintMatcher(Closure closure) {
19 this.closure = closure;
20 }
21
22 public boolean eval(Object object) {
23 try {
24 closure.call(new ParameterArray(object));
25 return true;
26 }
27 catch (AssertionError e) {
28 message = e.getMessage();
29 return false;
30 }
31 }
32
33 public String toString() {
34 return message;
35 }
36
37 }