DefaultPluginManager implements PluginManager { @Override public Collection<Object> loadPlugins(PluginSource source) throws Exception { final Collection<Class<?>> pluginClasses = Objects.requireNonNull(source, "Plugin Source cannot be null").load(); final Collection<Object> loaded = new ArrayList<>(); if (pluginClasses.isEmpty()) { return loaded; } final Iterator<Class<?>> itr = pluginClasses.iterator(); while (itr.hasNext()) { Class<?> pluginClass = itr.next(); if (pluginClass.getAnnotation(Plugin.class) == null) { itr.remove(); continue; } if (context.hasPlugin(pluginClass)) { itr.remove(); } } Collection<Node<?>> nodes = dependencyResolver.resolve(pluginClasses); createPlugins(nodes, loaded); return loaded; } DefaultPluginManager(PluginContext context, AnnotationProcessor annotationProcessor, DependencyResolver dependencyResolver); @Override void register(T plugin); @Override void register(String name, T plugin); @Override T getPlugin(String name); @Override T getPlugin(Class<T> pluginClass); @Override Collection<PluginRef> getAllPlugins(); @Override T removePlugin(String name); @Override T removePlugin(T plugin); @Override Collection<Object> loadPlugins(PluginSource source);  }
@Test public void shouldNotLoadAPluginTwice() throws Exception { manager.loadPlugins(mockSource); this.shouldLoadPluginsFromSource(); }
@Test public void shouldNotLoadForeignClasses() throws Exception { final List<Object> plugins = (List<Object>) manager.loadPlugins(new PluginSource() { @Override public Collection<Class<?>> load() throws IOException, ClassNotFoundException { return newArrayList(TestPlugin.class, String.class); } }); assertEquals(1, plugins.size()); assertTrue(plugins.get(0) instanceof TestPlugin); }