Hello guys,
Here is a little contribution: a mock object for a PropertyChangeListener.
In correspondence to the io and sql subpackages, I put this class in a beans
subpackage, since the PropertyChangeListener interface resides in
java.beans.
---- Start of class --------------
package com.mockobjects.beans;
import java.beans.*;
import com.mockobjects.*;
/**
* Mock object for a PropertyChangeListener.
* This mock object can be used in verifying the event propagation mechanism
* of beans. You can set the information you expect from a
PropertyChangeEvent
* as well as the number of events. If you expect more than one event, only
the
* actual values of the last event are stored.
*
* @author Ringo De Smet - <a href="http://www.mediagenix.com">MediaGeniX
NV</a>
*/
public class MockPropertyChangeListener
extends MockObject
implements PropertyChangeListener {
protected ExpectationValue expectedPropertyName;
protected ExpectationValue expectedOldValue;
protected ExpectationValue expectedNewValue;
protected ExpectationCounter expectedNrOfEvents;
public MockPropertyChangeListener() {
this.expectedPropertyName =
new
ExpectationValue("MockPropertyChangeListener.propertyName");
this.expectedOldValue =
new
ExpectationValue("MockPropertyChangeListener.oldValue");
this.expectedNewValue =
new
ExpectationValue("MockPropertyChangeListener.newValue");
this.expectedNrOfEvents =
new
ExpectationCounter("MockPropertyChangeListener.expectedNrOfEvents");
}
public MockPropertyChangeListener(String name) {
this.expectedPropertyName = new ExpectationValue(name +
".propertyName");
this.expectedOldValue = new ExpectationValue(name +
".oldValue");
this.expectedNewValue = new ExpectationValue(name +
".newValue");
this.expectedNrOfEvents = new ExpectationCounter(name +
".expectedNrOfEvents");
}
public void propertyChange(PropertyChangeEvent evt) {
this.expectedPropertyName.setActual(evt.getPropertyName());
this.expectedOldValue.setActual(evt.getOldValue());
this.expectedNewValue.setActual(evt.getNewValue());
this.expectedNrOfEvents.inc();
}
public void setExpectedNewValue(Object expectedNewValue) {
this.expectedNewValue.setExpected(expectedNewValue);
}
public void setExpectedNrOfEvents(int nrOfExpectedEvents) {
this.expectedNrOfEvents.setExpected(nrOfExpectedEvents);
}
public void setExpectedOldValue(Object expectedOldValue) {
this.expectedOldValue.setExpected(expectedOldValue);
}
public void setExpectedPropertyName(String expectedPropertyName) {
this.expectedPropertyName.setExpected(expectedPropertyName);
}
}
-- End of class ----------------------
Ringo
|