1 package com.mockobjects.beans; 2 3 import java.beans.PropertyChangeEvent ; 4 import java.beans.PropertyChangeListener ; 5 import com.mockobjects.ExpectationCounter; 6 import com.mockobjects.ExpectationValue; 7 import com.mockobjects.MockObject; 8 9 18 public class MockPropertyChangeListener extends MockObject implements PropertyChangeListener { 19 20 protected ExpectationValue propertyName; 21 protected ExpectationValue oldValue; 22 protected ExpectationValue newValue; 23 protected ExpectationCounter eventCount; 24 25 public MockPropertyChangeListener(String 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 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 expectedNewValue) { 44 newValue.setExpected(expectedNewValue); 45 } 46 47 public void setExpectedOldValue(Object expectedOldValue) { 48 oldValue.setExpected(expectedOldValue); 49 } 50 51 public void setExpectedEventCount(int expectedEventCount) { 52 eventCount.setExpected(expectedEventCount); 53 } 54 55 public void setExpectedPropertyName(String expectedPropertyName) { 56 propertyName.setExpected(expectedPropertyName); 57 } 58 59 } 60 | Popular Tags |