ResponseThread extends Thread { @Override public void run() { String requestString; ResponseWriter responseWriter; try { RequestReader reader = requestReaderFactory.createRequestReader(socket.getInputStream()); requestString = reader.readRequest(); responseWriter = responseWriterFactory.createResponseWriter(socket.getOutputStream()); } catch (IOException e) { Logger.logVerbose(TAG, StackTrace.getStackTrace(e)); return; } processRequest(requestString, responseWriter); } ResponseThread(
      Socket socket,
      ResponseWriterFactory responseWriterFactory,
      RequestReaderFactory requestReaderFactory,
      RequestHandlerFactory requestHandlerFactory); @Override void run();  }
@Test public void createsRequestReaderFromSocketInputStream() { testSubject.run(); verify(requestReaderFactory, times(1)).createRequestReader(socketInputStream); }
@Test public void createsResponseWriterFromSocketOutputStream() { testSubject.run(); verify(responseWriterFactory, times(1)).createResponseWriter(socketOutputStream); }
@Test public void handlesExceptionOnGetInputStream() { try { when(socket.getInputStream()).thenThrow(testException); } catch (IOException e) { Assert.fail(e.getMessage()); } testSubject.run(); PowerMockito.verifyStatic(Logger.class); Logger.logVerbose("ResponseThread", stackTrace); }
@Test public void handlesExceptionOnGetOutputStream() { try { when(socket.getOutputStream()).thenThrow(testException); } catch (IOException e) { Assert.fail(e.getMessage()); } testSubject.run(); PowerMockito.verifyStatic(Logger.class); Logger.logVerbose("ResponseThread", stackTrace); }
@Test public void createsAndCallsRequestHandler() { testSubject.run(); try { verify(requestHandlerFactory, times(1)) .createHandlerForRequest(socket, requestString, responseWriter); } catch (Exception e) { Assert.fail(e.getMessage()); } verify(requestHandler, times(1)).handleRequest(); }