Code example for PropertyChangeSupport

Methods: hasListeners, removePropertyChangeListener

0
     * Test the method hasListeners(String) when there is one listener for the 
     * named property. 
     */ 
    public void testHasListener_PropertyRegistered() { 
        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("myProP", l1);
        assertFalse(sup.hasListeners("myProp"));
        sup.addPropertyChangeListener("myProp", l2);
        assertTrue(sup.hasListeners("myProp"));
        sup.removePropertyChangeListener("myProp", l2);
        assertFalse(sup.hasListeners("myProp"));
        // The following assertion fails on RI. See HARMONY-2526 
        sup.addPropertyChangeListener("myProp", l3);
        assertTrue(sup.hasListeners("myProp"));
    } 
 
    /* 
     * Test the method hasListeners(String) when there is no listeners. 
     */