1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.constraint;
3
4 import org.jmock.Constraint;
5
6 import java.util.EventObject;
7
8 /***
9 * Tests if the value is an event announced by a specific object.
10 */
11 public class IsEventFrom
12 implements Constraint {
13 private Class _event_class;
14 private Object _source;
15
16 /***
17 * Constructs an IsEventFrom predicate that returns true for any object
18 * derived from {@link java.util.EventObject} announced by
19 * <var>source</var>.
20 */
21 public IsEventFrom(Object source) {
22 this(EventObject.class, source);
23 }
24
25 /***
26 * Constructs an IsEventFrom predicate that returns true for any object
27 * derived from <var>event_class</var> announced by
28 * <var>source</var>.
29 */
30 public IsEventFrom(Class event_class, Object source) {
31 _event_class = event_class;
32 _source = source;
33 }
34
35 public boolean eval(Object o) {
36 if (o instanceof EventObject) {
37 EventObject ev = (EventObject) o;
38 return _event_class.isInstance(o) && ev.getSource() == _source;
39
40 } else {
41 return false;
42 }
43 }
44
45 public String toString() {
46 return "an event of type " + _event_class.getName() +
47 " from " + _source;
48 }
49 }
This page was automatically generated by Maven