PluginManager { private PluginManager(Class<T> pluginClass, List<T> plugins) { super(); this.pluginClass = pluginClass; this.plugins = plugins; logger.info("Starting plugin manager with following plugins: "+Arrays.toString(plugins.toArray())); } private  PluginManager(Class<T> pluginClass, List<T> plugins); T getProxy(); I getProxy(Class<I> proxyInterface); List<T> getPlugins(); static Builder<T> builder(Class<T> pluginClass);  }
@Test public void testBuilderWithOnePlugin() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugin(new TestPlugin1()).build(); assertOrder(pluginManager, TestPlugin1.class); }
@Test public void testBuilderWithPluginList() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin1(),new TestPlugin2())).build(); assertOrder(pluginManager, TestPlugin1.class, TestPlugin2.class); }
@Test public void testBuilderWithPluginList2() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin2(),new TestPlugin1())).build(); assertOrder(pluginManager, TestPlugin2.class, TestPlugin1.class); }
@Test public void testBuilderWithPluginList3() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin1(),new TestPlugin2(),new TestPlugin3(),new TestPlugin4(),new TestPlugin5())).build(); assertOrder(pluginManager, TestPlugin1.class, TestPlugin3.class, TestPlugin4.class, TestPlugin5.class, TestPlugin2.class); }
@Test public void testBuilderWithPluginList4() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin5(),new TestPlugin4(),new TestPlugin3(),new TestPlugin2(),new TestPlugin1())).build(); assertOrder(pluginManager, new TestPlugin3(), new TestPlugin1(), new TestPlugin4(), new TestPlugin5(), new TestPlugin2()); }
@Test public void testBuilderWithPluginList5() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin2(),new TestPlugin5(),new TestPlugin4(),new TestPlugin1(),new TestPlugin3())).build(); assertOrder(pluginManager, new TestPlugin1(), new TestPlugin4(), new TestPlugin3(), new TestPlugin5(), new TestPlugin2()); }
@Test public void testBuilderWithCircularDependency() throws CircularDependencyException { Exception actual = null; try { pluginManager().withPlugins(plugins(new TestPlugin1(),new TestPlugin2(),new TestPlugin3(),new TestPlugin4(),new TestPlugin5(),new TestPlugin6(),new TestPlugin7())).build(); } catch (CircularDependencyException e) { actual = e; } Assert.assertNotNull(actual); }
@Test public void testBuilderWithCircularDependency2() throws CircularDependencyException { Exception actual = null; try { pluginManager().withPlugins(plugins(new TestPlugin10(),new TestPlugin11())).build(); } catch (CircularDependencyException e) { actual = e; } Assert.assertNotNull(actual); }
@Test public void testCircularDependencyToItself() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin1(),new TestPlugin8())).build(); assertOrder(pluginManager, new TestPlugin1(), new TestPlugin8()); }
@Test public void testPluginWithoutAnnotation() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPluginWithoutAnnotation())).build(); assertOrder(pluginManager, new TestPluginWithoutAnnotation()); }
@Test public void testRunsBefore() throws CircularDependencyException { PluginManager<TestPluginInterface> pluginManager = pluginManager().withPlugins(plugins(new TestPlugin3(),new TestPlugin9(),new TestPlugin10())).build(); assertOrder(pluginManager, new TestPlugin9(), new TestPlugin10(), new TestPlugin3()); }