KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > beans > MockPropertyChangeListener


1 package com.mockobjects.beans;
2
3 import java.beans.PropertyChangeEvent JavaDoc;
4 import java.beans.PropertyChangeListener JavaDoc;
5 import com.mockobjects.ExpectationCounter;
6 import com.mockobjects.ExpectationValue;
7 import com.mockobjects.MockObject;
8
9 /**
10  * Mock object for a PropertyChangeListener.
11  * This mock object can be used in verifying the event propagation mechanism
12  * of beans. You can set the information you expect from a PropertyChangeEvent
13  * as well as the number of events. If you expect more than one event, only the
14  * actual values of the last event are stored.
15  *
16  * @author Ringo De Smet - <a HREF="http://www.mediagenix.com">MediaGeniX NV</a>
17  */

18 public class MockPropertyChangeListener extends MockObject implements PropertyChangeListener JavaDoc {
19
20     protected ExpectationValue propertyName;
21     protected ExpectationValue oldValue;
22     protected ExpectationValue newValue;
23     protected ExpectationCounter eventCount;
24
25     public MockPropertyChangeListener(String JavaDoc name) {
26         propertyName = new ExpectationValue(name + ".propertyName");
27         oldValue = new ExpectationValue(name + ".oldValue");
28         newValue = new ExpectationValue(name + ".newValue");
29         eventCount = new ExpectationCounter(name + ".expectedNrOfEvents");
30     }
31
32     public MockPropertyChangeListener() {
33         this("MockPropertyChangeListener");
34     }
35
36     public void propertyChange(PropertyChangeEvent JavaDoc event) {
37         propertyName.setActual(event.getPropertyName());
38         oldValue.setActual(event.getOldValue());
39         newValue.setActual(event.getNewValue());
40         eventCount.inc();
41     }
42
43     public void setExpectedNewValue(Object JavaDoc expectedNewValue) {
44         newValue.setExpected(expectedNewValue);
45     }
46
47     public void setExpectedOldValue(Object JavaDoc expectedOldValue) {
48         oldValue.setExpected(expectedOldValue);
49     }
50
51     public void setExpectedEventCount(int expectedEventCount) {
52         eventCount.setExpected(expectedEventCount);
53     }
54
55     public void setExpectedPropertyName(String JavaDoc expectedPropertyName) {
56         propertyName.setExpected(expectedPropertyName);
57     }
58
59 }
60
Popular Tags