@Test
public void testUpdateQueue() throws Exception {

    class DummySwitchListener implements IOFSwitchListener {
        public int nAdded;
        public int nRemoved;
        public int nPortChanged;
        public DummySwitchListener() {
            nAdded = 0;
            nRemoved = 0;
            nPortChanged = 0;
        }
        public synchronized void addedSwitch(IOFSwitch sw) {
            nAdded++;
            notifyAll();
        }
        public synchronized void removedSwitch(IOFSwitch sw) {
            nRemoved++;
            notifyAll();
        }
        public String getName() {
            return "dummy";
        }
        @Override
        public void switchPortChanged(Long switchId) {
            nPortChanged++;
            notifyAll();
        }
    }
    DummySwitchListener switchListener = new DummySwitchListener();
    IOFSwitch sw = createMock(IOFSwitch.class);
    ControllerRunThread t = new ControllerRunThread();
    t.start();
    
    controller.addOFSwitchListener(switchListener);
    synchronized(switchListener) {
        controller.updates.put(controller.new SwitchUpdate(sw,
                                  Controller.SwitchUpdateType.ADDED));
        switchListener.wait(500);
        assertTrue("IOFSwitchListener.addedSwitch() was not called", 
                switchListener.nAdded == 1);
        controller.updates.put(controller.new SwitchUpdate(sw, 
                                  Controller.SwitchUpdateType.REMOVED));
        switchListener.wait(500);
        assertTrue("IOFSwitchListener.removedSwitch() was not called", 
                switchListener.nRemoved == 1);
        controller.updates.put(controller.new SwitchUpdate(sw, 
                                  Controller.SwitchUpdateType.PORTCHANGED));
        switchListener.wait(500);
        assertTrue("IOFSwitchListener.switchPortChanged() was not called", 
                switchListener.nPortChanged == 1);
    }
}