PluginCreator implements IPluginCreator { @Override public IPlugin create(final Class clazz, final IBootstrap bootstrap) throws PluginCreationException { try { Constructor c = clazz.getDeclaredConstructor(new Class[]{IBootstrap.class}); return (IPlugin) c.newInstance(new Object[]{bootstrap}); } catch (Throwable e) { throw new PluginCreationException("Could not create instance of IPlugin", e); } }  @Override IPlugin create(final Class clazz, final IBootstrap bootstrap);  }
@Test public void checkPluginCreation() throws Exception { PluginCreator creator = new PluginCreator(); IBootstrap<Object> bootstrap = mock(IBootstrap.class); doNothing().when(bootstrap).add(bootstrap); IPlugin plugin = creator.create(PluginTest.class, bootstrap); assertNotNull(plugin); plugin.load(); verify(bootstrap, times(1)).add(any(Object.class)); }
@Test (expected = PluginCreationException.class) public void checkPluginCreationException() throws Exception { PluginCreator creator = new PluginCreator(); IBootstrap<Object> bootstrap = mock(IBootstrap.class); creator.create(Object.class, bootstrap); fail(); }