1 3 package org.jmock.core.constraint; 4 5 import java.util.EventObject ; 6 import org.jmock.core.Constraint; 7 8 9 12 public class IsEventFrom implements Constraint 13 { 14 private Class eventClass; 15 private Object source; 16 17 22 public IsEventFrom( Object source ) { 23 this(EventObject .class, source); 24 } 25 26 30 public IsEventFrom( Class eventClass, Object source ) { 31 this.eventClass = eventClass; 32 this.source = source; 33 } 34 35 public boolean eval( Object o ) { 36 return (o instanceof EventObject ) 37 && eventClass.isInstance(o) 38 && eventHasSameSource((EventObject )o); 39 } 40 41 private boolean eventHasSameSource(EventObject ev) { 42 return ev.getSource() == source; 43 } 44 45 public StringBuffer describeTo( StringBuffer buffer ) { 46 return buffer.append("an event of type ") 47 .append(eventClass.getName()) 48 .append(" from ") 49 .append(source); 50 } 51 } 52 | Popular Tags |