1 3 package test.jmock.core.constraint; 4 5 import java.util.EventObject ; 6 import org.jmock.core.constraint.IsEventFrom; 7 8 9 public class IsEventFromTest extends AbstractConstraintsTest 10 { 11 public void testEvaluatesToTrueIfArgumentIsAnEventObjectFiredByASpecifiedSource() { 12 Object o = new Object (); 13 EventObject ev = new EventObject (o); 14 EventObject ev2 = new EventObject (new Object ()); 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 26 { 27 public DerivedEvent( Object source ) { 28 super(source); 29 } 30 } 31 32 public void testCanTestForSpecificEventClasses() { 33 Object o = new Object (); 34 DerivedEvent good_ev = new DerivedEvent(o); 35 DerivedEvent wrong_source = new DerivedEvent(new Object ()); 36 EventObject wrong_type = new EventObject (o); 37 EventObject wrong_source_and_type = new EventObject (new Object ()); 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 |