### Question:
TextUI implements UI { Thread getShutdownHook() { return m_shutdownHook; } TextUI(Resources resources,
                ProcessControl processControl,
                SampleModel sampleModel,
                Logger logger); ErrorHandler getErrorHandler();  }### Answer:
@Test public void testProcessStatusListener() throws Exception { final TextUI textUI = new TextUI(m_resources, m_processControl, m_sampleModel, m_logger); verify(m_logger).info(contains("The Grinder")); final CallData processsControlCall = m_processControlStubFactory.assertSuccess( "addProcessStatusListener", ProcessControl.Listener.class); final ProcessControl.Listener processListener = (ProcessControl.Listener)processsControlCall.getParameters()[0]; Runtime.getRuntime().removeShutdownHook(textUI.getShutdownHook()); final ProcessReports[] reports1 = new ProcessReports[0]; processListener.update(reports1); verify(m_logger).info("no agents!"); processListener.update(reports1); processListener.update(reports1); final StubAgentIdentity agentIdentity1 = new StubAgentIdentity("agent1"); final StubAgentProcessReport agentReport1 = new StubAgentProcessReport(agentIdentity1, ProcessReport.State.RUNNING); final WorkerProcessReport workerProcessReport1 = new StubWorkerProcessReport(agentIdentity1.createWorkerIdentity(), ProcessReport.State.RUNNING, 3, 6); final WorkerProcessReport workerProcessReport2 = new StubWorkerProcessReport(agentIdentity1.createWorkerIdentity(), ProcessReport.State.FINISHED, 0, 6); processListener.update( new ProcessReports[] { new StubProcessReports(agentReport1, new WorkerProcessReport[] { workerProcessReport1, workerProcessReport2, }), }); verify(m_logger).info( "AG agent1 [plugged in] " + "{ WK agent1-0 [rolling (3/6 strings)], WK agent1-1 [fini] }"); processListener.update( new ProcessReports[] { new StubProcessReports(agentReport1, new WorkerProcessReport[] { workerProcessReport2, workerProcessReport1, }), }); final StubAgentIdentity agentIdentity2 = new StubAgentIdentity("agent2"); final StubAgentProcessReport agentReport2 = new StubAgentProcessReport(agentIdentity2, ProcessReport.State.FINISHED); processListener.update( new ProcessReports[] { new StubProcessReports(agentReport2, new WorkerProcessReport[] { }), new StubProcessReports(agentReport1, new WorkerProcessReport[] { workerProcessReport2, workerProcessReport1, }), }); verify(m_logger).info( "AG agent1 [plugged in] " + "{ WK agent1-0 [rolling (3/6 strings)], WK agent1-1 [fini] }, " + "AG agent2 [that's all folks]"); verifyNoMoreInteractions(m_logger); }
@Test public void testShutdownHook() throws Exception { final TextUI textUI = new TextUI(m_resources, m_processControl, m_sampleModel, m_logger); verify(m_logger).info(contains("The Grinder")); final Thread shutdownHook = textUI.getShutdownHook(); assertTrue(Runtime.getRuntime().removeShutdownHook(shutdownHook)); shutdownHook.run(); verify(m_logger).info("done"); shutdownHook.run(); verifyNoMoreInteractions(m_logger); }