ExtensionLoader { public T getOrDefaultExtension(String name) { return containsExtension(name) ? getExtension(name) : getDefaultExtension(); } private  ExtensionLoader(Class<?> type); static void setLoadingStrategies(LoadingStrategy... strategies); static List<LoadingStrategy> getLoadingStrategies(); @SuppressWarnings("unchecked") static ExtensionLoader<T> getExtensionLoader(Class<T> type); static void resetExtensionLoader(Class type); static void destroyAll(); String getExtensionName(T extensionInstance); String getExtensionName(Class<?> extensionClass); List<T> getActivateExtension(URL url, String key); List<T> getActivateExtension(URL url, String[] values); List<T> getActivateExtension(URL url, String key, String group); List<T> getActivateExtension(URL url, String[] values, String group); @SuppressWarnings("unchecked") T getLoadedExtension(String name); Set<String> getLoadedExtensions(); List<T> getLoadedExtensionInstances(); Object getLoadedAdaptiveExtensionInstances(); @SuppressWarnings("unchecked") T getExtension(String name); T getExtension(String name, boolean wrap); T getOrDefaultExtension(String name); T getDefaultExtension(); boolean hasExtension(String name); Set<String> getSupportedExtensions(); Set<T> getSupportedExtensionInstances(); String getDefaultExtensionName(); void addExtension(String name, Class<?> clazz); @Deprecated void replaceExtension(String name, Class<?> clazz); @SuppressWarnings("unchecked") T getAdaptiveExtension(); @Override String toString();  }
@Test public void testGetOrDefaultExtension() { ExtensionLoader<InjectExt> loader = getExtensionLoader(InjectExt.class); InjectExt injectExt = loader.getOrDefaultExtension("non-exists"); assertEquals(InjectExtImpl.class, injectExt.getClass()); assertEquals(InjectExtImpl.class, loader.getOrDefaultExtension("injection").getClass()); }