diff --git a/hera-core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java b/hera-core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java index 4508210..b8d984e 100644 --- a/hera-core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java +++ b/hera-core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java @@ -29,12 +29,30 @@ public class OrderAwarePluginRegistry, S> extends * @param * @return */ - public static > OrderAwarePluginRegistry create() { + public static > PluginRegistry create() { return new OrderAwarePluginRegistry(); } + /** + * Creates a new {@link OrderAwarePluginRegistry} with the given plugins. + * + * @param + * @param + * @param plugins + * @return + */ + public static > PluginRegistry create( + List plugins) { + + PluginRegistry registry = create(); + registry.setPlugins(plugins); + + return registry; + } + + /* * (non-Javadoc) * diff --git a/hera-core/src/main/java/org/synyx/hera/core/PluginRegistry.java b/hera-core/src/main/java/org/synyx/hera/core/PluginRegistry.java index c9c0073..4208678 100644 --- a/hera-core/src/main/java/org/synyx/hera/core/PluginRegistry.java +++ b/hera-core/src/main/java/org/synyx/hera/core/PluginRegistry.java @@ -29,6 +29,14 @@ public interface PluginRegistry, S> extends Iterable { void addPlugin(T plugin); + /** + * Removes a given plugin from the registry. + * + * @param plugin + */ + boolean removePlugin(T plugin); + + /** * Returns the first plugin found for the given originating system. Thus, * further configured plugins are ignored. @@ -107,4 +115,12 @@ public interface PluginRegistry, S> extends Iterable { */ int countPlugins(); + + /** + * Returns whether the registry contains a given plugin. + * + * @param plugin + * @return + */ + boolean contains(T plugin); } \ No newline at end of file diff --git a/hera-core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java b/hera-core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java index 3e8d27c..bf9dbe5 100644 --- a/hera-core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java +++ b/hera-core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java @@ -58,6 +58,23 @@ public class SimplePluginRegistry, S> implements } + /** + * Creates a new {@link SimplePluginRegistry}. + * + * @param + * @param + * @return + */ + public static > PluginRegistry create( + List plugins) { + + PluginRegistry registry = create(); + registry.setPlugins(plugins); + + return registry; + } + + /* * (non-Javadoc) * @@ -81,6 +98,19 @@ public class SimplePluginRegistry, S> implements } + /* + * (non-Javadoc) + * + * @see + * org.synyx.hera.core.PluginRegistry#removePlugin(org.synyx.hera.core.Plugin + * ) + */ + public boolean removePlugin(T plugin) { + + return this.plugins.remove(plugin); + } + + /* * (non-Javadoc) * @@ -206,6 +236,18 @@ public class SimplePluginRegistry, S> implements } + /* + * (non-Javadoc) + * + * @see + * org.synyx.hera.core.PluginRegistry#contains(org.synyx.hera.core.Plugin) + */ + public boolean contains(T plugin) { + + return this.plugins.contains(plugin); + } + + /* * (non-Javadoc) * diff --git a/hera-core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java b/hera-core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java index b52689d..2c7ee7a 100644 --- a/hera-core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java +++ b/hera-core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java @@ -31,7 +31,7 @@ import org.junit.Test; */ public class SimplePluginRegistryUnitTest { - private SamplePlugin provider; + private SamplePlugin plugin; private PluginRegistry registry; @@ -43,10 +43,22 @@ public class SimplePluginRegistryUnitTest { @Before public void setUp() { - provider = new SamplePluginImplementation(); + plugin = new SamplePluginImplementation(); - registry = new SimplePluginRegistry(); - registry.setPlugins(Arrays.asList(provider)); + registry = SimplePluginRegistry.create(Arrays.asList(plugin)); + } + + + /** + * Asserts that the registry contains the plugin it was initialized with. + * + * @throws Exception + */ + @Test + public void assertRegistryInitialized() throws Exception { + + assertEquals(1, registry.countPlugins()); + assertTrue(registry.contains(plugin)); }