/*
* add a VetoableChangeListenerProxy
*/
public void testAddVetoableChangeListenerVetoableChangeListener_Proxy() {
MockSource source = new MockSource();
VetoableChangeSupport support = new VetoableChangeSupport(source);
VetoableChangeListener proxy = EventHandler.create(
VetoableChangeListener.class, source, "setText");
proxy = new MockVetoableChangeListener();
String propertyName = "label";
VetoableChangeListenerProxy listenerProxy = new VetoableChangeListenerProxy(
propertyName, proxy);
assertFalse(support.hasListeners("label"));
try{
support.addVetoableChangeListener(listenerProxy);
fail("should throw NPE");
}catch(NullPointerException e){
//expected
e.printStackTrace();
}
assertTrue(support.hasListeners("label"));
assertTrue(support.hasListeners(propertyName));
assertFalse(support.hasListeners("text"));
{
VetoableChangeListener[] listeners1 = support
.getVetoableChangeListeners();
VetoableChangeListener[] listeners2 = support
.getVetoableChangeListeners(propertyName);
VetoableChangeListener[] listeners3 = support
.getVetoableChangeListeners("text");
assertEquals(0, listeners3.length);
assertEquals(1, listeners1.length);
assertEquals(1, listeners2.length);
assertSame(proxy, listeners2[0]);
VetoableChangeListenerProxy wrappers = (VetoableChangeListenerProxy) listeners1[0];
assertSame(proxy, wrappers.getListener());
assertEquals(propertyName, wrappers.getPropertyName());
}
// add test for remove proxy
support.removeVetoableChangeListener(listenerProxy);
{
VetoableChangeListener[] listeners1 = support
.getVetoableChangeListeners();
VetoableChangeListener[] listeners2 = support
.getVetoableChangeListeners(propertyName);
assertEquals(0, listeners1.length);
assertEquals(0, listeners2.length);
}