### Question:
DebugThreadWorker implements Worker { public DebugThreadWorker(WorkerIdentity workerIdentity, final IsolateGrinderProcessRunner runner) { m_workerIdentity = workerIdentity; m_communicationStream = new PipedOutputStream(); final InputStream inputStream; try { inputStream = new PipedInputStream(m_communicationStream); } catch (IOException e) { throw new AssertionError(e); } m_thread = new Thread(workerIdentity.getName()) { public void run() { m_result = runner.run(inputStream); } }; m_thread.setDaemon(true); } DebugThreadWorker(WorkerIdentity workerIdentity,
                           final IsolateGrinderProcessRunner runner); void start(); WorkerIdentity getIdentity(); OutputStream getCommunicationStream(); int waitFor(); void destroy();  }### Answer:
@Test public void testDebugThreadWorker() throws Exception { final DelegatingStubFactory<IsolatedGrinderProcessRunner> isolateGrinderProcessRunnerStubFactory = DelegatingStubFactory.create(new IsolatedGrinderProcessRunner()); final DebugThreadWorker worker = new DebugThreadWorker(m_workerIdentity, isolateGrinderProcessRunnerStubFactory.getStub()); assertEquals(m_workerIdentity, worker.getIdentity()); assertNotNull(worker.getCommunicationStream()); worker.start(); final int[] resultHolder = { -1 }; final Thread waitThread = new Thread() { public void run() { resultHolder[0] = worker.waitFor(); } }; waitThread.start(); assertEquals(-1, resultHolder[0]); assertTrue(waitThread.isAlive()); final RedirectStandardStreams streams = new RedirectStandardStreams() { protected void runWithRedirectedStreams() throws Exception { new StreamSender(worker.getCommunicationStream()).shutdown(); waitThread.join(); } }; streams.run(); isolateGrinderProcessRunnerStubFactory.assertSuccess( "run", InputStream.class); assertEquals(-2, resultHolder[0]); final String output = new String(streams.getStderrBytes()); assertTrue(output.indexOf("No control stream from agent") > 0); worker.destroy(); }