public void testRemoveWithProxies(){
  Object bean=new Object();
  PropertyChangeSupport support=new PropertyChangeSupport(bean);
  EventLog all=new EventLog();
  support.addPropertyChangeListener(all);
  assertEquals(1,support.getPropertyChangeListeners().length);
  EventLog proxiedA=new EventLog();
  support.addPropertyChangeListener(new PropertyChangeListenerProxy("a",proxiedA));
  assertEquals(2,support.getPropertyChangeListeners().length);
  EventLog addA=new EventLog();
  support.addPropertyChangeListener("a",addA);
  assertEquals(3,support.getPropertyChangeListeners().length);
  EventLog addAProxiedB=new EventLog();
  support.addPropertyChangeListener("a",new PropertyChangeListenerProxy("b",addAProxiedB));
  assertEquals(4,support.getPropertyChangeListeners().length);
  EventLog proxiedAB=new EventLog();
  PropertyChangeListenerProxy proxyAB=new PropertyChangeListenerProxy("a",new PropertyChangeListenerProxy("b",proxiedAB));
  support.addPropertyChangeListener(proxyAB);
  assertEquals(5,support.getPropertyChangeListeners().length);
  EventLog proxiedAAC=new EventLog();
  support.addPropertyChangeListener(new PropertyChangeListenerProxy("a",new PropertyChangeListenerProxy("a",new PropertyChangeListenerProxy("c",proxiedAAC))));
  assertEquals(6,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener(all);
  assertEquals(5,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener("a",proxiedA);
  assertEquals(4,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener(new PropertyChangeListenerProxy("a",addA));
  assertEquals(3,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener("a",new PropertyChangeListenerProxy("b",addAProxiedB));
  assertEquals(2,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener(proxyAB);
  assertEquals(1,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener(proxiedAAC);
  support.removePropertyChangeListener(new PropertyChangeListenerProxy("a",proxiedAAC));
  support.removePropertyChangeListener("a",new PropertyChangeListenerProxy("c",proxiedAAC));
  support.removePropertyChangeListener("a",new PropertyChangeListenerProxy("c",new PropertyChangeListenerProxy("a",proxiedAAC)));
  assertEquals(1,support.getPropertyChangeListeners().length);
  support.removePropertyChangeListener("a",new PropertyChangeListenerProxy("a",new PropertyChangeListenerProxy("c",proxiedAAC)));
  assertEquals(0,support.getPropertyChangeListeners().length);
}

public void testRemoveWithProxies ( ) { Object bean = new Object ( ) ; PropertyChangeSupport support = new PropertyChangeSupport ( bean ) ; EventLog all = new EventLog ( ) ; support . addPropertyChangeListener ( all ) ; assertEquals ( 1 , support . getPropertyChangeListeners ( ) . length ) ; EventLog proxiedA = new EventLog ( ) ; support . addPropertyChangeListener ( new PropertyChangeListenerProxy ( "a" , proxiedA ) ) ; assertEquals ( 2 , support . getPropertyChangeListeners ( ) . length ) ; EventLog addA = new EventLog ( ) ; support . addPropertyChangeListener ( "a" , addA ) ; assertEquals ( 3 , support . getPropertyChangeListeners ( ) . length ) ; EventLog addAProxiedB = new EventLog ( ) ; support . addPropertyChangeListener ( "a" , new PropertyChangeListenerProxy ( "b" , addAProxiedB ) ) ; assertEquals ( 4 , support . getPropertyChangeListeners ( ) . length ) ; EventLog proxiedAB = new EventLog ( ) ; PropertyChangeListenerProxy proxyAB = new PropertyChangeListenerProxy ( "a" , new PropertyChangeListenerProxy ( "b" , proxiedAB ) ) ; support . addPropertyChangeListener ( proxyAB ) ; assertEquals ( 5 , support . getPropertyChangeListeners ( ) . length ) ; EventLog proxiedAAC = new EventLog ( ) ; support . addPropertyChangeListener ( new PropertyChangeListenerProxy ( "a" , new PropertyChangeListenerProxy ( "a" , new PropertyChangeListenerProxy ( "c" , proxiedAAC ) ) ) ) ; assertEquals ( 6 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( all ) ; assertEquals ( 5 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( "a" , proxiedA ) ; assertEquals ( 4 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( new PropertyChangeListenerProxy ( "a" , addA ) ) ; assertEquals ( 3 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( "a" , new PropertyChangeListenerProxy ( "b" , addAProxiedB ) ) ; assertEquals ( 2 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( proxyAB ) ; assertEquals ( 1 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( proxiedAAC ) ; support . removePropertyChangeListener ( new PropertyChangeListenerProxy ( "a" , proxiedAAC ) ) ; support . removePropertyChangeListener ( "a" , new PropertyChangeListenerProxy ( "c" , proxiedAAC ) ) ; support . removePropertyChangeListener ( "a" , new PropertyChangeListenerProxy ( "c" , new PropertyChangeListenerProxy ( "a" , proxiedAAC ) ) ) ; assertEquals ( 1 , support . getPropertyChangeListeners ( ) . length ) ; support . removePropertyChangeListener ( "a" , new PropertyChangeListenerProxy ( "a" , new PropertyChangeListenerProxy ( "c" , proxiedAAC ) ) ) ; assertEquals ( 0 , support . getPropertyChangeListeners ( ) . length ) ; }
test that we need to do our own equals ( ) work to manually unwrap an arbitrary number of proxies .
