@Test public void testNameLookupReturnsAllMatches() throws Exception { AddonRegistry registry = SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry(); Imported<PublishedService> instance = registry.getServices(PublishedService.class.getName()); Assert.assertTrue(instance.isAmbiguous()); Assert.assertFalse(instance.isUnsatisfied()); Assert.assertNotNull(instance); Iterator<PublishedService> iterator = instance.iterator(); Assert.assertTrue(iterator.hasNext()); Object first = iterator.next(); Assert.assertNotNull(first); Assert.assertTrue(iterator.hasNext()); Assert.assertTrue(iterator.hasNext()); Object second = iterator.next(); Assert.assertNotNull(second); Assert.assertFalse(iterator.hasNext()); boolean typeMatchFound = false; if (first instanceof PublishedService) typeMatchFound = true; if (second instanceof PublishedService) typeMatchFound = true; Assert.assertTrue(typeMatchFound); }
@Test public void testTypedLookupCanBeIterated() throws Exception { AddonRegistry registry = SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry(); Imported<PublishedService> instance = registry.getServices(PublishedService.class); Assert.assertFalse(instance.isAmbiguous()); Assert.assertFalse(instance.isUnsatisfied()); Iterator<PublishedService> iterator = instance.iterator(); Assert.assertTrue(iterator.hasNext()); Assert.assertNotNull(iterator.next()); Assert.assertFalse(iterator.hasNext()); }