### Question:
HTTPPlugin implements GrinderPlugin { public void initialize(PluginProcessContext processContext) throws PluginException { m_pluginProcessContext = processContext; final Grinder.ScriptContext scriptContext = processContext.getScriptContext(); m_sslContextFactory = scriptContext.getSSLControl(); m_slowClientSleeper = new SleeperImplementation( m_pluginProcessContext.getTimeAuthority(), null, 1, 0); try { HTTPConnection.removeDefaultModule( Class.forName("HTTPClient.RetryModule")); } catch (ClassNotFoundException e) { throw new PluginException("Could not load HTTPClient modules", e); } CookieModule.setCookiePolicyHandler(null); DefaultAuthHandler.setAuthorizationPrompter(null); try { final Statistics statistics = scriptContext.getStatistics(); statistics.registerDataLogExpression( "HTTP response code", StatisticsIndexMap.HTTP_PLUGIN_RESPONSE_STATUS_KEY); statistics.registerDataLogExpression( "HTTP response length", StatisticsIndexMap.HTTP_PLUGIN_RESPONSE_LENGTH_KEY); statistics.registerDataLogExpression( "HTTP response errors", StatisticsIndexMap.HTTP_PLUGIN_RESPONSE_ERRORS_KEY); statistics.registerDataLogExpression( "Time to resolve host", StatisticsIndexMap.HTTP_PLUGIN_DNS_TIME_KEY); statistics.registerDataLogExpression( "Time to establish connection", StatisticsIndexMap.HTTP_PLUGIN_CONNECT_TIME_KEY); statistics.registerDataLogExpression( "Time to first byte", StatisticsIndexMap.HTTP_PLUGIN_FIRST_BYTE_TIME_KEY); statistics.registerDataLogExpression( "New connections", StatisticsIndexMap.HTTP_PLUGIN_CONNECTIONS_ESTABLISHED); statistics.registerSummaryExpression( "Mean response length", "(/ " + StatisticsIndexMap.HTTP_PLUGIN_RESPONSE_LENGTH_KEY + " (+ (count timedTests) untimedTests))"); statistics.registerSummaryExpression( "Response bytes per second", "(* 1000 (/ " + StatisticsIndexMap.HTTP_PLUGIN_RESPONSE_LENGTH_KEY + " period))"); statistics.registerSummaryExpression( "Response errors", StatisticsIndexMap.HTTP_PLUGIN_RESPONSE_ERRORS_KEY); statistics.registerSummaryExpression( "Mean time to resolve host", "(/ " + StatisticsIndexMap.HTTP_PLUGIN_DNS_TIME_KEY + " (+ " + StatisticsIndexMap.HTTP_PLUGIN_CONNECTIONS_ESTABLISHED + "))"); statistics.registerSummaryExpression( "Mean time to establish connection", "(/ " + StatisticsIndexMap.HTTP_PLUGIN_CONNECT_TIME_KEY + " (+ " + StatisticsIndexMap.HTTP_PLUGIN_CONNECTIONS_ESTABLISHED + "))"); statistics.registerSummaryExpression( "Mean time to first byte", "(/ " + StatisticsIndexMap.HTTP_PLUGIN_FIRST_BYTE_TIME_KEY + " (+ (count timedTests) untimedTests))"); } catch (GrinderException e) { throw new PluginException("Could not register custom statistics", e); } }  void initialize(PluginProcessContext processContext); PluginThreadListener createThreadListener(
    PluginThreadContext threadContext);  }### Answer:
@Test public void testInitializeWithBadStatistics() throws Exception { final GrinderException grinderException = new GrinderException("Hello") {}; doThrow(grinderException).when(m_statistics) .registerDataLogExpression(isA(String.class), isA(String.class)); final HTTPPlugin plugin = new HTTPPlugin(); try { plugin.initialize(m_pluginProcessContext); fail("Expected PluginException"); } catch (PluginException e) { assertSame(grinderException, e.getCause()); } }
@Test public void testInitialiseWithBadHTTPClient() throws Exception { final String pluginName = HTTPPlugin.class.getName(); final URLClassLoader blockingLoader = new BlockingClassLoader(singleton("HTTPClient.RetryModule"), singleton(pluginName), Collections.<String>emptySet(), false); new PluginRegistry() { { setInstance(this); } public void register(GrinderPlugin plugin) throws GrinderException { plugin.initialize(m_pluginProcessContext); } }; try { Class.forName(pluginName, true, blockingLoader); fail("Expected PluginException"); } catch (ExceptionInInitializerError e) { assertTrue(e.getCause().getCause() instanceof ClassNotFoundException); } }