@Test
@SuppressWarnings("unchecked")
public void testAddingBundleWithBundleClassPath() throws Exception {

    Bundle mediatorBundle = EasyMock.createMock(Bundle.class);
    EasyMock.expect(mediatorBundle.getBundleId()).andReturn(42l).anyTimes();
    EasyMock.replay(mediatorBundle);
    ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(activator, mediatorBundle);
    BundleContext implBC = EasyMock.createMock(BundleContext.class);
    EasyMock.<Object>expect(implBC.registerService(
            EasyMock.eq("org.apache.aries.mytest.MySPI"),
            EasyMock.isA(ServiceFactory.class),
            (Dictionary<String,?>) EasyMock.anyObject())).andReturn(EasyMock.createNiceMock(ServiceRegistration.class)).times(3);
    EasyMock.replay(implBC);
    Bundle implBundle = EasyMock.createNiceMock(Bundle.class);
    EasyMock.expect(implBundle.getBundleContext()).andReturn(implBC).anyTimes();
    Dictionary<String, String> headers = new Hashtable<String, String>();
    headers.put(SpiFlyConstants.SPI_PROVIDER_HEADER, "*");
    headers.put(Constants.BUNDLE_CLASSPATH, ".,non-jar.jar,embedded.jar,embedded2.jar");
    EasyMock.expect(implBundle.getHeaders()).andReturn(headers).anyTimes();
    URL embeddedJar = getClass().getResource("/embedded.jar");
    assertNotNull("precondition", embeddedJar);
    EasyMock.expect(implBundle.getResource("embedded.jar")).andReturn(embeddedJar).anyTimes();
    URL embedded2Jar = getClass().getResource("/embedded2.jar");
    assertNotNull("precondition", embedded2Jar);
    EasyMock.expect(implBundle.getResource("embedded2.jar")).andReturn(embedded2Jar).anyTimes();
    URL dir = new URL("jar:" + embeddedJar + "!/META-INF/services");
    assertNotNull("precondition", dir);
    EasyMock.expect(implBundle.getResource("/META-INF/services")).andReturn(dir).anyTimes();
    EasyMock.expect(implBundle.findEntries((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), EasyMock.anyBoolean())).
        andReturn(null).anyTimes();
    ClassLoader cl = new URLClassLoader(new URL [] {embeddedJar}, getClass().getClassLoader());
    Class<?> clsA = cl.loadClass("org.apache.aries.spifly.impl2.MySPIImpl2a");
    EasyMock.<Object>expect(implBundle.loadClass("org.apache.aries.spifly.impl2.MySPIImpl2a")).andReturn(clsA).anyTimes();
    Class<?> clsB = cl.loadClass("org.apache.aries.spifly.impl2.MySPIImpl2b");
    EasyMock.<Object>expect(implBundle.loadClass("org.apache.aries.spifly.impl2.MySPIImpl2b")).andReturn(clsB).anyTimes();
    ClassLoader cl2 = new URLClassLoader(new URL [] {embedded2Jar}, getClass().getClassLoader());
    Class<?> clsC = cl2.loadClass("org.apache.aries.spifly.impl3.MySPIImpl3");
    EasyMock.<Object>expect(implBundle.loadClass("org.apache.aries.spifly.impl3.MySPIImpl3")).andReturn(clsC).anyTimes();
    EasyMock.replay(implBundle);
    assertEquals("Precondition", 0, activator.findProviderBundles("org.apache.aries.mytest.MySPI").size());
    // Call addingBundle();
    List<ServiceRegistration> registrations = customizer.addingBundle(implBundle, null);
    Collection<Bundle> bundles = activator.findProviderBundles("org.apache.aries.mytest.MySPI");
    assertEquals(1, bundles.size());
    assertSame(implBundle, bundles.iterator().next());
    // The bc.registerService() call should now have been made
    EasyMock.verify(implBC);
}