Code example for PropertyChangeSupport

Methods: addPropertyChangeListenerhasListenersremovePropertyChangeListener

0
     * Test the method hasListeners(String) when there is one listener for all 
     * properties. 
     */ 
    public void testHasListener_AllRegistered() { 
        Object src = new Object();
        PropertyChangeSupport sup = new PropertyChangeSupport(src);
        PropertyChangeListener l1 = new MockPropertyChangeListener();
        PropertyChangeListener l2 = new MockPropertyChangeListener();
        PropertyChangeListener l3 = new PropertyChangeListenerProxy("myProp",
                l2);
 
        assertFalse(sup.hasListeners("myProp"));
        sup.addPropertyChangeListener(l1);
        assertTrue(sup.hasListeners("myProp"));
        sup.removePropertyChangeListener(l1);
        assertFalse(sup.hasListeners("myProp"));
        sup.addPropertyChangeListener(l3);
        assertTrue(sup.hasListeners("myProp"));
    } 
 
    /* 
     * Test the method hasListeners(String) when there is one listener for the 
     * named property. 
Stop searching for code, let great code find you!  Add Codota to your java IDE