KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > constraint > IsEventFromTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.core.constraint;
4
5 import java.util.EventObject JavaDoc;
6 import org.jmock.core.constraint.IsEventFrom;
7
8
9 public class IsEventFromTest extends AbstractConstraintsTest
10 {
11     public void testEvaluatesToTrueIfArgumentIsAnEventObjectFiredByASpecifiedSource() {
12         Object JavaDoc o = new Object JavaDoc();
13         EventObject JavaDoc ev = new EventObject JavaDoc(o);
14         EventObject JavaDoc ev2 = new EventObject JavaDoc(new Object JavaDoc());
15
16         IsEventFrom p = new IsEventFrom(o);
17
18         assertTrue(p.eval(ev));
19         assertTrue("p should eval to false for an event not from o",
20                    !p.eval(ev2));
21         assertTrue("p should eval to false for objects that are not events",
22                    !p.eval(o));
23     }
24
25     private static class DerivedEvent extends EventObject JavaDoc
26     {
27         public DerivedEvent( Object JavaDoc source ) {
28             super(source);
29         }
30     }
31
32     public void testCanTestForSpecificEventClasses() {
33         Object JavaDoc o = new Object JavaDoc();
34         DerivedEvent good_ev = new DerivedEvent(o);
35         DerivedEvent wrong_source = new DerivedEvent(new Object JavaDoc());
36         EventObject JavaDoc wrong_type = new EventObject JavaDoc(o);
37         EventObject JavaDoc wrong_source_and_type = new EventObject JavaDoc(new Object JavaDoc());
38
39         IsEventFrom p = new IsEventFrom(DerivedEvent.class, o);
40
41         assertTrue(p.eval(good_ev));
42         assertTrue("p should eval to false for an event not from o",
43                    !p.eval(wrong_source));
44         assertTrue("p should eval to false for an event of the wrong type",
45                    !p.eval(wrong_type));
46         assertTrue("p should eval to false for an event of the wrong type " +
47                    "and from the wrong source",
48                    !p.eval(wrong_source_and_type));
49     }
50 }
51
Popular Tags