EnOceanGateway implements RadioInterface, RadioTelegramListener { @Override public void removeRadioListener(DeviceID deviceID, RadioTelegramListener listener) { CopyOnWriteArraySet<RadioTelegramListener> listenerList = null; listenerList = radioListeners.get(deviceID); if(listenerList != null) { listenerList.remove(listener); } } EnOceanGateway(EnOceanConnectionManager mgr, EspPortConfiguration config); void sendRadio(EspRadioTelegram.RORG rorg, DeviceID deviceID, byte[] payload, byte statusByte); void addRadioListener(DeviceID deviceID, RadioTelegramListener listener); @Override void removeRadioListener(DeviceID deviceID, RadioTelegramListener listener); @Override void radioTelegramReceived(EspRadioTelegram telegram); void connect(); void disconnect();  }
@Test public void testRemoveRadioListener() throws Exception { DeviceID id = DeviceID.fromString("0xFF800001"); TestRadioListener listener1 = new TestRadioListener(); TestRadioListener listener2 = new TestRadioListener(); Esp3RPSTelegram telegram = new Esp3RPSTelegram(id, (byte)0x00, (byte)0x00); EnOceanGateway gateway = new EnOceanGateway(new EnOceanConnectionManager(), new EspPortConfiguration()); gateway.addRadioListener(id, listener1); gateway.addRadioListener(id, listener2); gateway.removeRadioListener(id, listener1); gateway.radioTelegramReceived(telegram); Assert.assertNull(listener1.receivedTelegram); Assert.assertEquals(id, listener2.receivedTelegram.getSenderID()); Assert.assertEquals(1, listener2.receiveCount); gateway.addRadioListener(id, listener1); gateway.radioTelegramReceived(telegram); Assert.assertEquals(id, listener1.receivedTelegram.getSenderID()); Assert.assertEquals(1, listener1.receiveCount); Assert.assertEquals(id, listener2.receivedTelegram.getSenderID()); Assert.assertEquals(2, listener2.receiveCount); gateway.removeRadioListener(id, listener1); gateway.removeRadioListener(id, listener2); gateway.radioTelegramReceived(telegram); Assert.assertEquals(id, listener1.receivedTelegram.getSenderID()); Assert.assertEquals(1, listener1.receiveCount); Assert.assertEquals(id, listener2.receivedTelegram.getSenderID()); Assert.assertEquals(2, listener2.receiveCount); gateway.addRadioListener(id, listener1); gateway.addRadioListener(id, listener2); gateway.radioTelegramReceived(telegram); Assert.assertEquals(id, listener1.receivedTelegram.getSenderID()); Assert.assertEquals(2, listener1.receiveCount); Assert.assertEquals(id, listener2.receivedTelegram.getSenderID()); Assert.assertEquals(3, listener2.receiveCount); }