001 package groovy.mock; 002 003 import groovy.lang.Closure; 004 005 import com.mockobjects.constraint.Constraint; 006 007 /** 008 * 009 * @author Joe Walnes 010 * @author Chris Stevenson 011 * @version $Revision: 1.1 $ 012 */ 013 public class ClosureConstraintMatcher implements Constraint { 014 private Closure closure; 015 private String message = "closure"; 016 017 public ClosureConstraintMatcher(Closure closure) { 018 this.closure = closure; 019 } 020 021 public boolean eval(Object object) { 022 try { 023 closure.call(object); 024 return true; 025 } 026 catch (AssertionError e) { 027 message = e.getMessage(); 028 return false; 029 } 030 } 031 032 public String toString() { 033 return message; 034 } 035 036 }