PluginHolder { public static PluginHolder build(File[] pluginJars) throws MalformedURLException, InstantiationException, IllegalAccessException { if (instance != null) { throw new IllegalStateException("The PluginHolder has already been built. Please call getInstance() Instead."); } instance = new PluginHolder(); ArrayList<Class<? extends Plugin>> notifierClasses = new ArrayList<>(); ArrayList<Class<? extends Plugin>> securityClasses = new ArrayList<>(); for (File pluginJar : pluginJars) { notifierClasses.addAll(PluginUtils.getPluginsFromExternalJar(pluginJar, NotifierPlugin.class)); securityClasses.addAll(PluginUtils.getPluginsFromExternalJar(pluginJar, SecurityPlugin.class)); } for (Class<? extends Plugin> clazz : notifierClasses) { NotifierPlugin object = (NotifierPlugin) clazz.newInstance(); logger.info("Loading Notifier Plugin: " + object.getPluginName() + " of class type: " + object.getClass().getCanonicalName()); notifierPlugins.add(object); } for (Class<? extends Plugin> clazz : securityClasses) { SecurityPlugin object = (SecurityPlugin) clazz.newInstance(); logger.info("Loading Security Plugin: " + object.getPluginName() + " of class type: " + object.getClass().getCanonicalName()); securityPlugins.add(object); } return instance; } private  PluginHolder(); static PluginHolder build(File[] pluginJars); static PluginHolder getInstance(); ArrayList<NotifierPlugin> getNotifierPlugins(); ArrayList<SecurityPlugin> getSecurityPlugins();  }
@Test public void testBuild() throws Exception { System.out.println("build"); assertNotNull(ph); boolean expectedExceptionThrown = false; try { PluginHolder.build(null); } catch (IllegalStateException e) { expectedExceptionThrown = true; } assertTrue(expectedExceptionThrown); }