PluginRegistryContainer implements PluginRegistry { @Override public void addPlugin(PluginMetadata pluginMetadata) throws PluginException { plugins.put(pluginMetadata.getName(), pluginMetadata); Optional<Dependency> providedDependency = pluginMetadata.getProvidedDependency(); if (providedDependency.isPresent()) { Optional<PluginMetadata> anotherPlugin = getPlugin(providedDependency.get().getName()); if (anotherPlugin.isPresent()) { throw new PluginException("Another plugin providing the same virtual dependency found: " + anotherPlugin.get().getName()) .withDependencyProblem(new DependencyProblemContainer( Collections.emptyList(), new ArrayList<Dependency>() { { add(anotherPlugin.get().getDependency()); } } )); } plugins.put(providedDependency.get().getName(), pluginMetadata); } }  @Override void addImplementations(PluginMetadata pluginMetadata, Class extensionPoint, List<Class> implementationClasses); @Override void addPlugin(PluginMetadata pluginMetadata); @Override Optional<PluginMetadata> getPlugin(String pluginName); @Override List<String> getPluginNames(); @Override List<Class> getExtensionPoints(); @Override List<Class> getImplementations(Class extensionPoint); @Override List<Class> getExtensionPoints(String pluginName); @Override List<Class> getImplementations(String pluginName, Class extensionPoint); @Override void addResources(PluginMetadata pluginMetadata, List<Path> resourcesList); @Override List<Path> getResources(String pluginName); @Override List<Path> getResources(); @Override void addClassLoader(PluginMetadata pluginMetadata, ClassLoader classLoader); @Override Optional<ClassLoader> getClassLoader(String pluginName);  }
@Test(expected = PluginException.class) public void testDuplicateProvidedDependency() throws PluginException { PluginRegistry pluginRegistry = new PluginRegistryContainer(); PluginMetadata pluginMetadata = getMockPluginMetadata(PLUGIN_NAME); Dependency pluginDependency = new DependencyContainer(PLUGIN_NAME, "plugin-version"); when(pluginMetadata.getDependency()).thenReturn(pluginDependency); Dependency providedDependency = new DependencyContainer("some-plugin", "some-version"); when(pluginMetadata.getProvidedDependency()).thenReturn(Optional.of(providedDependency)); pluginRegistry.addPlugin(pluginMetadata); pluginRegistry.addPlugin(pluginMetadata); }