public ImageStrip[] get(final Annotation... qualifiers) { final List<ImageStrip> result = new LinkedList<>(); for (Annotation qualifier : qualifiers) { final ManagedInstance<ImageStrip> i = stripInstances.select(qualifier); if (!i.isUnsatisfied() && !i.isAmbiguous()) { result.add(i.get()); } } return result.toArray(new ImageStrip[result.size()]); }
public ImageStrip get(final Class<? extends ImageStrip> stripType) { final ManagedInstance<? extends ImageStrip> i = stripInstances.select(stripType); if (!i.isUnsatisfied() && !i.isAmbiguous()) { return i.get(); } return null; }
@Test(expected = RuntimeException.class) public void setupWithMoreThanOneMegaMenuBrandImplementationTest() { doReturn(true).when(megaMenuBrands).isAmbiguous(); presenter.setup(); }
@Test(expected = RuntimeException.class) public void setupWithMoreThanOneMegaMenuBrandImplementationTest() { doReturn(true).when(megaMenuBrands).isAmbiguous(); presenter.setup(); }
@PostConstruct public void setup() { view.init(this); if (aboutPopupConfigs.isUnsatisfied()) { throw new RuntimeException("One AboutPopupConfig implementation must be provided"); } if (aboutPopupConfigs.isAmbiguous()) { throw new RuntimeException("Only one AboutPopupConfig implementation must be provided"); } final AboutPopupConfig aboutPopupConfig = aboutPopupConfigs.get(); view.setProductName(aboutPopupConfig.productName()); view.setProductVersion(aboutPopupConfig.productVersion()); view.setProductLicense(aboutPopupConfig.productLicense()); view.setProductImageUrl(aboutPopupConfig.productImageUrl()); final String backgroundImageUrl = aboutPopupConfig.backgroundImageUrl(); if (backgroundImageUrl != null && !backgroundImageUrl.isEmpty()) { view.setBackgroundImageUrl(backgroundImageUrl); } }
@Test public void setupWithOneEmptyMegaMenuBrandImplementationTest() { doReturn(false).when(megaMenuBrands).isAmbiguous(); doReturn(false).when(megaMenuBrands).isUnsatisfied(); final MegaMenuBrandMock megaMenuBrand = new MegaMenuBrandMock("", "", ""); doReturn(megaMenuBrand).when(megaMenuBrands).get(); doReturn("defaultMenuText").when(view).getDefaultMenuText(); presenter.setup(); verify(view, never()).setBrandImage(anyString()); verify(view, never()).setBrandImageTitle(anyString()); verify(view).hideBrand(); verify(view).setMenuAccessorText(view.getDefaultMenuText()); }
@Test public void setupWithOneEmptyMegaMenuBrandImplementationTest() { doReturn(false).when(megaMenuBrands).isAmbiguous(); doReturn(false).when(megaMenuBrands).isUnsatisfied(); final MegaMenuBrandMock megaMenuBrand = new MegaMenuBrandMock("", "", ""); doReturn(megaMenuBrand).when(megaMenuBrands).get(); doReturn("defaultMenuText").when(view).getDefaultMenuText(); presenter.setup(); verify(view, never()).setBrandImage(anyString()); verify(view, never()).setBrandImageTitle(anyString()); verify(view).hideBrand(); verify(view).setMenuAccessorText(view.getDefaultMenuText()); }
@Test public void setupWithOneMegaMenuBrandImplementationTest() { doReturn(false).when(megaMenuBrands).isAmbiguous(); doReturn(false).when(megaMenuBrands).isUnsatisfied(); final MegaMenuBrandMock megaMenuBrand = new MegaMenuBrandMock("brandImageUrl", "brandImageLabel", "menuAccessorLabel"); doReturn(megaMenuBrand).when(megaMenuBrands).get(); doReturn("defaultMenuText").when(view).getDefaultMenuText(); presenter.setup(); verify(view).setBrandImage(megaMenuBrand.brandImageUrl()); verify(view).setBrandImageTitle(megaMenuBrand.brandImageLabel()); verify(view, never()).hideBrand(); verify(view).setMenuAccessorText(megaMenuBrand.menuAccessorLabel()); }
public void testResolvesAllWithAnyQualifier() throws Exception { final List<DestructableClass> beans = fromIterator(module.any.iterator()); assertTrue(module.any.isAmbiguous()); assertEquals(4, beans.size()); }
@Test public void setupWithOneMegaMenuBrandImplementationTest() { doReturn(false).when(megaMenuBrands).isAmbiguous(); doReturn(false).when(megaMenuBrands).isUnsatisfied(); final MegaMenuBrandMock megaMenuBrand = new MegaMenuBrandMock("brandImageUrl", "brandImageLabel", "menuAccessorLabel"); doReturn(megaMenuBrand).when(megaMenuBrands).get(); doReturn("defaultMenuText").when(view).getDefaultMenuText(); presenter.setup(); verify(view).setBrandImage(megaMenuBrand.brandImageUrl()); verify(view).setBrandImageTitle(megaMenuBrand.brandImageLabel()); verify(view, never()).hideBrand(); verify(view).setMenuAccessorText(megaMenuBrand.menuAccessorLabel()); }
private void setupBrand() { final String defaultMenuText = view.getDefaultMenuText(); if (megaMenuBrands.isAmbiguous()) { throw new RuntimeException("Multiple implementations of MegaMenuBrand were provided."); } if (!megaMenuBrands.isUnsatisfied()) { final MegaMenuBrand megaMenuBrand = megaMenuBrands.get(); final String brandImageUrl = megaMenuBrand.brandImageUrl(); if (brandImageUrl != null && !brandImageUrl.isEmpty()) { view.setBrandImage(brandImageUrl); final String brandImageLabel = megaMenuBrand.brandImageLabel(); if (brandImageLabel != null && !brandImageLabel.isEmpty()) { view.setBrandImageTitle(brandImageLabel); } } else { view.hideBrand(); } final String menuAccessorLabel = megaMenuBrand.menuAccessorLabel(); if (menuAccessorLabel != null && !menuAccessorLabel.isEmpty()) { view.setMenuAccessorText(menuAccessorLabel); } else { view.setMenuAccessorText(defaultMenuText); } } else { view.hideBrand(); view.setMenuAccessorText(defaultMenuText); } }
public void testSelectingSubtypeResolution() throws Exception { final ManagedInstance<DefaultDependentBean> selectedInstance = module.any.select(DefaultDependentBean.class); final List<DefaultDependentBean> beans = fromIterator(selectedInstance.iterator()); assertFalse(selectedInstance.isAmbiguous()); assertFalse(selectedInstance.isUnsatisfied()); assertEquals(1, beans.size()); assertTrue(beans.iterator().next().isDependent()); assertTrue(beans.iterator().next().isDefault()); }
public void testResolvesDefaultWithNoExplicitQualifiers() throws Exception { final List<DestructableClass> beans = fromIterator(module.defaultOnly.iterator()); assertTrue(module.defaultOnly.isAmbiguous()); assertEquals(2, beans.size()); for (final DestructableClass instance : beans) { assertTrue(getSimpleName(instance) + " is not @Default but was resolved.", instance.isDefault()); } }
public void testDoesNotResolveDefaultWithOtherQualifier() throws Exception { final List<DestructableClass> beans = fromIterator(module.aOnly.iterator()); assertTrue(module.aOnly.isAmbiguous()); assertEquals(2, beans.size()); for (final DestructableClass instance : beans) { assertFalse(getSimpleName(instance) + " is @Default but was resolved.", instance.isDefault()); } }
public void testSelectingQualifierResolution() throws Exception { final ManagedInstance<DestructableClass> selectedInstance = module.any.select(a); final List<DestructableClass> beans = fromIterator(selectedInstance.iterator()); assertTrue(selectedInstance.isAmbiguous()); assertEquals(2, beans.size()); for (final DestructableClass instance : beans) { assertFalse(getSimpleName(instance) + " is @Default but was resolved.", instance.isDefault()); } }
public void testDestroyAllOnSelectedSubtypeDoesNotAffectInjectedOrOtherSelectedInstances() throws Exception { final ManagedInstance<DefaultDependentBean> defaultDepBeanInstance = module.any.select(DefaultDependentBean.class); assertFalse("ManagedInstance<DefaultDependentBean> should not be ambiguous.", defaultDepBeanInstance.isAmbiguous()); assertFalse("ManagedInstance<DefaultDependentBean> should not be unsatisfied.", defaultDepBeanInstance.isUnsatisfied()); final DefaultDependentBean subtypeInstance = defaultDepBeanInstance.get(); assertFalse(getSimpleName(subtypeInstance) + " was destroyed before destroyAll was called.", subtypeInstance.isDestroyed()); final List<DestructableClass> anyBeans = fromIterator(module.any.iterator()); assertEquals(4, anyBeans.size()); for (final DestructableClass instance : anyBeans) { assertFalse(getSimpleName(instance) + " was destroyed before destroyAll was called.", instance.isDestroyed()); } defaultDepBeanInstance.destroyAll(); assertTrue(getSimpleName(subtypeInstance) + " was not destroyed after destroyAll was called.", subtypeInstance.isDestroyed()); for (final DestructableClass instance : anyBeans) { assertFalse(getSimpleName(instance) + " was destroyed after destroyAll was called on subtype instance.", instance.isDestroyed()); } }