### Question:
AbstractPluginRegistry implements IPluginRegistry { @Override public Plugin loadPlugin(PluginCoordinates coordinates) throws InvalidPluginException { boolean isSnapshot = PluginUtils.isSnapshot(coordinates); synchronized (mutex) { if (pluginCache.containsKey(coordinates)) { Plugin cachedPlugin = pluginCache.get(coordinates); if (isSnapshot) { pluginCache.remove(coordinates); try { cachedPlugin.getLoader().close(); } catch (IOException e) { e.printStackTrace(); } } else { return cachedPlugin; } } String pluginRelativePath = PluginUtils.getPluginRelativePath(coordinates); File pluginDir = new File(pluginsDir, pluginRelativePath); if (!pluginDir.exists()) { pluginDir.mkdirs(); } File pluginFile = new File(pluginDir, "plugin." + coordinates.getType()); if (pluginFile.exists() && isSnapshot) { try { FileUtils.deleteDirectory(pluginFile.getParentFile()); pluginFile.getParentFile().mkdirs(); } catch (IOException e) { e.printStackTrace(); } } if (!pluginFile.exists()) { downloadPlugin(pluginFile, coordinates); } if (!pluginFile.exists()) { throw new InvalidPluginException(Messages.i18n.format("AbstractPluginRegistry.PluginNotFound")); } PluginClassLoader pluginClassLoader; try { pluginClassLoader = createPluginClassLoader(pluginFile); } catch (IOException e) { throw new InvalidPluginException(Messages.i18n.format("AbstractPluginRegistry.InvalidPlugin", pluginFile.getAbsolutePath()), e); } URL specFile = pluginClassLoader.getResource(PluginUtils.PLUGIN_SPEC_PATH); if (specFile == null) { throw new InvalidPluginException(Messages.i18n.format("AbstractPluginRegistry.MissingPluginSpecFile", PluginUtils.PLUGIN_SPEC_PATH)); } try { PluginSpec spec = PluginUtils.readPluginSpecFile(specFile); Plugin plugin = new Plugin(spec, coordinates, pluginClassLoader); pluginCache.put(coordinates, plugin); return plugin; } catch (Exception e) { throw new InvalidPluginException(Messages.i18n.format("AbstractPluginRegistry.FailedToReadSpecFile", PluginUtils.PLUGIN_SPEC_PATH), e); } } } AbstractPluginRegistry();  AbstractPluginRegistry(File pluginsDir); @Override Plugin loadPlugin(PluginCoordinates coordinates); void setPluginsDir(File pluginsDir);  }### Answer:
@Test public void testLoadPlugin() throws Exception { File targetDir = new File("target").getAbsoluteFile(); File tmpDir = new File(targetDir, "_plugintmp"); AbstractPluginRegistry registry = new TestPluginRegistry(tmpDir); PluginCoordinates coords = new PluginCoordinates("io.apiman.test", "apiman-test-plugin", "1.0"); Plugin plugin = registry.loadPlugin(coords); Assert.assertNotNull(plugin);; Assert.assertEquals("Test Plugin", plugin.getName()); Assert.assertEquals("The first ever plugin for testing.", plugin.getDescription()); }