@Test
public void testSwitchAdded() throws Exception {

    LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
    linkDiscovery.switchService = getMockSwitchService();
    Capture<OFMessage> wc;
    Set<OFPort> qPorts;
    OFPortDesc ofpp = OFFactories.getFactory(OFVersion.OF_13).buildPortDesc()
    .setName("eth4242")
    .setPortNo(OFPort.of(4242))
    .setHwAddr(MacAddress.of("5c:16:c7:00:00:01"))
    .setCurr(new HashSet<OFPortFeatures>()) // random
    .build();
    IOFSwitch sw1 = createMockSwitch(1L);
    // Set switch map in floodlightProvider.
    Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>();
    switches.put(DatapathId.of(1L), sw1);
    getMockSwitchService().setSwitches(switches);
    // Create the set of ports
    List<OFPort> ports = new ArrayList<OFPort>();
    for(short p=1; p<=20; ++p) {
        ports.add(OFPort.of(p));
    }
    // Set the captures.
    wc = new Capture<OFMessage>(CaptureType.ALL);
    // Expect switch to return those ports.
    expect(sw1.getEnabledPortNumbers()).andReturn(ports).anyTimes();
    expect(sw1.getPort(OFPort.of(EasyMock.anyInt()))).andReturn(ofpp).anyTimes();
    expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    expect(sw1.getLatency()).andReturn(U64.ZERO).anyTimes();
    expect(sw1.write(capture(wc))).andReturn(true).anyTimes();
    replay(sw1);
    linkDiscovery.switchActivated(sw1.getId());
    verify(sw1);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());
    Thread.sleep(100);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());
    Thread.sleep(200);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertTrue(qPorts.isEmpty());
    // Ensure that through every switch port, an LLDP and BDDP
    // packet was sent out.  Total # of packets = # of ports * 2.
    assertTrue(wc.hasCaptured());
    List<OFMessage> msgList = wc.getValues();
    assertTrue(msgList.size() == ports.size() * 2);
}