From: Nat P. <np...@us...> - 2002-10-14 18:01:24
|
Update of /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock In directory usw-pr-cvs1:/tmp/cvs-serv20269/source/com/b13media/mock Modified Files: IsEventFrom.java Log Message: IsEventFrom predicate can test for event type. Index: IsEventFrom.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/IsEventFrom.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- IsEventFrom.java 11 Oct 2002 14:57:37 -0000 1.1 +++ IsEventFrom.java 14 Oct 2002 18:01:18 -0000 1.2 @@ -9,22 +9,30 @@ public class IsEventFrom implements Predicate { + private Class _event_class; private Object _source; public IsEventFrom( Object source ) { + this( EventObject.class, source ); + } + + public IsEventFrom( Class event_class, Object source ) { + _event_class = event_class; _source = source; } - + public boolean eval( Object o ) { if( o instanceof EventObject ) { EventObject ev = (EventObject)o; - return ev.getSource() == _source; + return _event_class.isInstance(o) && ev.getSource() == _source; + } else { return false; } } public String toString() { - return "an event from " + _source.toString(); + return "an event of type " + _event_class.getName() + + " from " + _source.toString(); } } |