### Question:
RegisteredPlugin implements PluginProcessContext { public PluginThreadListener getPluginThreadListener() throws EngineException { final ThreadContext threadContext = m_threadContextLocator.get(); if (threadContext == null) { throw new EngineException("Must be called from worker thread"); } return createPluginThreadListener(threadContext); } RegisteredPlugin(GrinderPlugin plugin, ScriptContext scriptContext,
                          ThreadContextLocator threadContextLocator,
                          StatisticsServices statisticsServices,
                          TimeAuthority timeAuthority, Logger logger); ScriptContext getScriptContext(); PluginThreadListener getPluginThreadListener(); StatisticsServices getStatisticsServices(); TimeAuthority getTimeAuthority();  }### Answer:
@Test public void testGetPluginThreadListener() throws Exception { final GrinderPluginStubFactory grinderPluginStubFactory = new GrinderPluginStubFactory(); final GrinderPlugin grinderPlugin = grinderPluginStubFactory.getStub(); final RandomStubFactory<ScriptContext> scriptContextStubFactory = RandomStubFactory.create(ScriptContext.class); final RandomStubFactory<TimeAuthority> timeAuthorityStubFactory = RandomStubFactory.create(TimeAuthority.class); final StubThreadContextLocator threadContextLocator = new StubThreadContextLocator(); final RegisteredPlugin registeredPlugin = new RegisteredPlugin(grinderPlugin, scriptContextStubFactory.getStub(), threadContextLocator, StatisticsServicesImplementation.getInstance(), timeAuthorityStubFactory.getStub(), m_logger); try { registeredPlugin.getPluginThreadListener(); fail("Expected EngineException"); } catch (EngineException e) { } threadContextLocator.set(m_threadContext); grinderPluginStubFactory.setThrowExceptionFromCreateThreadListener(true); try { registeredPlugin.getPluginThreadListener(); fail("Expected EngineException"); } catch (EngineException e) { } verify(m_threadContext).getLogMarker(); grinderPluginStubFactory.assertException("createThreadListener", PluginException.class, PluginThreadContext.class); grinderPluginStubFactory.assertNoMoreCalls(); grinderPluginStubFactory.setThrowExceptionFromCreateThreadListener(false); final PluginThreadListener pluginThreadListener1 = registeredPlugin.getPluginThreadListener(); grinderPluginStubFactory.assertSuccess( "createThreadListener", PluginThreadContext.class); final PluginThreadListener pluginThreadListener2 = registeredPlugin.getPluginThreadListener(); verify(m_threadContext) .registerThreadLifeCycleListener(isA(ThreadLifeCycleListener.class)); grinderPluginStubFactory.assertNoMoreCalls(); assertSame(pluginThreadListener1, pluginThreadListener2); final PluginThreadListener pluginThreadListener3 = registeredPlugin.createPluginThreadListener(m_threadContext); assertSame(pluginThreadListener1, pluginThreadListener3); verifyNoMoreInteractions(m_threadContext); }