PluginRegistry { void add(Class<? extends Plugin> pluginClass) { try { add(pluginClass.newInstance()); } catch (InstantiationException e) { throw new KernelException("Plugin %s can not be instantiated", pluginClass); } catch (IllegalAccessException e) { throw new KernelException("Plugin %s can not be instantiated", pluginClass); } }  Map<String, Plugin> getPluginsByName();  }
@Test public void test_add_non_instantiable_plugin_classes() { try { underTest.add(MyPlugin2.class); Assertions.failBecauseExceptionWasNotThrown(KernelException.class); } catch (KernelException e) { assertThat(e).hasMessage(String.format("Plugin %s can not be instantiated", MyPlugin2.class)); } }
@Test(expected = KernelException.class) public void test_assertNameNotBlank_with_null() { underTest.add(new UnnamedPlugin(null)); }
@Test(expected = KernelException.class) public void test_assertNameNotBlank_with_empty() { underTest.add(new UnnamedPlugin("")); }
@Test(expected = KernelException.class) public void test_assertUniqueness_with_class_conflict() { underTest.add(new MyPlugin()); underTest.add(new MyPlugin()); }
@Test(expected = KernelException.class) public void test_assertUniqueness_with_name_conflict() { underTest.add(new MyPlugin()); underTest.add(new UnnamedPlugin(MyPlugin.NAME)); }