@Test
public void testPreExistingBundles() throws Exception {

    Bundle b1 = EasyMock.createMock(Bundle.class);
    EasyMock.expect(b1.getState()).andReturn(Bundle.RESOLVED);
    EasyMock.replay(b1);
    Bundle b2 = EasyMock.createMock(Bundle.class);
    EasyMock.expect(b2.getState()).andReturn(Bundle.ACTIVE);
    Dictionary<String, String> headers = new Hashtable<>();
    headers.put("Remote-Service", "OSGI-INF/remote-service/");
    EasyMock.expect(b2.getHeaders()).andReturn(headers);
    URL rs3URL = getClass().getResource("/ed3.xml");
    URL rs4URL = getClass().getResource("/ed4.xml");
    List<URL> urls = Arrays.asList(rs3URL, rs4URL);
    EasyMock.expect(b2.findEntries("OSGI-INF/remote-service", "*.xml", false))
        .andReturn(Collections.enumeration(urls));
    EasyMock.replay(b2);
    Bundle[] bundles = {b1, b2};
    LocalDiscovery ld = new LocalDiscovery();
    ld.processExistingBundles(bundles);
    assertEquals(3, ld.endpointDescriptions.size());
    Set<String> expected = new HashSet<>(
        Arrays.asList("http://somewhere:12345", "http://somewhere:1", "http://somewhere"));
    Set<String> actual = new HashSet<>();
    for (Map.Entry<EndpointDescription, Bundle> entry : ld.endpointDescriptions.entrySet()) {
        assertSame(b2, entry.getValue());
        actual.add(entry.getKey().getId());
    }
    assertEquals(expected, actual);
}