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