@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)); } }
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); } }
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); } } }
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); } }  }
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(); }
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();  }