### Question:
CommandLineUtil { public static List<Extension> loadExtensions(ClassLoader classLoader, List<ExtendedArgument> arguments) { List<Extension> results = new ArrayList<>(); ServiceLoader<ExtensionHandler> services = ServiceLoader.load(ExtensionHandler.class, classLoader); for (ExtendedArgument argument : arguments) { String name = argument.getName(); String value = argument.getValue(); boolean consumed = false; for (ExtensionHandler handler : services) { try { Extension extension = handler.handle(name, value); if (extension != null) { results.add(extension); consumed = true; break; } } catch (IOException e) { YSLOG.error(e, "E99001", name, value); for (Extension ext : results) { try { ext.close(); } catch (IOException inner) { e.addSuppressed(inner); } } throw new IllegalArgumentException(MessageFormat.format( "invalid extended argument \"{0}\"", argument), e); } } if (consumed == false) { YSLOG.error("E99001", name, value); throw new IllegalArgumentException(MessageFormat.format( "there is no available extension handler \"{0}\"", argument)); } } return results; } private  CommandLineUtil(); static void prepareLogContext(); static Properties loadProperties(File path); static List<File> parseFileList(String fileListOrNull); static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files); static List<Extension> loadExtensions(ClassLoader classLoader, List<ExtendedArgument> arguments); static final String LOG_CONTEXT_PREFIX; static final String SCHEME_CLASSPATH; }### Answer:
@Test public void loadExtensions() throws Exception { File f = folder.newFile().getCanonicalFile(); List<Extension> extensions = CommandLineUtil.loadExtensions(getClass().getClassLoader(), Arrays.asList( new ExtendedArgument(TestingExtensionHandler.TAG, f.getAbsolutePath()))); try { assertThat(extensions, hasSize(1)); Extension e0 = extensions.get(0); assertThat(e0.getName(), is(TestingExtensionHandler.TAG)); assertThat(((BasicExtension) e0).getData().getFile().getCanonicalFile(), is(f)); } finally { closeAll(extensions); } }
@Test(expected = IllegalArgumentException.class) public void loadExtensions_erroneous() throws Exception { CommandLineUtil.loadExtensions(getClass().getClassLoader(), Arrays.asList( new ExtendedArgument(ErroneousExtensionHandler.TAG, "?"))); }
@Test(expected = IllegalArgumentException.class) public void loadExtensions_unknown() throws Exception { CommandLineUtil.loadExtensions(getClass().getClassLoader(), Arrays.asList( new ExtendedArgument("UNKNOWN", "?"))); }