@Test (dataProvider="assetTestCases") public <T> void testGetAsset(int count, int found, T asset, Class<T> clazz) { ComponentProvider mockDefaultProvider = Mockito.mock(ComponentProvider.class); ExtendedComponentProvider mockProviders[] = new ExtendedComponentProvider[count]; TypeInfo<?> mockTypeInfo = Mockito.mock(TypeInfo.class); for (int i = 0; i < count; i++) { mockProviders[i] = Mockito.mock(ExtendedComponentProvider.class, "provider" + i); } if (found < count) { Mockito.when(mockProviders[found].getAsset(mockTypeInfo, clazz)).thenReturn(asset); } else if (found == count) { Mockito.when(mockDefaultProvider.getAsset(mockTypeInfo, clazz)).thenReturn(asset); } registry.setDefaultViewProvider(mockDefaultProvider); registry.refreshComponents(Arrays.asList(mockProviders)); Object actual = registry.getAsset(mockTypeInfo, asset.getClass()); if (found <= count) { Assert.assertEquals(actual, asset); } else { Assert.assertNull(actual); } for (int i = 0; i <= found && i < count; i++) { Mockito.verify(mockProviders[i]).getAsset(mockTypeInfo, clazz); } for (int i = found + 1; i < count; i++) { Mockito.verify(mockProviders[i], Mockito.never()).getAsset(mockTypeInfo, clazz); } if (found >= count) { Mockito.verify(mockDefaultProvider).getAsset(mockTypeInfo, clazz); } else { Mockito.verify(mockDefaultProvider, Mockito.never()).getAsset(mockTypeInfo, clazz); } }
@Override public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass) { for (ExtendedComponentProvider provider : activeProviders.get()) { T asset = provider.getAsset(objectType, assetClass); if (asset != null) { return asset; } } return defaultViewProvider.get().getAsset(objectType, assetClass); }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass) { for (ExtendedComponentProvider provider : activeProviders.get()) { T asset = provider.getAsset(objectType, assetClass); if (asset != null) { return asset; } } return defaultViewProvider.get().getAsset(objectType, assetClass); } }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass) { for (ExtendedComponentProvider provider : activeProviders.get()) { T asset = provider.getAsset(objectType, assetClass); if (asset != null) { return asset; } } return defaultViewProvider.get().getAsset(objectType, assetClass); } ExternalComponentRegistryImpl(); }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass) { for (ExtendedComponentProvider provider : activeProviders.get()) { T asset = provider.getAsset(objectType, assetClass); if (asset != null) { return asset; } } return defaultViewProvider.get().getAsset(objectType, assetClass); } ExternalComponentRegistryImpl(); static ExternalComponentRegistryImpl getInstance(); @Override Set<ViewInfo> getViewInfos(String componentTypeId, ViewType type); Collection<ExtendedComponentTypeInfo> getComponentInfos(); @Override T getAsset(TypeInfo<?> objectType, Class<T> assetClass); void setDefaultViewProvider(ComponentProvider provider); @Override AbstractComponent newInstance(ComponentTypeInfo componentTypeInfo); @Override AbstractComponent newCollection(Collection<AbstractComponent> components); @Override T newInstance(Class<T> componentClass, AbstractComponent parent); void refreshComponents(List<ExtendedComponentProvider> providers); @Override AbstractComponent getComponent(String id); @Override boolean isCreatable(Class<?> clazz); @Override AbstractComponent newInstance(String componentType); }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass) { for (ExtendedComponentProvider provider : activeProviders.get()) { T asset = provider.getAsset(objectType, assetClass); if (asset != null) { return asset; } } return defaultViewProvider.get().getAsset(objectType, assetClass); } ExternalComponentRegistryImpl(); static ExternalComponentRegistryImpl getInstance(); @Override Set<ViewInfo> getViewInfos(String componentTypeId, ViewType type); Collection<ExtendedComponentTypeInfo> getComponentInfos(); @Override T getAsset(TypeInfo<?> objectType, Class<T> assetClass); void setDefaultViewProvider(ComponentProvider provider); @Override AbstractComponent newInstance(ComponentTypeInfo componentTypeInfo); @Override AbstractComponent newCollection(Collection<AbstractComponent> components); @Override T newInstance(Class<T> componentClass, AbstractComponent parent); void refreshComponents(List<ExtendedComponentProvider> providers); @Override AbstractComponent getComponent(String id); @Override boolean isCreatable(Class<?> clazz); @Override AbstractComponent newInstance(String componentType); static final byte USER_DEFINED_GROUP_PERMISSION; }