}
@Test
public void testServiceWithExpectedObjectsDifferentClassLoaders() throws Exception
{
AddonRegistry addonRegistry = SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
AddonId depOneId = AddonId.from("test:dep1", "1");
AddonId depTwoId = AddonId.from("test:dep2", "2");
Addon depOne = addonRegistry.getAddon(depOneId);
Addon depTwo = addonRegistry.getAddon(depTwoId);
ServiceRegistry depOneServiceRegistry = depOne.getServiceRegistry();
ServiceRegistry depTwoServiceRegistry = depTwo.getServiceRegistry();
Assert.assertTrue(depOneServiceRegistry.hasService(PublishedService.class));
Assert.assertFalse(depOneServiceRegistry.hasService(PublishedServiceSubtype.class));
Assert.assertTrue(depTwoServiceRegistry.hasService(PublishedService.class));
Assert.assertTrue(depTwoServiceRegistry.hasService(PublishedServiceSubtype.class));
Assert.assertNotNull(depOneServiceRegistry.getExportedInstance(PublishedService.class.getName()));
Assert.assertNotNull(depTwoServiceRegistry.getExportedInstance(PublishedService.class.getName()));
Assert.assertNull(depOneServiceRegistry.getExportedInstance(PublishedServiceSubtype.class.getName()));
Assert.assertNotNull(depTwoServiceRegistry.getExportedInstance(PublishedServiceSubtype.class.getName()));
Imported<PublishedService> services = addonRegistry.getServices(PublishedService.class);
Assert.assertFalse("Imported<PublishedService> should have been satisfied", services.isUnsatisfied());
Assert.assertTrue("Imported<PublishedService> should have been ambiguous", services.isAmbiguous());
Iterator<PublishedService> iterator = services.iterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertThat(iterator.next(), is(instanceOf(PublishedService.class)));
Assert.assertTrue(iterator.hasNext());
Assert.assertThat(iterator.next(), is(instanceOf(PublishedService.class)));
Imported<PublishedServiceSubtype> services2 = addonRegistry.getServices(PublishedServiceSubtype.class);
Assert.assertFalse("Imported<PublishedServiceSubtype> should have been satisfied", services2.isUnsatisfied());
Assert.assertFalse("Imported<PublishedServiceSubtype> should not have been ambiguous", services2.isAmbiguous());
Iterator<PublishedServiceSubtype> iterator2 = services2.iterator();
Assert.assertTrue(iterator2.hasNext());
Assert.assertThat(iterator2.next(), is(instanceOf(PublishedServiceSubtype.class)));