View Javadoc

1   package groovy.mock;
2   
3   import groovy.lang.Closure;
4   import com.mockobjects.constraint.Constraint;
5   
6   /***
7    * 
8    * @author Joe Walnes
9    * @author Chris Stevenson
10   * @version $Revision: 1.3 $
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          }
25          catch (AssertionError e) {
26              message = e.getMessage();
27              return false;
28          }
29      }
30  
31      public String toString() {
32          return message;
33      }
34  
35  }