### Question:
DefaultPluginRegistry implements PluginRegistry { @SuppressWarnings("unchecked") public <T> T lookupPlugin(Class<T> pluginType) { List<T> plugins = (List<T>)pluginMap.get(pluginType); if (plugins == null) { throw new WicketRuntimeException("Plugin of type " + pluginType.getName() + " not found."); } if (plugins.size() == 1) { return plugins.get(0); } throw new WicketRuntimeException("There are " + plugins.size() + " plugins registered of type " + pluginType.getName() + "."); } DefaultPluginRegistry(); @SuppressWarnings("unchecked") T lookupPlugin(Class<T> pluginType); void registerPlugin(Object plugin); Set<Class<?>> getStopClasses(); void setStopClasses(Set<Class<?>> stopClasses); List<Class<?>> getAllClasses(Class<?> cls); public Map<Class<?>, List<Object>> pluginMap; }### Answer:
@Test public void testLookupPluginByClassHierarchy() { assertSame(registry.lookupPlugin(PluginB.class), registeredPlugin); assertSame(registry.lookupPlugin(PluginA.class), registeredPlugin); try { registry.lookupPlugin(Object.class); fail("Should not be able to lookup by a class registered as a stop class!"); } catch (WicketRuntimeException e) { } }
@Test public void testLookupPluginByInterface() { assertSame(registry.lookupPlugin(IPlugin.class), registeredPlugin); try { registry.lookupPlugin(Serializable.class); fail("Should not be able to lookup by an interface registered as a stop class!"); } catch (WicketRuntimeException e) { } }