View Javadoc

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