@Test
public void testBundleChanged() throws Exception {

    LocalDiscovery ld = new LocalDiscovery();
    Bundle bundle = EasyMock.createMock(Bundle.class);
    EasyMock.expect(bundle.getSymbolicName()).andReturn("testing.bundle").anyTimes();
    EasyMock.expect(bundle.getState()).andReturn(Bundle.ACTIVE);
    Dictionary<String, String> headers = new Hashtable<>();
    headers.put("Remote-Service", "OSGI-INF/rsa/");
    EasyMock.expect(bundle.getHeaders()).andReturn(headers);
    EasyMock.expect(bundle.findEntries("OSGI-INF/rsa", "*.xml", false))
        .andReturn(Collections.enumeration(
            Collections.singleton(getClass().getResource("/ed3.xml"))));
    EasyMock.replay(bundle);
    BundleEvent be0 = new BundleEvent(BundleEvent.INSTALLED, bundle);
    ld.bundleChanged(be0);
    assertEquals(0, ld.endpointDescriptions.size());
    ServiceReference<EndpointEventListener> sr = epListenerWithScope("(objectClass=*)");
    EndpointEventListener endpointListener = EasyMock.createMock(EndpointEventListener.class);
    endpointListener.endpointChanged(EasyMock.anyObject(EndpointEvent.class), EasyMock.eq("(objectClass=*)"));
    EasyMock.expectLastCall();
    EasyMock.replay(endpointListener);
    ld.bindListener(sr, endpointListener);
    // Start the bundle
    BundleEvent be = new BundleEvent(BundleEvent.STARTED, bundle);
    ld.bundleChanged(be);
    assertEquals(1, ld.endpointDescriptions.size());
    EndpointDescription endpoint = ld.endpointDescriptions.keySet().iterator().next();
    assertEquals("http://somewhere:12345", endpoint.getId());
    assertSame(bundle, ld.endpointDescriptions.get(endpoint));
    EasyMock.verify(endpointListener);
    // Stop the bundle
    EasyMock.reset(endpointListener);
    endpointListener.endpointChanged(EasyMock.anyObject(EndpointEvent.class), EasyMock.eq("(objectClass=*)"));
    EasyMock.expectLastCall();
    EasyMock.replay(endpointListener);
    BundleEvent be1 = new BundleEvent(BundleEvent.STOPPED, bundle);
    ld.bundleChanged(be1);
    assertEquals(0, ld.endpointDescriptions.size());
    EasyMock.verify(endpointListener);
}