### Question:
PluginRegistryImplementation extends PluginRegistry implements ProcessLifeCycleListener { public void register(GrinderPlugin plugin) throws EngineException { synchronized (m_plugins) { if (!m_plugins.containsKey(plugin)) { final RegisteredPlugin registeredPlugin = new RegisteredPlugin(plugin, m_scriptContext, m_threadContextLocator, m_statisticsServices, m_timeAuthority, m_logger); try { plugin.initialize(registeredPlugin); } catch (PluginException e) { throw new EngineException("An instance of the plug-in class '" + plugin.getClass().getName() + "' could not be initialised.", e); } m_plugins.put(plugin, registeredPlugin); m_logger.info("registered plug-in {}", plugin.getClass().getName()); } } } PluginRegistryImplementation(Logger logger, ScriptContext scriptContext,
                               ThreadContextLocator threadContextLocator,
                               StatisticsServices statisticsServices,
                               TimeAuthority timeAuthority); void register(GrinderPlugin plugin); void threadCreated(final ThreadContext threadContext); void threadStarted(ThreadContext threadContext);  }### Answer:
@Test public void testRegister() throws Exception { final PluginRegistry pluginRegistry = new PluginRegistryImplementation( m_logger, m_scriptContext, m_threadContextLocator, StatisticsServicesImplementation.getInstance(), m_timeAuthority); pluginRegistry.register(m_grinderPlugin); verify(m_grinderPlugin).initialize(m_pluginCaptor.capture()); final RegisteredPlugin registeredPlugin = m_pluginCaptor.getValue(); assertSame(m_scriptContext, registeredPlugin.getScriptContext()); assertSame(m_timeAuthority, registeredPlugin.getTimeAuthority()); verify(m_logger).info(contains("registered plug-in"), contains("GrinderPlugin")); pluginRegistry.register(m_grinderPlugin); verifyNoMoreInteractions(m_grinderPlugin, m_logger); }
@Test public void testRegisterWithBadPlugin() throws Exception { final PluginRegistry pluginRegistry = new PluginRegistryImplementation( m_logger, m_scriptContext, m_threadContextLocator, StatisticsServicesImplementation.getInstance(), m_timeAuthority); final PluginException initialiseException = new PluginException("barf"); doThrow(initialiseException) .when(m_grinderPlugin).initialize(m_pluginCaptor.capture()); try { pluginRegistry.register(m_grinderPlugin); fail("Expected EngineException"); } catch (EngineException e) { assertSame(initialiseException, e.getCause()); } }